Sets the dumper to be used when dumping proxies in the generated container.
public setProxyDumper ( Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface $proxyDumper ) | ||
$proxyDumper | Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface |
protected function getDumper(SymfonyBuilder $container) : DumperInterface { $dumper = new PhpDumper($container); if (class_exists(ProxyDumper::class)) { $dumper->setProxyDumper(new ProxyDumper()); } return $dumper; }
public function testDumpContainerWithProxyService() { $container = new ContainerBuilder(); $container->register('foo', 'stdClass'); $container->getDefinition('foo')->setLazy(true); $container->compile(); $dumper = new PhpDumper($container); $dumper->setProxyDumper(new ProxyDumper()); $dumpedString = $dumper->dump(); $this->assertStringMatchesFormatFile(__DIR__ . '/../Fixtures/php/lazy_service_structure.txt', $dumpedString, '->dump() does generate proxy lazy loading logic.'); }
/** * @param ContainerBuilder $container */ protected function dumpContainer(ContainerBuilder $container) { $debug = $container->getParameter('debug'); $randomId = mt_rand(); $className = sprintf('dic_%d', $randomId); $containerFile = ROOT . 'cache/dic.php'; $versionFile = ROOT . 'cache/dic.txt'; $configFile = ROOT . 'cache/config.json'; $dumper = new PhpDumper($container); $dumper->setProxyDumper(new ProxyDumper()); $containerContent = $dumper->dump(['class' => $className, 'debug' => $debug]); file_put_contents($containerFile, $containerContent); file_put_contents($versionFile, $className); file_put_contents($configFile, json_encode($container->getParameterBag()->all(), JSON_PRETTY_PRINT)); @chmod($containerFile, 0777); @chmod($versionFile, 0777); @chmod($configFile, 0777); }
/** * Dumps the service container to PHP code in the cache. * * @param ConfigCache $cache The config cache * @param ContainerBuilder $container The service container * @param string $class The name of the class to generate * @param string $baseClass The name of the container's base class */ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container); if (class_exists('ProxyManager\Configuration')) { $dumper->setProxyDumper(new ProxyDumper()); } $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass)); if (!$this->debug) { $content = static::stripComments($content); } $cache->write($content, $container->getResources()); }
/** * Dumps the service container to PHP code in the config directory. * * This method is based on the dumpContainer method in the parent class, but * that method is reliant on the Config component which we do not use here. * * @param ContainerBuilder $container * The service container. * @param string $baseClass * The name of the container's base class * * @return bool * TRUE if the container was successfully dumped to disk. */ protected function dumpDrupalContainer(ContainerBuilder $container, $baseClass) { if (!$this->storage()->writeable()) { return FALSE; } // Cache the container. $dumper = new PhpDumper($container); $dumper->setProxyDumper(new ProxyDumper(new ProxyBuilder())); $class = $this->getClassName(); $namespace = $this->getClassNamespace(); $content = $dumper->dump(['class' => $class, 'base_class' => $baseClass, 'namespace' => $namespace]); return $this->storage()->save($class . '.php', $content); }
/** * {@inheritdoc} */ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container); if ($container->getParameter('installed') && class_exists('ProxyManager\\Configuration') && class_exists('Symfony\\Bridge\\ProxyManager\\LazyProxy\\PhpDumper\\ProxyDumper')) { $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath()))); } $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => $cache->getPath())); if (!$this->debug) { $content = static::stripComments($content); } $cache->write($content, $container->getResources()); }
/** * {@inheritdoc} */ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container); if ($container->getParameter('installed') && class_exists('ProxyManager\\Configuration')) { $dumper->setProxyDumper(new ProxyDumper()); } $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass)); $cache->write($content, $container->getResources()); if (!$this->debug) { $cache->write(php_strip_whitespace($cache), $container->getResources()); } }
/** * Dumps the service container to PHP code in the cache. * * @param ConfigCache $cache The config cache * @param ContainerBuilder $container The service container * @param string $class The name of the class to generate * @param string $baseClass The name of the container's base class */ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container); if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper')) { $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath()))); } $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => $cache->getPath(), 'debug' => $this->debug)); $cache->write($content, $container->getResources()); }
/** * Dumps the service container to PHP code in the cache * * @param \Symfony\Component\Config\ConfigCache $cache */ protected function dumpContainer(ConfigCache $cache) { $dumper = new PhpDumper($this->innerContainer); if (class_exists('ProxyManager\\Configuration')) { $dumper->setProxyDumper(new ProxyDumper()); } $content = $dumper->dump(array('class' => $this->containerClassName, 'base_class' => "Container")); $cache->write($content, $this->innerContainer->getResources()); }
/** * Dump the container to the disk. * * @param ConfigCache $cache The config cache */ protected function dump_container($cache) { try { $dumper = new PhpDumper($this->container); $proxy_dumper = new ProxyDumper(); $dumper->setProxyDumper($proxy_dumper); $cached_container_dump = $dumper->dump(array('class' => 'phpbb_cache_container', 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder')); $cache->write($cached_container_dump, $this->container->getResources()); } catch (IOException $e) { // Don't fail if the cache isn't writeable } }
/** * {@inheritdoc} */ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container); if ($container->getParameter('installed') && class_exists('ProxyManager\\Configuration') && class_exists('Symfony\\Bridge\\ProxyManager\\LazyProxy\\PhpDumper\\ProxyDumper')) { $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath()))); } $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => $cache->getPath())); $cache->write($content, $container->getResources()); // we should not use parent::stripComments method to cleanup source code from the comments to avoid // memory leaks what generate token_get_all function. if (!$this->debug) { $cache->write(php_strip_whitespace($cache->getPath()), $container->getResources()); } }
/** * @param \Heystack\Core\DependencyInjection\SilverStripe\HeystackSilverStripeContainerBuilder $container * @param stirng $mode * @param bool|void $debug * @return string */ protected function dumpContainer(HeystackSilverStripeContainerBuilder $container, $mode, $debug = false) { $container->compile(); if ($debug) { $dumper = new YamlDumper($container); return $dumper->dump(); } else { $location = $this->heystackBasePath . '/cache/'; if (!file_exists($location)) { mkdir($location, 0777, true); } $class = "HeystackServiceContainer{$mode}"; $dumper = new PhpDumper($container); if (class_exists('Symfony\\Bridge\\ProxyManager\\LazyProxy\\PhpDumper\\ProxyDumper')) { $dumper->setProxyDumper(new ProxyDumper()); } file_put_contents($this->getRealPath($location) . "/{$class}.php", $dumper->dump(['class' => $class, 'base_class' => "Heystack\\Core\\DependencyInjection\\SilverStripe\\HeystackSilverStripeContainer"])); return 'Container generated'; } }
public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServices() { /* * test graph: * [connection] -> [event_manager] --> [entity_manager](lazy) * | * --(call)- addEventListener ("@lazy_service") * * [lazy_service](lazy) -> [entity_manager](lazy) * */ $container = new ContainerBuilder(); $eventManagerDefinition = new Definition('stdClass'); $connectionDefinition = $container->register('connection', 'stdClass'); $connectionDefinition->addArgument($eventManagerDefinition); $container->register('entity_manager', 'stdClass') ->setLazy(true) ->addArgument(new Reference('connection')); $lazyServiceDefinition = $container->register('lazy_service', 'stdClass'); $lazyServiceDefinition->setLazy(true); $lazyServiceDefinition->addArgument(new Reference('entity_manager')); $eventManagerDefinition->addMethodCall('addEventListener', array(new Reference('lazy_service'))); $container->compile(); $dumper = new PhpDumper($container); $dumper->setProxyDumper(new DummyProxyDumper()); $dumper->dump(); }