2017 © Pedro Peláez
 

library nerd-proxy

Lightweight Object Proxy

image

nerd-components/nerd-proxy

Lightweight Object Proxy

  • Monday, June 26, 2017
  • by pldin601
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Nerd Proxy

Coverage Status Build Status StyleCI Dependency Status, (*1)

A lightweight object proxy for PHP 7., (*2)

Usage

Create object implementing given interfaces:, (*3)

<?php

use \Nerd\Proxy\Proxy;
use \Nerd\Proxy\Handler;

interface FooInterface {
    public function foo(): string;
}

interface BarInterface {
    public function bar(): string;
}

$interfacesList = [FooInterface::class, BarInterface::class];

$handler = new class implements Handler {
    public function invoke(ReflectionMethod $method, array $args, $proxyInstance) {
        switch ($method->getName()) {
            case 'foo':
                return 'foo called';
            case 'bar':
                return 'bar called';
        }
    }
};

$proxy = Proxy::newProxyInstance($handler, $interfacesList);

$proxy instanceof FooInterface; // true
$proxy instanceof BarInterface; // true

$proxy->foo(); // 'foo called'
$proxy->bar(); // 'bar called'

Create proxy for given object:, (*4)

<?php

use \Nerd\Proxy\Proxy;
use \Nerd\Proxy\Handler;

$object = new class {
    public function foo(): int {
        echo "Foo! ";
        return 10;
    }
};

$objectProxy = Proxy::newProxyForObject($object, new class implements Handler {
    public function invoke(ReflectionMethod $method, array $args, $proxyInstance) {
        echo "Before call. ";
        $result = $method->invokeArgs($proxyInstance, $args);
        echo "After call.";
        return $result;
    }
});

$objectProxy->foo(); // will print: 'Before call. Foo! After call.' and then return 10 

The Versions

26/06 2017

dev-master

9999999-dev

Lightweight Object Proxy

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Roman Lakhtadyr

09/06 2017

v0.1

0.1.0.0

Lightweight Object Proxy

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Roman Lakhtadyr