当前位置: 首页>>代码示例>>PHP>>正文


PHP ContainerBuilder::addObjectResource方法代码示例

本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::addObjectResource方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::addObjectResource方法的具体用法?PHP ContainerBuilder::addObjectResource怎么用?PHP ContainerBuilder::addObjectResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DependencyInjection\ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder::addObjectResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * {@inheritDoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $extensionManager = new ExtensionManager();
     foreach ($configs as $config) {
         if (!isset($config['extensions'])) {
             continue;
         }
         foreach ($config['extensions'] as $config) {
             if (!isset($config['class'])) {
                 continue;
             }
             $extensionManager->activateExtension($config['class']);
         }
     }
     $configuration = new Configuration($extensionManager->getActivatedExtensions());
     $config = $this->processConfiguration($configuration, $configs);
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../resources'));
     $loader->load('services.xml');
     foreach ($extensionManager->getActivatedExtensions() as $extension) {
         $extensionConfig = $config['extensions'][$extension->getName()];
         $tempContainer = new ContainerBuilder(new ParameterBag(array()));
         $tempContainer->addObjectResource($extension);
         // load extension into temporary container
         $extension->load($extensionConfig, $tempContainer);
         // merge temporary container into normal one
         $container->merge($tempContainer);
     }
     $settings = $this->createSettings($config);
     $configurationDefinition = $container->findDefinition('pdepend.configuration');
     $configurationDefinition->setArguments(array($settings));
 }
开发者ID:Jvbzephir,项目名称:pdepend,代码行数:34,代码来源:PdependExtension.php

示例2: 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;
 }
开发者ID:bankiru,项目名称:doctrine-api-bundle,代码行数:37,代码来源:ContainerTest.php

示例3: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $parameters = $container->getParameterBag()->all();
     $definitions = $container->getDefinitions();
     $aliases = $container->getAliases();
     $exprLangProviders = $container->getExpressionLanguageProviders();
     foreach ($container->getExtensions() as $extension) {
         if ($extension instanceof PrependExtensionInterface) {
             $extension->prepend($container);
         }
     }
     foreach ($container->getExtensions() as $name => $extension) {
         if (!($config = $container->getExtensionConfig($name))) {
             // this extension was not called
             continue;
         }
         $config = $container->getParameterBag()->resolveValue($config);
         $tmpContainer = new ContainerBuilder($container->getParameterBag());
         $tmpContainer->setResourceTracking($container->isTrackingResources());
         $tmpContainer->addObjectResource($extension);
         foreach ($exprLangProviders as $provider) {
             $tmpContainer->addExpressionLanguageProvider($provider);
         }
         $extension->load($config, $tmpContainer);
         $container->merge($tmpContainer);
         $container->getParameterBag()->add($parameters);
     }
     $container->addDefinitions($definitions);
     $container->addAliases($aliases);
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:33,代码来源:MergeExtensionConfigurationPass.php

示例4: addRegisterClassNamedServicesPass

 private function addRegisterClassNamedServicesPass(ContainerBuilder $builder)
 {
     $compilerPass = new RegisterClassNamedServicesPass();
     $passConfig = $builder->getCompilerPassConfig();
     $passes = $passConfig->getOptimizationPasses();
     foreach ($passes as $key => $pass) {
         if ($pass instanceof ResolveReferencesToAliasesPass) {
             array_splice($passes, $key, 0, [$compilerPass]);
             break;
         }
     }
     $passConfig->setOptimizationPasses($passes);
     $builder->addObjectResource($compilerPass);
 }
开发者ID:symfonette,项目名称:class-named-services,代码行数:14,代码来源:ContainerBuilderConfigurator.php

