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


PHP DependencyInjection\Definition类代码示例

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


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

示例1: createEnvironment

 /**
  * @param ContainerBuilder $container
  * @param string           $code
  * @param Definition       $formatter
  * @param array            $extensions
  *
  * @return string
  */
 public function createEnvironment(ContainerBuilder $container, $code, Definition $formatter, array $extensions)
 {
     $loader = new Definition('Twig_Loader_String');
     $loader->setPublic(false);
     $container->setDefinition(sprintf('sonata.formatter.twig.loader.%s', $code), $loader);
     $loaderSelector = new Definition('Sonata\\FormatterBundle\\Twig\\Loader\\LoaderSelector', array(new Reference(sprintf('sonata.formatter.twig.loader.%s', $code)), new Reference('twig.loader')));
     $loaderSelector->setPublic(false);
     $env = new Definition('Twig_Environment', array($loaderSelector, array('debug' => false, 'strict_variables' => false, 'charset' => 'UTF-8')));
     $env->setPublic(false);
     $container->setDefinition(sprintf('sonata.formatter.twig.env.%s', $code), $env);
     $sandboxPolicy = new Definition('Sonata\\FormatterBundle\\Twig\\SecurityPolicyContainerAware', array(new Reference('service_container'), $extensions));
     $sandboxPolicy->setPublic(false);
     $container->setDefinition(sprintf('sonata.formatter.twig.sandbox.%s.policy', $code), $sandboxPolicy);
     $sandbox = new Definition('Twig_Extension_Sandbox', array($sandboxPolicy, true));
     $sandbox->setPublic(false);
     $container->setDefinition(sprintf('sonata.formatter.twig.sandbox.%s', $code), $sandbox);
     $env->addMethodCall('addExtension', array(new Reference(sprintf('sonata.formatter.twig.sandbox.%s', $code))));
     foreach ($extensions as $extension) {
         $env->addMethodCall('addExtension', array(new Reference($extension)));
     }
     $lexer = new Definition('Twig_Lexer', array(new Reference(sprintf('sonata.formatter.twig.env.%s', $code)), array('tag_comment' => array('<#', '#>'), 'tag_block' => array('<%', '%>'), 'tag_variable' => array('<%=', '%>'))));
     $lexer->setPublic(false);
     $container->setDefinition(new Reference(sprintf('sonata.formatter.twig.lexer.%s', $code)), $lexer);
     $env->addMethodCall('setLexer', array(new Reference(sprintf('sonata.formatter.twig.lexer.%s', $code))));
     return sprintf('sonata.formatter.twig.env.%s', $code);
 }
开发者ID:devcodixis,项目名称:SonataFormatterBundle,代码行数:34,代码来源:SonataFormatterExtension.php

示例2: testProcess

 public function testProcess()
 {
     // TEST 1
     // must work with no tagged services
     $containerBuilder = new ContainerBuilder();
     $compilerPass = new RepositoryCompilerPass();
     $compilerPass->process($containerBuilder);
     // TEST 2
     // must add repository tagged service into the repository pool
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->setDefinition('lag.repository.repository_pool', new Definition());
     $repository = new Definition();
     $repository->addTag('doctrine.repository');
     $containerBuilder->setDefinition('repository1', $repository);
     $repository = new Definition();
     $repository->addTag('doctrine.repository');
     $containerBuilder->setDefinition('repository2', $repository);
     $compilerPass = new RepositoryCompilerPass();
     $compilerPass->process($containerBuilder);
     $methodCalls = $containerBuilder->getDefinition('lag.repository.repository_pool')->getMethodCalls();
     $this->assertCount(2, $methodCalls);
     foreach ($methodCalls as $call) {
         /** @var Reference $reference */
         $reference = $call[1][0];
         // test reference assignment
         $this->assertEquals('add', $call[0]);
         $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $reference);
         $this->assertTrue(in_array($reference->__toString(), ['repository1', 'repository2']));
     }
 }
开发者ID:larriereguichet,项目名称:DoctrineRepositoryBundle,代码行数:30,代码来源:RepositoryCompilerPassTest.php

