2017 © Pedro Peláez
 

library reflection-api

image

igniphp/reflection-api

  • Monday, May 14, 2018
  • by dkraczkowski
  • Repository
  • 1 Watchers
  • 0 Stars
  • 136 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 353 % Grown

The README.md

Igni logo

Build Status Scrutinizer Code Quality Code Coverage, (*1)

Installation

composer require igniphp/reflection-api

Reflection API

Licensed under MIT License., (*2)

Reflection api provides tools that allows to: - read and write object's properties - build classes on runtime - retrieves closure's body - instantiating objects without reflection api, (*3)

Reading object's properties

use Igni\Utils\ReflectionApi;

class TestClass
{
    private $test;

    public function __construct()
    {
        $this->test = 1;
    }
}

$instance = new TestClass();

ReflectionApi::readProperty($instance, 'test');

Write object's properties

use Igni\Utils\ReflectionApi;

class TestClass
{
    private $test;

    public function __construct()
    {
        $this->test = 1;
    }
}

$instance = new TestClass();

ReflectionApi::writeProperty($instance, 'test', 2);

Create an instance

use Igni\Utils\ReflectionApi;

class TestClass
{
    private $test;

    public function __construct()
    {
        $this->test = 1;
    }
}

$instance = ReflectionApi::createInstance(TestClass::class);

Building and loading class on runtime

use Igni\Utils\ReflectionApi;
use Igni\Utils\ReflectionApi\RuntimeProperty;
use Igni\Utils\ReflectionApi\RuntimeMethod;

$class = ReflectionApi::createClass('TestClass');

$class->addProperty((new RuntimeProperty('test))->makePrivate());

$constructor = new RuntimeMethod('__construct');
$constructor->addBody(
    '$this->test = 1'
);

$getTest = new RuntimeMethod('getTest');
$getTest->setReturnType('string');
$getTest->addBody(
    'return $this->test'
);

$class->addMethod($constructor);
$class->addMethod($getTest);

$class->load();

$instance = $class->createInstance();

$instance instanceof 'TestClass';// true.
$instance->getTest();// 1

The Versions

14/05 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dawid Kraczkowski

14/05 2018

1.0.2

1.0.2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dawid Kraczkowski

14/05 2018

1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dawid Kraczkowski

10/05 2018

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dawid Kraczkowski