예제 #1
0
 protected function getProxy($class)
 {
     if (empty($this->proxies[$class])) {
         $this->proxies[$class] = $this->factory->createProxy($class);
     }
     return $this->proxies[$class];
 }
 /**
  * {@inheritDoc}
  *
  * @covers \ProxyManager\Factory\RemoteObjectFactory::__construct
  * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy
  * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator
  *
  * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
  */
 public function testWillTryAutoGeneration()
 {
     $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
     $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
     $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
     $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
     $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
     $generator->expects($this->once())->method('generate')->with($this->callback(function (ClassGenerator $targetClass) use($proxyClassName) {
         return $targetClass->getName() === $proxyClassName;
     }));
     // simulate autoloading
     $autoloader->expects($this->once())->method('__invoke')->with($proxyClassName)->will($this->returnCallback(function () use($proxyClassName) {
         eval('class ' . $proxyClassName . ' extends stdClass {}');
     }));
     $this->inflector->expects($this->once())->method('getProxyClassName')->with('ProxyManagerTestAsset\\BaseInterface')->will($this->returnValue($proxyClassName));
     $this->inflector->expects($this->once())->method('getUserClassName')->with('ProxyManagerTestAsset\\BaseInterface')->will($this->returnValue('stdClass'));
     $this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
     $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
     $adapter = $this->getMock('ProxyManager\\Factory\\RemoteObject\\AdapterInterface');
     $factory = new RemoteObjectFactory($adapter, $this->config);
     /* @var $proxy \stdClass */
     $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter);
     $this->assertInstanceOf($proxyClassName, $proxy);
 }
예제 #3
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\RemoteObject\Adapter\XmlRpc;
use ProxyManager\Factory\RemoteObjectFactory;
use Zend\XmlRpc\Client;
if (!class_exists('Zend\\XmlRpc\\Client')) {
    echo "This example needs Zend\\XmlRpc\\Client to run. \n In order to install it, " . "please run following:\n\n" . "\$ php composer.phar require zendframework/zend-xmlrpc:2.*\n\n";
    exit(2);
}
class Foo
{
    public function bar()
    {
        return 'bar local!';
    }
}
$factory = new RemoteObjectFactory(new XmlRpc(new Client('http://localhost:9876/remote-proxy/remote-proxy-server.php')));
$proxy = $factory->createProxy('Foo');
try {
    var_dump($proxy->bar());
    // bar remote !
} catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $error) {
    echo "To run this example, please following before:\n\n\$ php -S localhost:9876 -t \"" . __DIR__ . "\"\n";
    exit(2);
}