示例3: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $analysis = $container->getParameter('es.analysis');
     $connections = $container->getParameter('es.connections');
     $managers = $container->getParameter('es.managers');
     $collector = $container->get('es.metadata_collector');
     foreach ($managers as $managerName => $manager) {
         if (!isset($connections[$manager['connection']])) {
             throw new InvalidConfigurationException('There is no ES connection with the name: ' . $manager['connection']);
         }
         $managerName = strtolower($managerName);
         $connection = $connections[$manager['connection']];
         $managerDefinition = new Definition($container->getParameter('es.manager.class'), [$managerName, $connection, $analysis, $manager]);
         $managerDefinition->setFactory([new Reference('es.manager_factory'), 'createManager']);
         $container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition);
         // Make es.manager.default as es.manager service.
         if ($managerName === 'default') {
             $container->setAlias('es.manager', 'es.manager.default');
         }
         $mappings = $collector->getMappings($manager['mappings']);
         // Building repository services.
         foreach ($mappings as $repositoryType => $repositoryDetails) {
             $repositoryDefinition = new Definition($container->getParameter('es.repository.class'), [$repositoryDetails['bundle'] . ':' . $repositoryDetails['class']]);
             $repositoryDefinition->setFactory([new Reference(sprintf('es.manager.%s', $managerName)), 'getRepository']);
             $repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType);
             if (strtolower(substr($repositoryType, -8)) === 'document') {
                 $container->setAlias(sprintf('es.manager.%s.%s', $managerName, substr($repositoryType, 0, strlen($repositoryType) - 8)), $repositoryId);
             }
             $container->setDefinition($repositoryId, $repositoryDefinition);
         }
     }
 }
开发者ID:emgiezet,项目名称:ElasticsearchBundle,代码行数:35,代码来源:MappingPass.php

示例4: createDefinition

 /**
  * {@inheritdoc}
  */
 public function createDefinition(ContainerBuilder $container, array $config)
 {
     $definition = new Definition('Jose\\Object\\JWK');
     $definition->setFactory([new Reference('jose.factory.jwk'), 'createFromKeyFile']);
     $definition->setArguments([$config['path'], $config['password'], $config['additional_values']]);
     return $definition;
 }
开发者ID:spomky-labs,项目名称:jose-bundle,代码行数:10,代码来源:KeyFile.php

示例5: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $pool = $container->getDefinition('sonata.product.pool');
     $calls = $pool->getMethodCalls();
     $pool->setMethodCalls(array());
     $map = array();
     foreach ($calls as $method => $arguments) {
         if ($arguments[0] !== '__hack') {
             $pool->addMethodCall($arguments[0], $arguments[1]);
             continue;
         }
         foreach ($arguments[1] as $code => $options) {
             // define a new ProductDefinition
             $definition = new Definition('Sonata\\Component\\Product\\ProductDefinition', array(new Reference($options['provider']), new Reference($options['manager'])));
             $definition->setPublic(false);
             $container->setDefinition($code, $definition);
             $container->getDefinition($options['provider'])->addMethodCall('setCode', array($code));
             $pool->addMethodCall('addProduct', array($code, new Reference($code)));
             $map[$code] = $container->getDefinition($options['manager'])->getArgument(0);
             $container->getDefinition($options['provider'])->addMethodCall('setBasketElementManager', array(new Reference('sonata.basket_element.manager')));
             $container->getDefinition($options['provider'])->addMethodCall('setCurrencyPriceCalculator', array(new Reference('sonata.price.currency.calculator')));
             $container->getDefinition($options['provider'])->addMethodCall('setProductCategoryManager', array(new Reference('sonata.product_category.product')));
             $container->getDefinition($options['provider'])->addMethodCall('setProductCollectionManager', array(new Reference('sonata.product_collection.product')));
             $container->getDefinition($options['provider'])->addMethodCall('setOrderElementClassName', array($container->getParameter('sonata.order.order_element.class')));
             $container->getDefinition($options['provider'])->addMethodCall('setEventDispatcher', array(new Reference('event_dispatcher')));
             if (array_key_exists('variations', $options)) {
                 $container->getDefinition($options['provider'])->addMethodCall('setVariationFields', array($options['variations']['fields']));
             }
         }
     }
     $container->getDefinition('sonata.product.subscriber.orm')->replaceArgument(0, $map);
 }
开发者ID:kinkinweb,项目名称:lhvb,代码行数:35,代码来源:AddProductProviderCompilerPass.php

