定制 gabrieljmj/prototype 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gabrieljmj/prototype

Composer 安装命令:

composer require gabrieljmj/prototype

包简介

README 文档

README

Total Downloads Latest Unstable Version License Scrutinizer Code Quality

This library allows you to create prototypes almost like in JavaScript.

##Tests Sorry, I know that it is wrong, but I left the tests to do after the library. Why? Because I am having problems to write them.

##1. Creating an object Objects are created with functions. These functions will return an object. All objects are registred on a class called \Gabrieljmj\Prototype\Prototype.

require_once 'autoload.php';

use Gabrieljmj\Prototype\Prototype;

function Person() {
    return Prototype::getInstance()->prot('Person');
}

To set methods, you need set as global the variable $self and use like you use $this on OOP:

Person()->on = 1;

Person()->setName = function ($name) {
    global $self;
    $self->name = $name;
};

Person()->getName = function() {
    global $self;
    return $self->name;
};

So you can instance this and execute the methods and get the propeties:

$user1 = new Person();
$user1->setName('Hansel');

$user2 = new Person();
$user2->setName('Gretel');

echo $user1->getName() . ' and ' . $user2->getName(); //Hansel and Gretel

##2. Extending The extending is almost the same of JavaScript. Just set the property $prototype:

function Employee() {
    return Prototype::getInstance()->prot('Employee');
}

Employee()->prototype = new Person();

Employee()->setJobTitle = function ($jobtitle) {
    global $self;
    $self->jobTitle = $jobtitle;
};

Employee()->getJobTitle = function () {
    global $self;
    return $self->jobTitle;
};

$employee = new Employee();
$employee->setName('Jhon');
$employee->setJobTitle('Developer');

echo 'Hi! My name is ' . $employee->getName() . ' and I work as ' . $employee->getJobTitle() . '.';
//Hi! My name is Jhon and I work as Developer.

###2.1. Instanceof

var_dump($person instanceof Employee); //bool(false)
var_dump($employee instanceof Person); //bool(true)

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固