for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace StaticAnalysis\LazyLoadingValueHolder;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use ProxyManager\Proxy\LazyLoadingInterface;
require_once __DIR__ . '/../../vendor/autoload.php';
class MyProxiedClass
{
public function sayHello() : string
return 'Hello!';
}
(static function () : void {
echo (new LazyLoadingValueHolderFactory())
->createProxy(
MyProxiedClass::class,
static function (
?object & $instance,
LazyLoadingInterface $proxy,
string $method,
array $parameters,
?\Closure & $initializer
) : bool {
$instance = new MyProxiedClass();
$initializer = null; // disable initialization
return true;
)
->sayHello();
$valueHolder = (new LazyLoadingValueHolderFactory())
->createProxy(MyProxiedClass::class, static function (
?object & $wrappedObject,
$wrappedObject = new MyProxiedClass();
});
$valueHolder->initializeProxy();
$wrappedValue = $valueHolder->getWrappedValueHolderValue();
assert(null !== $wrappedValue);
echo $wrappedValue->sayHello();
$valueHolder->setProxyInitializer(static function (
})();