示例6: load

 /**
  * {@inheritdoc}
  */
 public function load(ContainerBuilder $container, array $config)
 {
     $container->setDefinition(self::CLIENT_ID, new Definition('GuzzleHttp\\Client', [$config]));
     $definition = new Definition('Ingresse\\Behat\\ApiExtension\\Context\\Initializer\\ApiClientInitializer', [new Reference(self::CLIENT_ID), $config]);
     $definition->addTag(ContextExtension::INITIALIZER_TAG);
     $container->setDefinition('ingresse_api.context_initializer', $definition);
 }
开发者ID:ingresse,项目名称:behat-api-extension,代码行数:10,代码来源:Extension.php

示例7: createDefinition

 /**
  * @param type $modelName
  * @return Definition
  */
 private function createDefinition($modelName)
 {
     $definition = new Definition(SyliusTrackerListener::class);
     $definition->addArgument(new Reference('symedit_analytics.tracker'));
     $definition->addTag('kernel.event_listener', ['event' => sprintf('symedit.%s.%s', $modelName, ResourceActions::SHOW), 'method' => 'track']);
     return $definition;
 }
开发者ID:symedit,项目名称:symedit,代码行数:11,代码来源:SymEditAnalyticsExtension.php

示例8: testCreatorReturnsNullIfSyntheticServiceIsRequested

 /**
  * Ensures that the creator returns null if a synthetic service is requested.
  */
 public function testCreatorReturnsNullIfSyntheticServiceIsRequested()
 {
     $definition = new Definition();
     $definition->setSynthetic(true);
     $this->container->setDefinition('my.service', $definition);
     $this->assertNull($this->creator->create('my.service'));
 }
开发者ID:webfactory,项目名称:symfony-application-tests,代码行数:10,代码来源:ServiceCreatorTest.php

示例9: addDefinitions

 /**
  * {@inheritdoc}
  */
 protected function addDefinitions(ContainerBuilder $container, array $config)
 {
     $container->setParameter('kherge_uuid.serializer.uuid_handler.class', 'KHerGe\\Bundle\\UuidBundle\\Serializer\\UuidHandler');
     $definition = new Definition('%kherge_uuid.serializer.uuid_handler.class%');
     $definition->addTag('jms_serializer.subscribing_handler');
     $container->setDefinition('kherge_uuid.serializer.uuid_handler', $definition);
 }
开发者ID:kherge,项目名称:uuid-bundle,代码行数:10,代码来源:UuidHandler.php

