ilya / ron
Extend classes and create implementations in runtime
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/ilya/ron
Requires
- php: >=5.4.0
Requires (Dev)
- phpspec/phpspec: ~2
This package is not auto-updated.
Last update: 2025-10-11 21:17:26 UTC
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 declarationapply(): evaluates the code usingevalgetClassName(): 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.