示例5: load

 /**
  * Loads a specific configuration.
  *
  * @param array            $config    An array of configuration values
  * @param ContainerBuilder $container A ContainerBuilder instance
  *
  * @throws \InvalidArgumentException When provided tag is not defined in this extension
  *
  * @api
  */
 public function load(array $config, ContainerBuilder $container)
 {
     $container->addObjectResource($this);
     $configuration = $this->getConfiguration($config, $container);
     if ($configuration instanceof ConfigurationInterface) {
         $config = $this->processConfiguration($configuration, $config);
         $this->applyParametrizedValues($config, $container);
     }
     $configFiles = $this->getConfigFiles($config);
     if (!empty($configFiles)) {
         $this->loadFiles($configFiles, $container);
     }
     $this->postLoad($config, $container);
 }
开发者ID:axelvnk,项目名称:elcodi,代码行数:24,代码来源:AbstractExtension.php

示例6: process

 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     $parameters = $container->getParameterBag()->all();
     $definitions = $container->getDefinitions();
     $aliases = $container->getAliases();
     foreach ($container->getExtensions() as $name => $extension) {
         $tmpContainer = new ContainerBuilder($container->getParameterBag());
         $tmpContainer->addObjectResource($extension);
         $extension->load($container->getExtensionConfig($name), $tmpContainer);
         $container->merge($tmpContainer);
     }
     $container->addDefinitions($definitions);
     $container->addAliases($aliases);
     $container->getParameterBag()->add($parameters);
 }
开发者ID:noelg,项目名称:symfony-demo,代码行数:18,代码来源:MergeExtensionConfigurationPass.php

示例7: process

 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     $parameters = $container->getParameterBag()->all();
     $definitions = $container->getDefinitions();
     $aliases = $container->getAliases();
     foreach ($container->getExtensionConfigs() as $name => $configs) {
         list($namespace, $tag) = explode(':', $name);
         $extension = $container->getExtension($namespace);
         $tmpContainer = new ContainerBuilder($container->getParameterBag());
         $tmpContainer->addObjectResource($extension);
         $extension->load($tag, $configs, $tmpContainer);
         $container->merge($tmpContainer);
     }
     $container->addDefinitions($definitions);
     $container->addAliases($aliases);
     $container->getParameterBag()->add($parameters);
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:20,代码来源:MergeExtensionConfigurationPass.php

示例8: prepareContainer

 protected function prepareContainer(ContainerBuilder $container)
 {
     $extensions = [];
     foreach ($this->bundles as $bundle) {
         if ($extension = $bundle->getContainerExtension()) {
             $container->registerExtension($extension);
             $extensions[] = $extension->getAlias();
         }
         if ($this->debug) {
             $container->addObjectResource($bundle);
         }
     }
     foreach ($this->bundles as $bundle) {
         $bundle->build($container);
     }
     $this->buildBundleless($container);
     // ensure these extensions are implicitly loaded
     $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
 }
开发者ID:rollerworks,项目名称:datagrid-bundle,代码行数:19,代码来源:AppKernel.php

示例9: process

 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     $parameters = $container->getParameterBag()->all();
     $definitions = $container->getDefinitions();
     $aliases = $container->getAliases();
     foreach ($container->getExtensions() as $name => $extension) {
         if (!($config = $container->getExtensionConfig($name))) {
             // this extension was not called
             continue;
         }
         $config = $container->getParameterBag()->resolveValue($config);
         $tmpContainer = new ContainerBuilder($container->getParameterBag());
         $tmpContainer->addObjectResource($extension);
         $extension->load($config, $tmpContainer);
         $container->merge($tmpContainer);
     }
     $container->addDefinitions($definitions);
     $container->addAliases($aliases);
     $container->getParameterBag()->add($parameters);
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:23,代码来源:MergeExtensionConfigurationPass.php

示例10: create

 /**
  * Returns a new created container instance.
  *
  * @param string $environment
  * @param bool   $debug
  *
  * @return ContainerInterface
  */
 public function create($environment, $debug = false)
 {
     $cachedContainerClassName = ucfirst($environment) . ($debug ? 'Debug' : '') . 'Container';
     $cache = new ConfigCache($this->cacheDir . '/' . $cachedContainerClassName . '.php', $debug);
     if (!$cache->isFresh()) {
         $container = new ContainerBuilder(new ParameterBag(['environment' => $environment, 'debug' => $debug]));
         $container->addObjectResource($this);
         foreach ($this->loaders as $loader) {
             (new ClosureLoader($container))->load($loader);
         }
         $container->compile();
         $dumper = new PhpDumper($container);
         $content = $dumper->dump(['class' => stristr(basename($cache->getPath()), '.', true)]);
         $cache->write($debug ? $content : self::stripComments($content), $container->getResources());
         if ($debug) {
             self::dumpForDebug(preg_replace('/\\.php/', '.xml', $cache->getPath()), $container);
         }
     }
     require_once $cache->getPath();
     return new $cachedContainerClassName();
 }
