/usr/share/php/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php is in php-symfony-proxy-manager-bridge 2.3.21+dfsg-4+deb8u3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | <?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper;
use ProxyManager\Generator\ClassGenerator;
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
/**
* Generates dumped PHP code of proxies via reflection.
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class ProxyDumper implements DumperInterface
{
/**
* @var \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator
*/
private $proxyGenerator;
/**
* @var \ProxyManager\GeneratorStrategy\BaseGeneratorStrategy
*/
private $classGenerator;
/**
* Constructor
*/
public function __construct()
{
$this->proxyGenerator = new LazyLoadingValueHolderGenerator();
$this->classGenerator = new BaseGeneratorStrategy();
}
/**
* {@inheritdoc}
*/
public function isProxyCandidate(Definition $definition)
{
return $definition->isLazy() && ($class = $definition->getClass()) && class_exists($class);
}
/**
* {@inheritdoc}
*/
public function getProxyFactoryCode(Definition $definition, $id)
{
$instantiation = 'return';
if (ContainerInterface::SCOPE_CONTAINER === $definition->getScope()) {
$instantiation .= " \$this->services['$id'] =";
} elseif (ContainerInterface::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) {
$instantiation .= " \$this->services['$id'] = \$this->scopedServices['$scope']['$id'] =";
}
$methodName = 'get'.Container::camelize($id).'Service';
$proxyClass = $this->getProxyClassName($definition);
return <<<EOF
if (\$lazyLoad) {
\$container = \$this;
$instantiation new $proxyClass(
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) use (\$container) {
\$wrappedInstance = \$container->$methodName(false);
\$proxy->setProxyInitializer(null);
return true;
}
);
}
EOF;
}
/**
* {@inheritdoc}
*/
public function getProxyCode(Definition $definition)
{
$generatedClass = new ClassGenerator($this->getProxyClassName($definition));
$this->proxyGenerator->generate(new \ReflectionClass($definition->getClass()), $generatedClass);
return $this->classGenerator->generate($generatedClass);
}
/**
* Produces the proxy class name for the given definition.
*
* @param Definition $definition
*
* @return string
*/
private function getProxyClassName(Definition $definition)
{
return str_replace('\\', '', $definition->getClass()).'_'.spl_object_hash($definition);
}
}
|