本文整理汇总了PHP中Symfony\Component\DependencyInjection\Dumper\PhpDumper::dump方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpDumper::dump方法的具体用法?PHP PhpDumper::dump怎么用?PHP PhpDumper::dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Dumper\PhpDumper
的用法示例。
在下文中一共展示了PhpDumper::dump方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* Builds the container.
* @param array $parameters
*/
public function build($parameters = array())
{
// sort array by key to generate the container name
ksort($parameters);
// needed for new packages installed
$composerClass = array_filter(get_declared_classes(), function ($item) {
if (0 === strpos($item, 'ComposerAutoloaderInit')) {
return true;
}
});
$composerClass = array_pop($composerClass);
// generate hash
$parametersHash = md5(serialize($parameters) . $composerClass);
$containerClass = 'Container' . $parametersHash;
$isDebug = true;
$file = sprintf('%s/ladybug_cache/%s.php', sys_get_temp_dir(), $parametersHash);
$containerConfigCache = new ConfigCache($file, $isDebug);
if (!$containerConfigCache->isFresh()) {
$this->initializeContainer();
$this->loadServices();
$this->loadThemes();
$this->loadPlugins();
$this->setParameters($parameters);
$this->container->compile();
$dumper = new PhpDumper($this->container);
$containerConfigCache->write($dumper->dump(array('class' => $containerClass)), $this->container->getResources());
} else {
require_once $file;
$this->container = new $containerClass();
}
}
示例2: warmup
public static function warmup()
{
$containerFile = self::getCacheDir() . '/container.php';
$builder = self::getContainer();
$dumper = new PhpDumper($builder);
file_put_contents($containerFile, $dumper->dump());
}
示例3: dumpContainer
/**
* 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);
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'optimize_strings' => false));
$cache->write($content, $container->getResources());
}
示例4: boot
protected function boot()
{
if ($this->hasBooted()) {
return;
}
// Nothing to do
if ($this->debug) {
$this->setContainer(new ContainerBuilder(new ParameterBag($this->getAppParameters())));
$this->loadContainerConfiguration();
} else {
$filename = $this->getContainerCacheFilename();
if (file_exists($filename)) {
require_once $filename;
$this->setContainer(new CachedContainer());
} else {
$this->setContainer(new ContainerBuilder(new ParameterBag($this->getAppParameters())));
$this->loadContainerConfiguration();
$this->container->compile();
if ($this->containerIsCacheable()) {
$dumper = new PhpDumper($this->container);
file_put_contents($filename, $dumper->dump());
}
}
}
}
示例5: create
/**
* Loads a container and returns it.
*
* If the cache file for the service container exists and is current, it
* will be loaded and returned. Otherwise, a new container will be built
* using the configuration file and the provided optional builder. The
* builder will be used to make changes to the service container before
* it is compiled and cached.
*
* It may be important to note that debug mode for the `ConfigCache` class
* is enabled by default. This will ensure that cached configuration files
* are updated whenever they are changed.
*
* @param string $containerCacheFilePath The container cache file path.
* @param callable $containerBuilderCallable The new container builder callable.
* @param string $compiledContainerClassName The compiled container class name.
* @param boolean $debug Is debugging mode enabled?
*
* @return Jarvis The loaded application.
*/
public static function create($containerCacheFilePath, callable $containerBuilderCallable = null, $compiledContainerClassName = 'AppCachedContainer', $debug = true)
{
$cacheManager = new ConfigCache($containerCacheFilePath, $debug);
if (!$cacheManager->isFresh()) {
$container = static::createContainer();
if (null !== $containerBuilderCallable) {
$containerBuilderCallable($container);
}
if ($debug) {
$filename = pathinfo($containerCacheFilePath, PATHINFO_DIRNAME) . '/' . pathinfo($containerCacheFilePath, PATHINFO_FILENAME) . '.xml';
$container->setParameter('debug.container.dump', $filename);
}
$container->compile();
$dumper = new PhpDumper($container);
$cacheManager->write($dumper->dump(array('class' => $compiledContainerClassName)), $container->getResources());
if ($debug) {
$filename = $container->getParameter('debug.container.dump');
$dumper = new XmlDumper($container);
$filesystem = new Filesystem();
$filesystem->dumpFile($filename, $dumper->dump(), null);
try {
$filesystem->chmod($filename, 0666, umask());
} catch (IOException $e) {
// discard chmod failure (some filesystem may not support it)
}
}
}
if (!class_exists($compiledContainerClassName)) {
/** @noinspection PhpIncludeInspection */
require $containerCacheFilePath;
}
return new Jarvis(new $compiledContainerClassName());
}
示例6:
function it_uses_container_dump_to_create_the_cache(Filesystem $filesystem, ContainerDumperFactory $dumperFactory, ContainerBuilder $containerBuilder, PhpDumper $dumper)
{
$dumper->dump()->willReturn('file contents');
$dumperFactory->create($containerBuilder)->willReturn($dumper);
$this->dump($containerBuilder);
$filesystem->dumpFile($this->path, 'file contents')->shouldHaveBeenCalled();
}
示例7: compile
public function compile()
{
foreach (PluginRepository::findAll() as $plugin) {
$containerBuilder = new UnfreezableContainerBuilder();
$containerBuilder->registerExtension(new GeneralExtension());
$extensionClass = new \ReflectionClass('Stagehand\\TestRunner\\DependencyInjection\\Extension\\' . $plugin->getPluginID() . 'Extension');
if (!$extensionClass->isInterface() && !$extensionClass->isAbstract() && $extensionClass->isSubclassOf('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')) {
$containerBuilder->registerExtension($extensionClass->newInstance());
}
foreach ($containerBuilder->getExtensions() as $extension) {
/* @var $extension \Symfony\Component\DependencyInjection\Extension\ExtensionInterface */
$containerBuilder->loadFromExtension($extension->getAlias(), array());
}
$containerBuilder->addCompilerPass(new ReplaceDefinitionByPluginDefinitionPass($plugin));
$containerBuilder->getCompilerPassConfig()->setOptimizationPasses(array_filter($containerBuilder->getCompilerPassConfig()->getOptimizationPasses(), function (CompilerPassInterface $compilerPass) {
return !$compilerPass instanceof ResolveParameterPlaceHoldersPass;
}));
ErrorReporting::invokeWith(error_reporting() & ~E_USER_DEPRECATED, function () use($containerBuilder) {
$containerBuilder->compile();
});
$phpDumper = new PhpDumper($containerBuilder);
$containerClass = $plugin->getPluginID() . 'Container';
$containerClassSource = $phpDumper->dump(array('class' => $containerClass));
$containerClassSource = preg_replace('/^<\\?php/', '<?php' . PHP_EOL . 'namespace ' . self::COMPILED_CONTAINER_NAMESPACE . ';' . PHP_EOL, $containerClassSource);
file_put_contents(__DIR__ . '/../' . $containerClass . '.php', $containerClassSource);
}
}
示例8: buildContainer
/**
* @param BundleInterface[] $bundles
* @param array $configs
* @param bool $compile
*
* @return ContainerBuilder
*/
protected function buildContainer(array $bundles = [], array $configs = [], $compile = true)
{
$container = new ContainerBuilder(new ParameterBag(['kernel.debug' => false, 'kernel.bundles' => array_map('get_class', $bundles), 'kernel.cache_dir' => CACHE_DIR . 'test', 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__]));
$container->set('annotation_reader', new AnnotationReader());
$container->addObjectResource($container);
$extensions = [];
foreach ($bundles as $bundle) {
if ($extension = $bundle->getContainerExtension()) {
$container->registerExtension($extension);
$extensions[] = $extension->getAlias();
}
$container->addObjectResource($bundle);
}
foreach ($bundles as $bundle) {
$bundle->build($container);
}
foreach ($configs as $alias => $config) {
$container->prependExtensionConfig($alias, $config);
}
// ensure these extensions are implicitly loaded
$container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
foreach ($bundles as $bundle) {
$bundle->setContainer($container);
$bundle->boot();
}
$container->compile();
$dumper = new PhpDumper($container);
$dumper->dump();
return $container;
}
示例9:
function it_uses_config_cache_to_create_the_cache(Filesystem $filesystem, ContainerDumperFactory $dumperFactory, ContainerBuilder $containerBuilder, PhpDumper $dumper, ConfigCache $configCache)
{
$dumper->dump()->willReturn('file contents');
$dumperFactory->create($containerBuilder)->willReturn($dumper);
$containerBuilder->getResources()->willReturn([]);
$this->dump($containerBuilder);
$configCache->write('file contents', [])->shouldHaveBeenCalled();
}
示例10: dumpContainer
/**
* @param SymfonyRequest $symfonyRequest
* @param string $filePath
*/
private function dumpContainer(SymfonyRequest $symfonyRequest, $filePath)
{
$containerConfigCache = new ConfigCache($filePath, $this->appMode === ApplicationMode::DEVELOPMENT);
if (!$containerConfigCache->isFresh()) {
$containerBuilder = ServiceContainerBuilder::create($this->appPath, $symfonyRequest, $this->appMode);
$dumper = new PhpDumper($containerBuilder);
$containerConfigCache->write($dumper->dump(['class' => 'ACP3ServiceContainer']), $containerBuilder->getResources());
}
}
示例11: testDumpContainerWithProxyService
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.');
}
示例12: dumpContainer
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
{
$dumper = new PhpDumper($container);
$namespace = null;
if (($p = strrpos($class, "\\")) !== false) {
$namespace = substr($class, 0, $p);
$class = substr($class, $p + 1);
}
$content = $dumper->dump(["namespace" => $namespace, "class" => $class, "base_class" => $baseClass]);
$cache->write($content, $container->getResources());
}
示例13: getContainer
public function getContainer()
{
$container = new ContainerBuilder(new ParameterBag(array('kernel.bundle_dirs' => array(), 'kernel.bundles' => array(), 'kernel.cache_dir' => sys_get_temp_dir())));
$loader = new DoctrineMongoDBExtension();
$container->registerExtension($loader);
$loader->mongodbLoad(array(), $container);
$dumper = new PhpDumper($container);
$code = $dumper->dump(array('class' => 'DoctrineMongoDBBundleTestsProjectServiceContainer'));
eval(str_replace('<?php', null, $code));
return new \DoctrineMongoDBBundleTestsProjectServiceContainer();
}
示例14: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$file = sprintf('%s/%s', $this->getRoot(), $this->file);
$output->writeln('Caching the container:');
$output->writeln(sprintf("\tFile:\t\t%s", $file));
$container = \Maverick\bootstrap($this->getRoot(), true);
$container->compile();
$dumper = new PhpDumper($container);
$dumped = $dumper->dump(['namespace' => $this->namespace, 'class' => $this->class]);
file_put_contents($file, $dumped);
}
示例15: getDumpedContainer
protected function getDumpedContainer()
{
static $i = 0;
$class = 'PaginatorExtensionTestContainer' . $i++;
$this->container->compile();
$dumper = new PhpDumper($this->container);
eval('?>' . $dumper->dump(array('class' => $class)));
$container = new $class();
$container->enterScope('request');
$container->set('kernel', $this->kernel);
return $container;
}