定制 ilya/ron 二次开发

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

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

ilya/ron

Composer 安装命令:

composer require ilya/ron

包简介

Extend classes and create implementations in runtime

README 文档

README

Ron allows you to override abstract methods and implement interfaces in... run time! How cool is that?

Installation

Ron requires PHP >=5.4.0.

You can grab Ron using Composer: composer require "ilya/ron:0.1.*".

Use

First, create an interface or an abstract class:

<?php namespace demo;

interface Foo {
    public function bar(stdClass $so, $amaze = null);
}

abstract class Baz {
    abstract protected function wow($such, stdClass $doge = null); 
}

Then you need to "wrap" them into \ReflectionClass, like so:

// you could pass "demo\Foo" as the argument instead
$ron = new \Ron\Ron(new \ReflectionClass('demo\Baz'));

So now that you've successfully created an instance of \Ron\Ron, you can call the method create on it.

$entity = $ron->create();

Now that the $entity variable has type \Ron\Entity, here is what you can do:

  • getCode(): returns the valid PHP class declaration
  • apply(): evaluates the code using eval
  • getClassName(): returns the class name used (e.g. class\_ff3453363262dssfwgw)

To finish, let me show you just a very basic example:

$methods = ['wow' => 'Hello, world!'];

$entity = (new \Ron\Ron(new \ReflectionClass('demo\Baz')))->create($methods);

$entity->apply();
$name = $entity->getClassName();

(new $name)->wow('Hey!'); // Hello, world!

That's it, have any questions?

License

Ron is licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-15