开发者ID:issei-m,项目名称:symfony-dic-demo,代码行数:29,代码来源:ContainerFactory.php

示例11: dumpContainer

 protected function dumpContainer(ContainerBuilder $container, $class, $file)
 {
     foreach (array('cache', 'logs') as $name) {
         $dir = $container->getParameter(sprintf('kernel.%s_dir', $name));
         if (!is_dir($dir)) {
             if (false === @mkdir($dir, 0777, true)) {
                 die(sprintf('Unable to create the %s directory (%s)', $name, dirname($dir)));
             }
         } elseif (!is_writable($dir)) {
             die(sprintf('Unable to write in the %s directory (%s)', $name, $dir));
         }
     }
     // cache the container
     $dumper = new PhpDumper($container);
     $content = $dumper->dump(array('class' => $class));
     if (!$this->debug) {
         $content = self::stripComments($content);
     }
     $this->writeCacheFile($file, $content);
     if ($this->debug) {
         $container->addObjectResource($this);
         // save the resources
         $this->writeCacheFile($this->getCacheDir() . '/' . $class . '.meta', serialize($container->getResources()));
     }
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:25,代码来源:Kernel.php

示例12: createContainer

 /**
  * Construct a new container.
  *
  * @var ContainerBuilder
  * @return \Symfony\Component\DependencyInjection\ContainerBuilder
  */
 public function createContainer()
 {
     $civicrm_base_path = dirname(dirname(__DIR__));
     $container = new ContainerBuilder();
     $container->addCompilerPass(new RegisterListenersPass('dispatcher'));
     $container->addObjectResource($this);
     $container->setParameter('civicrm_base_path', $civicrm_base_path);
     //$container->set(self::SELF, $this);
     $container->setDefinition(self::SELF, new Definition('Civi\\Core\\Container', array()));
     // TODO Move configuration to an external file; define caching structure
     //    if (empty($configDirectories)) {
     //      throw new \Exception(__CLASS__ . ': Missing required properties (civicrmRoot, configDirectories)');
     //    }
     //    $locator = new FileLocator($configDirectories);
     //    $loaderResolver = new LoaderResolver(array(
     //      new YamlFileLoader($container, $locator)
     //    ));
     //    $delegatingLoader = new DelegatingLoader($loaderResolver);
     //    foreach (array('services.yml') as $file) {
     //      $yamlUserFiles = $locator->locate($file, NULL, FALSE);
     //      foreach ($yamlUserFiles as $file) {
     //        $delegatingLoader->load($file);
     //      }
     //    }
     $container->setDefinition('angular', new Definition('Civi\\Angular\\Manager', array()))->setFactoryService(self::SELF)->setFactoryMethod('createAngularManager');
     $container->setDefinition('dispatcher', new Definition('Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher', array(new Reference('service_container'))))->setFactoryService(self::SELF)->setFactoryMethod('createEventDispatcher');
     $container->setDefinition('magic_function_provider', new Definition('Civi\\API\\Provider\\MagicFunctionProvider', array()));
     $container->setDefinition('civi_api_kernel', new Definition('Civi\\API\\Kernel', array(new Reference('dispatcher'), new Reference('magic_function_provider'))))->setFactoryService(self::SELF)->setFactoryMethod('createApiKernel');
     $container->setDefinition('cxn_reg_client', new Definition('Civi\\Cxn\\Rpc\\RegistrationClient', array()))->setFactoryClass('CRM_Cxn_BAO_Cxn')->setFactoryMethod('createRegistrationClient');
     $container->setDefinition('psr_log', new Definition('CRM_Core_Error_Log', array()));
     foreach (array('js_strings', 'community_messages') as $cacheName) {
         $container->setDefinition("cache.{$cacheName}", new Definition('CRM_Utils_Cache_Interface', array(array('name' => $cacheName, 'type' => array('*memory*', 'SqlGroup', 'ArrayCache')))))->setFactoryClass('CRM_Utils_Cache')->setFactoryMethod('create');
     }
     $container->setDefinition('pear_mail', new Definition('Mail'))->setFactoryClass('CRM_Utils_Mail')->setFactoryMethod('createMailer');
     if (empty(\Civi::$statics[__CLASS__]['boot'])) {
         throw new \RuntimeException("Cannot initialize container. Boot services are undefined.");
     }
     foreach (\Civi::$statics[__CLASS__]['boot'] as $bootService => $def) {
         $container->setDefinition($bootService, new Definition($def['class'], array($bootService)))->setFactoryClass(__CLASS__)->setFactoryMethod('getBootService');
     }
     // Expose legacy singletons as services in the container.
     $singletons = array('resources' => 'CRM_Core_Resources', 'httpClient' => 'CRM_Utils_HttpClient', 'cache.default' => 'CRM_Utils_Cache', 'i18n' => 'CRM_Core_I18n');
     foreach ($singletons as $name => $class) {
         $container->setDefinition($name, new Definition($class))->setFactoryClass($class)->setFactoryMethod('singleton');
     }
     $container->setDefinition('civi_token_compat', new Definition('Civi\\Token\\TokenCompatSubscriber', array()))->addTag('kernel.event_subscriber');
     foreach (array('Activity', 'Contribute', 'Event', 'Member') as $comp) {
         $container->setDefinition("crm_" . strtolower($comp) . "_tokens", new Definition("CRM_{$comp}_Tokens", array()))->addTag('kernel.event_subscriber');
     }
     \CRM_Utils_Hook::container($container);
     return $container;
 }
开发者ID:rameshrr99,项目名称:civicrm-core,代码行数:58,代码来源:Container.php

示例13: buildContainer

    /**
     * Builds the service container.
     *
     * @return ContainerBuilder The compiled service container
     */
    protected function buildContainer()
    {
        foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) {
            if (!is_dir($dir)) {
                if (false === @mkdir($dir, 0777, true)) {
                    throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir));
                }
            } elseif (!is_writable($dir)) {
                throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
            }
        }

        $container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
        $extensions = array();
        foreach ($this->bundles as $bundle) {
            if ($extension = $bundle->getContainerExtension()) {
                $container->registerExtension($extension);
                $extensions[] = $extension->getAlias();
            }

            if ($this->debug) {
                $container->addObjectResource($bundle);
            }
        }
        foreach ($this->bundles as $bundle) {
            $bundle->build($container);
        }

        $container->addObjectResource($this);

        // ensure these extensions are implicitly loaded
        $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));

        if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
            $container->merge($cont);
        }

        $container->addCompilerPass(new AddClassesToCachePass($this));
        $container->compile();

        return $container;
    }
