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


PHP ContainerBuilder::getAlias方法代码示例

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


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

示例1: definitionClass

 /**
  * @param string $id
  * @return string
  */
 public function definitionClass(string $id) : string
 {
     if ($this->builder->hasAlias($id)) {
         return $this->builder->getDefinition((string) $this->builder->getAlias($id))->getClass()->getClass();
     }
     return $this->builder->getDefinition($id)->getClass();
 }
开发者ID:dumplie,项目名称:dumplie,代码行数:11,代码来源:ServiceContainer.php

示例2: process

    public function process( ContainerBuilder $container )
    {
        if ( !$container->hasAlias( 'session.storage' ) )
        {
            return;
        }

        $sessionStorageAlias = $container->getAlias( 'session.storage' );
        $sessionStorageProxyDef = $container->findDefinition( 'ezpublish_legacy.session_storage_proxy' );
        $sessionStorageProxyDef->replaceArgument( 1, new Reference( (string)$sessionStorageAlias ) );
        $container->setAlias( 'session.storage', 'ezpublish_legacy.session_storage_proxy' );

        if ( $container->hasAlias( 'session.handler' ) )
        {
            $sessionHandlerAlias = $container->getAlias( 'session.handler' );
            $interfaces = class_implements( $container->findDefinition( (string)$sessionHandlerAlias ) );
            // Only swap session handler if it implements appropriate interface.
            if ( isset( $interfaces['SessionHandlerInterface'] ) )
            {
                $sessionHandlerProxyDef = $container->findDefinition( 'ezpublish_legacy.session_handler_proxy' );
                $sessionHandlerProxyDef->replaceArgument( 1, new Reference( (string)$sessionHandlerAlias ) );
                $container->setAlias( 'session.handler', 'ezpublish_legacy.session_handler_proxy' );
            }
        }
    }
开发者ID:ezsystemstraining,项目名称:ez54training,代码行数:25,代码来源:LegacySessionPass.php

示例3: testDriverIsAliased

 public function testDriverIsAliased()
 {
     $config = ['driver' => 'doctrine'];
     $this->extension->load([$config], $this->container);
     $alias = $this->container->getAlias('bernard.driver');
     $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Alias', $alias);
     $this->assertEquals('bernard.driver.doctrine', (string) $alias);
 }
开发者ID:johanderuijter,项目名称:BernardBundle,代码行数:8,代码来源:BernardExtensionTest.php

示例4: testSerializerServiceCanBeJmsSerializer

 public function testSerializerServiceCanBeJmsSerializer()
 {
     $this->container->register('jms_serializer.serializer', 'JMS\\Serializer\\Serializer');
     $this->container->register('serializer', 'JMS\\Serializer\\Serializer');
     $compiler = new SerializerConfigurationPass();
     $compiler->process($this->container);
     $this->assertSame('fos_rest.serializer.jms', (string) $this->container->getAlias('fos_rest.serializer'));
 }
开发者ID:sblaut,项目名称:FOSRestBundle,代码行数:8,代码来源:SerializerConfigurationPassTest.php

示例5: process

 public function process(ContainerBuilder $container)
 {
     // "query.max_query_count" is an array, it is only accessible
     // through "query" node and getting the "max_query_count" array
     // key with PHP.
     $query = $container->getParameter('liip_functional_test.query');
     if (null === $query['max_query_count']) {
         $container->removeDefinition('liip_functional_test.query.count_client');
         return;
     }
     if ($container->hasDefinition('test.client')) {
         // test.client is a definition.
         // Register it again as a private service to inject it as the parent
         $definition = $container->getDefinition('test.client');
         $definition->setPublic(false);
         $container->setDefinition('liip_functional_test.query.count_client.parent', $definition);
     } elseif ($container->hasAlias('test.client')) {
         // test.client is an alias.
         // Register a private alias for this service to inject it as the parent
         $container->setAlias('liip_functional_test.query.count_client.parent', new Alias((string) $container->getAlias('test.client'), false));
     } else {
         throw new \Exception('The LiipFunctionalTestBundle\'s Query Counter can only be used in the test environment.' . PHP_EOL . 'See https://github.com/liip/LiipFunctionalTestBundle#only-in-test-environment');
     }
     $container->setAlias('test.client', 'liip_functional_test.query.count_client');
 }
