PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,38 @@
<?php
/**
* This example demonstrates how an access interceptor scope localizer
* (which is a specific type of smart reference) is safe to use to
* proxy fluent interfaces.
*/
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory;
class FluentCounter
{
public $counter = 0;
/** @return FluentCounter */
public function fluentMethod()
{
$this->counter += 1;
return $this;
}
}
$factory = new AccessInterceptorScopeLocalizerFactory();
$foo = new FluentCounter();
/* @var $proxy FluentCounter */
$proxy = $factory->createProxy(
$foo,
array('fluentMethod' => function ($proxy) { echo "pre-fluentMethod #{$proxy->counter}!\n"; }),
array('fluentMethod' => function ($proxy) { echo "post-fluentMethod #{$proxy->counter}!\n"; })
);
$proxy->fluentMethod()->fluentMethod()->fluentMethod()->fluentMethod();
echo 'The proxy counter is now at ' . $proxy->counter . "\n";
echo 'The real instance counter is now at ' . $foo->counter . "\n";

View File

@ -0,0 +1,46 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\LazyLoadingGhostFactory;
class Foo
{
private $foo;
public function __construct()
{
sleep(5);
}
public function setFoo($foo)
{
$this->foo = (string) $foo;
}
public function getFoo()
{
return $this->foo;
}
}
$startTime = microtime(true);
$factory = new LazyLoadingGhostFactory();
for ($i = 0; $i < 1000; $i += 1) {
$proxy = $factory->createProxy(
'Foo',
function ($proxy, $method, $parameters, & $initializer) {
$initializer = null;
$proxy->setFoo('Hello World!');
return true;
}
);
}
var_dump('time after 1000 instantiations: ' . (microtime(true) - $startTime));
echo $proxy->getFoo() . "\n";
var_dump('time after single call to doFoo: ' . (microtime(true) - $startTime));

View File

@ -0,0 +1,36 @@
<?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);
}

View File

@ -0,0 +1,20 @@
<?php
use Zend\XmlRpc\Server;
require_once __DIR__ . '/../../vendor/autoload.php';
class Foo
{
public function bar()
{
return 'bar remote!';
}
}
$server = new Server();
$server->setClass(new Foo(), 'Foo');
$server->setReturnResponse(false);
$server->handle();

View File

@ -0,0 +1,23 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\AccessInterceptorValueHolderFactory;
class Foo
{
public function doFoo()
{
echo "Foo!\n";
}
}
$factory = new AccessInterceptorValueHolderFactory();
$proxy = $factory->createProxy(
new Foo(),
array('doFoo' => function () { echo "pre-foo!\n"; }),
array('doFoo' => function () { echo "post-foo!\n"; })
);
$proxy->doFoo();

View File

@ -0,0 +1,39 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
class Foo
{
public function __construct()
{
sleep(5);
}
public function doFoo()
{
echo "Foo!";
}
}
$startTime = microtime(true);
$factory = new LazyLoadingValueHolderFactory();
for ($i = 0; $i < 1000; $i += 1) {
$proxy = $factory->createProxy(
'Foo',
function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) {
$initializer = null;
$wrappedObject = new Foo();
return true;
}
);
}
var_dump('time after 1000 instantiations: ' . (microtime(true) - $startTime));
$proxy->doFoo();
var_dump('time after single call to doFoo: ' . (microtime(true) - $startTime));