开发者ID:usefulthink,项目名称:symfony,代码行数:47,代码来源:Kernel.php

示例14: loadInternal

 public function loadInternal(array $config, ContainerBuilder $container)
 {
     $loader = new XmlFileLoader($container, new FileLocator(array(__DIR__ . '/../Resources/config/')));
     $loader->load('services.xml');
     // add factories as resource
     foreach ($this->factories as $factory) {
         $container->addObjectResource($factory);
     }
     // property naming
     $container->getDefinition('jms_serializer.camel_case_naming_strategy')->addArgument($config['property_naming']['separator'])->addArgument($config['property_naming']['lower_case']);
     if ($config['property_naming']['enable_cache']) {
         $container->getDefinition('jms_serializer.cache_naming_strategy')->addArgument(new Reference((string) $container->getAlias('jms_serializer.naming_strategy')));
         $container->setAlias('jms_serializer.naming_strategy', 'jms_serializer.cache_naming_strategy');
     }
     // gather handlers
     $serializationHandlers = $deserializationHandlers = array();
     foreach ($config['handlers'] as $k => $handlerConfig) {
         $id = $this->factories[$k]->getHandlerId($container, $handlerConfig);
         $type = $this->factories[$k]->getType($handlerConfig);
         if (0 !== ($type & HandlerFactoryInterface::TYPE_SERIALIZATION)) {
             $serializationHandlers[] = new Reference($id);
         }
         if (0 !== ($type & HandlerFactoryInterface::TYPE_DESERIALIZATION)) {
             $deserializationHandlers[] = new Reference($id);
         }
     }
     foreach (array('json', 'xml', 'yaml') as $format) {
         $container->getDefinition('jms_serializer.' . $format . '_serialization_visitor')->replaceArgument(1, $serializationHandlers);
     }
     foreach (array('json', 'xml') as $format) {
         $container->getDefinition('jms_serializer.' . $format . '_deserialization_visitor')->replaceArgument(1, $deserializationHandlers);
     }
     // metadata
     if ('none' === $config['metadata']['cache']) {
         $container->removeAlias('jms_serializer.metadata.cache');
     } elseif ('file' === $config['metadata']['cache']) {
         $container->getDefinition('jms_serializer.metadata.cache.file_cache')->replaceArgument(0, $config['metadata']['file_cache']['dir']);
         $dir = $container->getParameterBag()->resolveValue($config['metadata']['file_cache']['dir']);
         if (!file_exists($dir)) {
             if (!($rs = @mkdir($dir, 0777, true))) {
                 throw new RuntimeException(sprintf('Could not create cache directory "%s".', $dir));
             }
         }
     } else {
         $container->setAlias('jms_serializer.metadata.cache', new Alias($config['metadata']['cache'], false));
     }
     $container->getDefinition('jms_serializer.metadata_factory')->replaceArgument(2, $config['metadata']['debug']);
     // directories
     $directories = array();
     $bundles = $container->getParameter('kernel.bundles');
     if ($config['metadata']['auto_detection']) {
         foreach ($bundles as $name => $class) {
             $ref = new \ReflectionClass($class);
             $directories[$ref->getNamespaceName()] = dirname($ref->getFileName()) . '/Resources/config/serializer';
         }
     }
     foreach ($config['metadata']['directories'] as $directory) {
         $directory['path'] = rtrim(str_replace('\\', '/', $directory['path']), '/');
         if ('@' === $directory['path'][0]) {
             $bundleName = substr($directory['path'], 1, strpos($directory['path'], '/') - 1);
             if (!isset($bundles[$bundleName])) {
                 throw new RuntimeException(sprintf('The bundle "%s" has not been registered with AppKernel. Available bundles: %s', $bundleName, implode(', ', array_keys($bundles))));
             }
             $ref = new \ReflectionClass($bundles[$bundleName]);
             $directory['path'] = dirname($ref->getFileName()) . substr($directory['path'], strlen('@' . $bundleName));
         }
         $directories[rtrim($directory['namespace_prefix'], '\\')] = rtrim($directory['path'], '\\/');
     }
     $container->getDefinition('jms_serializer.metadata.file_locator')->replaceArgument(0, $directories);
     $container->setParameter('jms_serializer.json_serialization_visitor.options', $config['visitors']['json']['options']);
     $container->setParameter('jms_serializer.xml_deserialization_visitor.doctype_whitelist', $config['visitors']['xml']['doctype_whitelist']);
 }
开发者ID:ramol,项目名称:JMSSerializerBundle,代码行数:72,代码来源:JMSSerializerExtension.php

示例15: addObjectResource

 public function addObjectResource($object)
 {
     return $this->delegate->addObjectResource($object);
 }
开发者ID:planetenkiller,项目名称:core,代码行数:4,代码来源:SandboxContainerBuilder.php


注:本文中的Symfony\Component\DependencyInjection\ContainerBuilder::addObjectResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。