2017 © Pedro Peláez
 

library ron

Extend classes and create implementations in runtime

image

ilya/ron

Extend classes and create implementations in runtime

  • Tuesday, April 15, 2014
  • by ilya.s
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Ron

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

Installation

Ron requires PHP >=5.4.0., (*2)

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

Use

First, create an interface or an abstract class:, (*4)

<?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:, (*5)

// 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., (*6)

$entity = $ron->create();

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

  • 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:, (*8)

$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?, (*9)

License

Ron is licensed under the MIT license., (*10)

The Versions

15/04 2014

dev-master

9999999-dev

Extend classes and create implementations in runtime

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

php class interface extend implementation implement

15/04 2014

0.1.0

0.1.0.0

Extend classes and create implementations in runtime

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

php class interface extend implementation implement