开发者ID:Kilix,项目名称:LiipFunctionalTestBundle,代码行数:25,代码来源:SetTestClientPass.php

示例6: process

 public function process(ContainerBuilder $container)
 {
     $definitions = new \SplPriorityQueue();
     $order = PHP_INT_MAX;
     foreach ($container->getDefinitions() as $id => $definition) {
         if (!($decorated = $definition->getDecoratedService())) {
             continue;
         }
         $definitions->insert(array($id, $definition), array($decorated[2], --$order));
     }
     foreach ($definitions as list($id, $definition)) {
         list($inner, $renamedId) = $definition->getDecoratedService();
         $definition->setDecoratedService(null);
         if (!$renamedId) {
             $renamedId = $id . '.inner';
         }
         // we create a new alias/service for the service we are replacing
         // to be able to reference it in the new one
         if ($container->hasAlias($inner)) {
             $alias = $container->getAlias($inner);
             $public = $alias->isPublic();
             $container->setAlias($renamedId, new Alias((string) $alias, false));
         } else {
             $definition = $container->getDefinition($inner);
             $public = $definition->isPublic();
             $definition->setPublic(false);
             $container->setDefinition($renamedId, $definition);
         }
         $container->setAlias($inner, new Alias($id, $public));
     }
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:31,代码来源:DecoratorServicePass.php

示例7: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $tags = $container->findTaggedServiceIds($this->tagName);
     foreach ($tags as $id => $tag) {
         /** @var Definition $serviceLinkDef */
         $serviceLinkDef = $container->getDefinition($id);
         if (!isset($tag[0]['service'])) {
             throw new InvalidArgumentException(sprintf('Tag "%s" for service "%s" does not have required param "service"', $this->tagName, $id));
         }
         $serviceId = $tag[0]['service'];
         $isOptional = false;
         if (strpos($serviceId, '?') === 0) {
             $serviceId = substr($serviceId, 1);
             $isOptional = true;
         }
         if ($container->hasDefinition($serviceId)) {
             // the service we are referring to must be public
             $serviceDef = $container->getDefinition($serviceId);
             if (!$serviceDef->isPublic()) {
                 $serviceDef->setPublic(true);
             }
         } elseif ($container->hasAlias($serviceId)) {
             // the service alias we are referring to must be public
             $serviceAlias = $container->getAlias($serviceId);
             if (!$serviceAlias->isPublic()) {
                 $serviceAlias->setPublic(true);
             }
         } elseif (!$isOptional) {
             throw new InvalidArgumentException(sprintf('Target service "%s" is undefined. The service link "%s" with tag "%s" and tag-service "%s"', $serviceId, $id, $this->tagName, $serviceId));
         }
         $serviceLinkDef->setClass($this->decoratorClass)->setPublic(false)->setArguments([new Reference('service_container'), $serviceId, $isOptional]);
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:36,代码来源:ServiceLinkCompilerPass.php

示例8: process

 /**
  * You can modify the container here before it is dumped to PHP code.
  *
  * @param ContainerBuilder $container
  *
  * @api
  */
 public function process(ContainerBuilder $container)
 {
     $config = $container->getParameter(ElastificationPhpClientExtension::PARAMETER_CONFIG_KEY);
     if (true === $config['profiler_enabled']) {
         $clientAlias = $container->getAlias(ElastificationPhpClientExtension::ALIAS_CLIENT);
         $profilerDef = $container->getDefinition(ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY);
         $profilerDef->replaceArgument(0, new Reference($clientAlias->__toString()));
         $dataCollectorDef = $container->getDefinition('elastification_php_client.datacollector');
         $dataCollectorDef->addMethodCall('setConfig', array($config));
         $container->setAlias(ElastificationPhpClientExtension::ALIAS_CLIENT, ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY);
     } else {
         if ($container->hasDefinition('profiler')) {
             $sfProfilerDef = $container->getDefinition('profiler');
             $sfProfilerMethodCalls = $sfProfilerDef->getMethodCalls();
             foreach ($sfProfilerMethodCalls as $sfProfilerMethodCallsIndex => $sfProfilerMethodCall) {
                 if (isset($sfProfilerMethodCall[1][0]) && 'elastification_php_client.datacollector' == (string) $sfProfilerMethodCall[1][0]) {
                     unset($sfProfilerMethodCalls[$sfProfilerMethodCallsIndex]);
                 }
             }
             $sfProfilerDef->setMethodCalls($sfProfilerMethodCalls);
         }
         $container->removeDefinition(ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY);
         $container->removeDefinition('elastification_php_client.datacollector');
     }
 }
开发者ID:elastification,项目名称:php-client-bundle,代码行数:32,代码来源:ProfilerCompilerPass.php

示例9: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $tags = $container->findTaggedServiceIds(self::TAG_NAME);
     foreach ($tags as $id => $tag) {
         /** @var Definition $serviceLinkDef */
         $serviceLinkDef = $container->getDefinition($id);
         if (!isset($tag[0]['service'])) {
             throw new RuntimeException(sprintf('Tag "%s" for service "%s" does not have required param "service"', self::TAG_NAME, $id));
         }
         $serviceId = $tag[0]['service'];
         $isOptional = false;
         if (strpos($serviceId, '?') === 0) {
             $serviceId = substr($serviceId, 1);
             $isOptional = true;
         }
         if ($container->hasDefinition($serviceId)) {
             // the service we are referring to must be public
             $serviceDef = $container->getDefinition($serviceId);
             if (!$serviceDef->isPublic()) {
                 $serviceDef->setPublic(true);
             }
         } elseif ($container->hasAlias($serviceId)) {
             // the service alias we are referring to must be public
             $serviceAlias = $container->getAlias($serviceId);
             if (!$serviceAlias->isPublic()) {
                 $serviceAlias->setPublic(true);
             }
         } elseif (!$isOptional) {
             throw new RuntimeException(sprintf('Target service "%s" is undefined. The service link "%s" with tag "%s" and tag-service "%s"', $serviceId, $id, self::TAG_NAME, $serviceId));
         }
         $serviceLinkDef->setClass('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->setPublic(false)->setArguments([new Reference('service_container'), $serviceId, $isOptional]);
     }
 }
开发者ID:northdakota,项目名称:platform,代码行数:36,代码来源:ServiceLinkPass.php

示例10: process

 /**
  * @see Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface::process()
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition('foq_elastica.provider_registry')) {
         return;
     }
     // Infer the default index name from the service alias
     $defaultIndex = substr($container->getAlias('foq_elastica.index'), 19);
     $registry = $container->getDefinition('foq_elastica.provider_registry');
     $providers = $container->findTaggedServiceIds('foq_elastica.provider');
     foreach ($providers as $providerId => $tags) {
         $index = $type = null;
         $class = $container->getDefinition($providerId)->getClass();
         if (!$class || !$this->isProviderImplementation($class)) {
             throw new \InvalidArgumentException(sprintf('Elastica provider "%s" with class "%s" must implement ProviderInterface.', $providerId, $class));
         }
         foreach ($tags as $tag) {
             if (!isset($tag['type'])) {
                 throw new \InvalidArgumentException(sprintf('Elastica provider "%s" must specify the "type" attribute.', $providerId));
             }
             $index = isset($tag['index']) ? $tag['index'] : $defaultIndex;
             $type = $tag['type'];
         }
         $registry->addMethodCall('addProvider', array($index, $type, $providerId));
     }
 }
开发者ID:niborb,项目名称:FOQElasticaBundle,代码行数:28,代码来源:RegisterProvidersPass.php

示例11: testObjectManagerConfiguration

 /**
  * @dataProvider getObjectManagerConfigurationTestData
  *
  * @param string $expectedModelManagerName
  * @param string $expectedObjectManager
  * @param array  $configs
  * @param string $message
  */
 public function testObjectManagerConfiguration($expectedModelManagerName, $expectedObjectManager, $configs, $message = '')
 {
     $this->extension->load($configs, $this->container);
     $alias = $this->container->getAlias('ivoaz_content_editable.object_manager');
     $modelManagerName = $this->container->getParameter('ivoaz_content_editable.model_manager_name');
     $this->assertEquals($expectedObjectManager, $alias, $message);
     $this->assertEquals($expectedModelManagerName, $modelManagerName, $message);
 }
开发者ID:ivoaz,项目名称:content-editable-bundle,代码行数:16,代码来源:IvoazContentEditableExtensionTest.php

示例12: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $alias = $container->getAlias('spy_timeline.spread.deployer');
     $spreadDeployer = $container->getDefinition((string) $alias);
     foreach ($container->findTaggedServiceIds('spy_timeline.spread') as $id => $tags) {
         $spreadDeployer->addMethodCall('addSpread', array($container->getDefinition($id)));
     }
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:11,代码来源:AddSpreadCompilerPass.php

示例13: process

 public function process(\Symfony\Component\DependencyInjection\ContainerBuilder $container)
 {
     //Backward compatibility with Fos User 1.3
     if (class_exists('FOS\\UserBundle\\FOSUserEvents')) {
         $fosUserListenerFlash = new \Symfony\Component\DependencyInjection\Definition();
         $fosUserListenerFlash->setClass('Tecnocreaciones\\Bundle\\AjaxFOSUserBundle\\EventListener\\FlashListener')->addArgument($container->getDefinition('session'))->addArgument($container->getAlias('translator'))->setTags(array('kernel.event_subscriber'));
     }
 }
开发者ID:bambamboole,项目名称:AjaxFOSUserBundle,代码行数:8,代码来源:ServicePass.php

示例14: loadInternal

 public function loadInternal(array $config, ContainerBuilder $container)
 {
     $loader = new XmlFileLoader($container, new FileLocator(array(__DIR__ . '/../Resources/config/')));
     $loader->load('services.xml');
     // Built-in handlers.
     $container->getDefinition('jms_serializer.datetime_handler')->addArgument($config['handlers']['datetime']['default_format'])->addArgument($config['handlers']['datetime']['default_timezone']);
     // 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');
     }
     $bundles = $container->getParameter('kernel.bundles');
     // 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));
     }
     if ($config['metadata']['infer_types_from_doctrine_metadata'] && isset($bundles['DoctrineBundle'])) {
         $container->setAlias('jms_serializer.metadata_driver', 'jms_serializer.metadata.doctrine_type_driver');
     }
     $container->getDefinition('jms_serializer.metadata_factory')->replaceArgument(2, $config['metadata']['debug']);
     // directories
     $directories = array();
     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.xml_deserialization_visitor.doctype_whitelist', $config['visitors']['xml']['doctype_whitelist']);
     $container->setParameter('jms_serializer.json_serialization_visitor.options', $config['visitors']['json']['options']);
     if (!$config['enable_short_alias']) {
         $container->removeAlias('serializer');
     }
 }
开发者ID:shreyans264,项目名称:symfonyPlayGround,代码行数:58,代码来源:JMSSerializerExtension.php

示例15: enableUserinfoSignature

 private function enableUserinfoSignature(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('oauth2_server.openid_connect.userinfo_endpoint');
     $jwt_creator = new Reference('jose.jwt_creator.openid_connect');
     $issuer = $container->getParameter('oauth2_server.openid_connect.userinfo_endpoint.signature.issuer');
     $signature_algorithm = $container->getParameter('oauth2_server.openid_connect.userinfo_endpoint.signature.signature_algorithm');
     $signature_key_set = new Reference($container->getAlias('oauth2_server.openid_connect.userinfo_endpoint.signature.signature_key_set'));
     $definition->addMethodCall('enableSignedResponsesSupport', [$jwt_creator, $issuer, $signature_algorithm, $signature_key_set]);
 }
开发者ID:spomky-labs,项目名称:oauth2-server-bundle,代码行数:9,代码来源:UserInfoEndpointSignatureSupportCompilerPass.php


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