示例10: isInlinableDefinition

 protected function isInlinableDefinition(ContainerBuilder $container, $id, Definition $definition)
 {
     if (!$definition->isShared()) {
         return true;
     }
     if ($definition->isPublic()) {
         return false;
     }
     $references = count(array_keys($container->getAliases(), $id, true));
     foreach ($container->getDefinitions() as $cDefinition) {
         if ($references > 1) {
             break;
         }
         if ($this->isReferencedByArgument($id, $cDefinition->getArguments())) {
             $references += 1;
             continue;
         }
         foreach ($cDefinition->getMethodCalls() as $call) {
             if ($this->isReferencedByArgument($id, $call[1])) {
                 $references += 1;
                 continue 2;
             }
         }
     }
     return $references <= 1;
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:26,代码来源:InlineServiceDefinitionsPass.php

示例11: createDefinition

 /**
  * {@inheritdoc}
  */
 public function createDefinition(ContainerBuilder $container, array $config)
 {
     $definition = new Definition('Jose\\Object\\X5UJWKSet');
     $definition->setFactory([new Reference('jose.factory.jwk'), 'createFromX5U']);
     $definition->setArguments([$config['url'], $config['is_secured'], $config['cache'], $config['cache_ttl'], $config['is_https']]);
     return $definition;
 }
开发者ID:spomky-labs,项目名称:jose-bundle,代码行数:10,代码来源:X5U.php

示例12: registerPagers

 /**
  * @param array            $configs
  * @param ContainerBuilder $container
  */
 private function registerPagers(array $configs, ContainerBuilder $container)
 {
     $shouldDisableRedirector = true;
     foreach ($configs as $name => $config) {
         $serviceId = sprintf("%s.%s", self::PREFIX_PAGER, $name);
         $definition = $container->register($serviceId, $container->getParameter('kg_pager.class'));
         // Sets the default items per page for the given pager.
         if (isset($config['per_page'])) {
             $definition->addArgument($config['per_page']);
         }
         // Changes the strategy, if this pager should merge last two pages
         // given the following threshold.
         if (isset($config['merge']) && $config['merge'] > 0) {
             $strategyDefinition = new Definition($container->getParameter('kg_pager.strategy.last_page_merged.class'));
             $strategyDefinition->addArgument($config['merge']);
             $definition->addArgument($strategyDefinition);
         }
         // Wraps the pager inside a request decorator to have it automatically
         // infer the current page from the request.
         if ($config['key']) {
             $definition = $container->register($serviceId, $container->getParameter('kg_pager.request_decorator.class'))->setArguments(array($definition, new Reference('request_stack'), $config['key']));
         }
         if ($config['redirect']) {
             $shouldDisableRedirector = false;
             $definition = $container->register($serviceId, $container->getParameter('kg_pager.bounds_check_decorator.class'))->setArguments(array($definition));
             if ($config['key']) {
                 $definition->addArgument($config['key']);
             }
         }
     }
     if ($shouldDisableRedirector) {
         $container->removeDefinition('kg_pager.out_of_bounds_redirector');
     }
 }
开发者ID:kgilden,项目名称:pager-bundle,代码行数:38,代码来源:KGPagerExtension.php

示例13: testProcess

 /**
  * @dataProvider processProvider
  */
 public function testProcess($hasWarmer, $configIds)
 {
     $warmerId = 'yahoo_japan_config_cache.cache_warmer';
     $container = new ContainerBuilder();
     foreach ($configIds as $configId) {
         $definition = new Definition($configId);
         $definition->addTag(ConfigCache::TAG_CACHE_WARMER);
         $container->setDefinition($configId, $definition);
     }
     if ($hasWarmer) {
         $definition = new Definition($warmerId);
         $container->setDefinition($warmerId, $definition);
     }
     $pass = new CacheWarmerPass();
     $pass->process($container);
     foreach ($configIds as $index => $configId) {
         if ($hasWarmer) {
             $calls = $container->getDefinition($warmerId)->getMethodCalls();
             $this->assertTrue(isset($calls[$index][0]));
             // method name
             $this->assertSame('addConfig', $calls[$index][0]);
             $this->assertTrue(isset($calls[$index][1][0]));
             // argument
             $this->assertEquals(new Reference($configId), $calls[$index][1][0]);
         } else {
             $this->assertFalse($container->hasDefinition($warmerId));
         }
     }
 }
开发者ID:yahoojapan,项目名称:ConfigCacheBundle,代码行数:32,代码来源:CacheWarmerPassTest.php

示例14: loadInitializer

 /**
  * Load the initializer.
  *
  * @param ContainerBuilder    $container
  * @param HttpKernelInterface $app
  */
 private function loadInitializer(ContainerBuilder $container, $app)
 {
     $definition = new Definition('Laracasts\\Behat\\Context\\KernelAwareInitializer', [$app]);
     $definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]);
     $definition->addTag(ContextExtension::INITIALIZER_TAG, ['priority' => 0]);
     $container->setDefinition('laravel.initializer', $definition);
 }
开发者ID:HRcc,项目名称:Behat-Laravel-Extension,代码行数:13,代码来源:BehatExtension.php

示例15: getConnectionReference

 /**
  * @param string                                                  $name
  * @param array                                                   $config
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  *
  * @return \Symfony\Component\DependencyInjection\Reference
  */
 private function getConnectionReference($name, array $config, ContainerBuilder $container)
 {
     if (isset($config['client_id'])) {
         return new Reference($config['client_id']);
     }
     $parameters = array('scheme' => $config['scheme'], 'host' => $config['host'], 'port' => $config['port']);
     if ($config['password']) {
         $parameters['password'] = $config['password'];
     }
     if ($config['timeout']) {
         $parameters['timeout'] = $config['timeout'];
     }
     if ($config['database']) {
         $parameters['database'] = $config['database'];
     }
     $options = null;
     if (isset($config['options'])) {
         $options = $config['options'];
     }
     $clientClass = '%doctrine_cache.predis.client.class%';
     $clientId = sprintf('doctrine_cache.services.%s_predis.client', $name);
     $clientDef = new Definition($clientClass);
     $clientDef->addArgument($parameters);
     $clientDef->addArgument($options);
     $clientDef->setPublic(false);
     $container->setDefinition($clientId, $clientDef);
     return new Reference($clientId);
 }
开发者ID:javiereguiluz,项目名称:DoctrineCacheBundle,代码行数:35,代码来源:PredisDefinition.php


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