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


PHP Definition::setScope方法代码示例

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


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

示例1: applyDefaults

 /**
  * Apply the default values required by the AdminInterface to the Admin service definition
  *
  * @param \Symfony\Component\DependencyInjection\Definition $definition
  * @param array $attributes
  * @return \Symfony\Component\DependencyInjection\Definition
  */
 public function applyDefaults(Definition $definition, array $attributes = array())
 {
     $definition->setScope(ContainerInterface::SCOPE_PROTOTYPE);
     $manager_type = $attributes[0]['manager_type'];
     if (!$definition->hasMethodCall('setModelManager')) {
         $definition->addMethodCall('setModelManager', array(new Reference(sprintf('sonata.admin.manager.%s', $manager_type))));
     }
     if (!$definition->hasMethodCall('setFormContractor')) {
         $definition->addMethodCall('setFormContractor', array(new Reference(sprintf('sonata.admin.builder.%s_form', $manager_type))));
     }
     if (!$definition->hasMethodCall('setListBuilder')) {
         $definition->addMethodCall('setListBuilder', array(new Reference(sprintf('sonata.admin.builder.%s_list', $manager_type))));
     }
     if (!$definition->hasMethodCall('setDatagridBuilder')) {
         $definition->addMethodCall('setDatagridBuilder', array(new Reference(sprintf('sonata.admin.builder.%s_datagrid', $manager_type))));
     }
     if (!$definition->hasMethodCall('setTranslator')) {
         $definition->addMethodCall('setTranslator', array(new Reference('translator')));
     }
     if (!$definition->hasMethodCall('setConfigurationPool')) {
         $definition->addMethodCall('setConfigurationPool', array(new Reference('sonata.admin.pool')));
     }
     if (!$definition->hasMethodCall('setRouter')) {
         $definition->addMethodCall('setRouter', array(new Reference('router')));
     }
     if (!$definition->hasMethodCall('setLabel')) {
         $label = isset($attributes[0]['label']) ? $attributes[0]['label'] : '-';
         $definition->addMethodCall('setLabel', array($label));
     }
     $definition->addMethodCall('configure');
     return $definition;
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:39,代码来源:AddDependencyCallsPass.php

示例2: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     foreach ($container->findTaggedServiceIds('snc_redis.connection_parameters') as $id => $attr) {
         $parameterDefinition = $container->getDefinition($id);
         $parameters = $parameterDefinition->getArgument(0);
         if ($parameters['logging']) {
             if ('%kernel.debug%' === $parameters['logging'] && false === $container->getParameter('kernel.debug')) {
                 continue;
             }
             $optionId = sprintf('snc_redis.client.%s_options', $parameters['alias']);
             $option = $container->getDefinition($optionId);
             if (1 < count($option->getArguments())) {
                 throw new \RuntimeException('Please check the predis option arguments.');
             }
             $arguments = $option->getArgument(0);
             $connectionFactoryId = sprintf('snc_redis.%s_connectionfactory', $parameters['alias']);
             $connectionFactoryDef = new Definition($container->getParameter('snc_redis.connection_factory.class'));
             $connectionFactoryDef->setPublic(false);
             $connectionFactoryDef->setScope(ContainerInterface::SCOPE_CONTAINER);
             $connectionFactoryDef->addArgument(new Reference(sprintf('snc_redis.client.%s_profile', $parameters['alias'])));
             $connectionFactoryDef->addMethodCall('setConnectionWrapperClass', array($container->getParameter('snc_redis.connection_wrapper.class')));
             $connectionFactoryDef->addMethodCall('setLogger', array(new Reference('snc_redis.logger')));
             $container->setDefinition($connectionFactoryId, $connectionFactoryDef);
             $arguments['connections'] = new Reference($connectionFactoryId);
             $option->replaceArgument(0, $arguments);
         }
     }
 }
开发者ID:ronnylt,项目名称:SncRedisBundle,代码行数:31,代码来源:LoggingPass.php

示例3: load

 /**
  * {@inheritDoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.xml');
     $config = $this->getConfiguration($configs, $container);
     $config = $this->processConfiguration($config, $configs);
     foreach ($config['services'] as $name => $settings) {
         // until we can use file attachments in Guzzle in php 5.5 we block use of the upload type
         if ('upload' === $settings['type']) {
             throw new \ConfigurationException('The "upload" type is currently disabled due to PHP 5.5 cURL issues.');
         }
         $def = new Definition($container->getParameter('pompdelux.kraken.service.class'));
         $def->setPublic(true);
         $def->setScope(ContainerInterface::SCOPE_CONTAINER);
         $def->addArgument(new Reference('pompdelux.kraken.guzzle.' . $settings['type'] . '.service'));
         $def->addArgument(new Reference('logger'));
         $def->addArgument(new Reference('router'));
         $def->addArgument($settings['api_key']);
         $def->addArgument($settings['api_secret']);
         $def->addArgument($settings['type']);
         $def->addArgument($settings['use_lossy']);
         $callback = $settings['callback'] ? $settings['callback_route'] : null;
         $def->addArgument($callback);
         $container->setDefinition(sprintf('pompdelux.kraken.%s', $name), $def);
     }
 }
开发者ID:pompdelux,项目名称:kraken-bundle,代码行数:29,代码来源:KrakenExtension.php

示例4: configureDefinition

 /**
  * @param Definition $definition
  * @param array $config
  */
 private function configureDefinition(Definition $definition, array $config)
 {
     foreach ($config['servers'] as $currentServer) {
         $currentServer = explode(':', $currentServer, 2);
         $definition->addMethodCall('addServer', $currentServer);
     }
     $definition->addMethodCall('setTimeout', array($config['timeout']));
     $definition->setScope('prototype');
 }
开发者ID:derrabus,项目名称:gearman-bundle,代码行数:13,代码来源:GearmanExtension.php

示例5: load

 /**
  * {@inheritdoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $this->defineParameters($container);
     $definition = new Definition('Scaffold\\Scaffolder');
     $definition->setArguments(array('%scaffold.template_path%', '%scaffold.tmp_path%'));
     $definition->setScope('prototype');
     $container->setDefinition('scaffold.scaffolder', $definition);
     $definition = new Definition('Scaffold\\Variable\\Model');
     $container->setDefinition('model.variable', $definition);
 }
开发者ID:czogori,项目名称:scaffold,代码行数:13,代码来源:ScaffoldExtension.php

示例6: transformDefinition

 /**
  * Transforms the Definition into one we can use for mocks
  *
  * @return Object
  * @author Dan Cox
  */
 public function transformDefinition($mockery)
 {
     $definition = new Definition();
     // Set the class to the mockery decorator
     $definition->setClass('Wasp\\DI\\ServiceMockeryDecorator');
     // Add the mockery name as a definition;
     $definition->setArguments([$mockery]);
     // Incase it is a prototype scoped class
     $definition->setScope('container');
     return $definition;
 }
开发者ID:antoligy,项目名称:Framework,代码行数:17,代码来源:MockeryPass.php

示例7: testFindLowestScopeInNamedPackageWithDefinition

 /** @dataProvider getScopesTests */
 public function testFindLowestScopeInNamedPackageWithDefinition($scope)
 {
     $container = new ContainerBuilder();
     $defaultPackage = new Definition('stdClass');
     $aPackage = new Definition('stdClass');
     $bPackage = new Definition('stdClass');
     $bPackage->setScope($scope);
     $cPackage = new Definition('stdClass');
     $definition = new Definition('stdClass', array($defaultPackage, array($aPackage, $bPackage, $cPackage)));
     $container->setDefinition('templating.helper.assets', $definition);
     $profilerPass = new TemplatingAssetHelperPass();
     $profilerPass->process($container);
     $this->assertSame($scope, $definition->getScope());
 }
开发者ID:brennantom,项目名称:hackazon,代码行数:15,代码来源:TemplatingAssetHelperPassTest.php

示例8: load

 /**
  * {@inheritDoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.xml');
     //Compatibilidad con fos user 1.3
     if (!class_exists('FOS\\UserBundle\\FOSUserEvents')) {
         $registrationFormHandlerDefinition = new Definition("Tecnocreaciones\\Bundle\\AjaxFOSUserBundle\\Handler\\RegistrationFormHandler");
         $registrationFormHandlerDefinition->setScope("request");
         $registrationFormHandlerDefinition->setArguments(array(new Reference("fos_user.registration.form"), new Reference("request"), new Reference("fos_user.user_manager"), new Reference("fos_user.mailer"), new Reference("fos_user.util.token_generator"), new Reference("event_dispatcher")));
         $container->setDefinition("fos_user.registration.form.handler.default", $registrationFormHandlerDefinition);
     }
 }
开发者ID:bambamboole,项目名称:AjaxFOSUserBundle,代码行数:17,代码来源:TecnocreacionesAjaxFOSUserExtension.php

示例9: loadConnection

 /**
  * Loads connections.
  *
  * @param array $config A connection config options.
  * @param ContainerBuilder $container The ContainerBuilder instance
  */
 protected function loadConnection(array $config, ContainerBuilder $container)
 {
     $connectionDef = new Definition('Lt\\Bundle\\RedisBundle\\Connection\\RedisClient');
     //TODO: Use configurable class.
     $connectionDef->setScope(ContainerInterface::SCOPE_CONTAINER);
     $parameters = array('host' => $config['host'], 'port' => $config['port'], 'database' => $config['database'], 'password' => $config['auth']);
     $connectionDef->addArgument($parameters);
     $connectionDef->addArgument($config['options']);
     if ($config['logging']) {
         $connectionDef->addArgument(new Reference('lt_redis.connection_factory'));
     }
     $container->setDefinition(sprintf('lt_redis.%s', $config['alias']), $connectionDef);
     $container->setAlias(sprintf('lt_redis.%s_connection', $config['alias']), sprintf('lt_redis.%s', $config['alias']));
 }
开发者ID:ronnylt,项目名称:LtRedisBundle,代码行数:20,代码来源:LtRedisExtension.php

示例10: load

 /**
  * {@inheritDoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.xml');
     $config = $this->getConfiguration($configs, $container);
     $config = $this->processConfiguration($config, $configs);
     foreach ($config['class'] as $name => $settings) {
         $def = new Definition($container->getParameter('pdl.phpredis.class'));
         $def->setPublic(true);
         $def->setScope(ContainerInterface::SCOPE_CONTAINER);
         $def->addArgument($name);
         $def->addArgument($container->getParameter('kernel.environment'));
         $def->addArgument($settings);
         $def->addMethodCall('setLogger', [new Reference('pdl.phpredis.logger')]);
         $container->setDefinition(sprintf('pdl.phpredis.%s', $name), $def);
     }
 }
开发者ID:pompdelux,项目名称:phpredis-bundle,代码行数:20,代码来源:PHPRedisExtension.php

示例11: loadDoctrine

 /**
  * Loads the Doctrine configuration.
  *
  * @param array            $config    A configuration array
  * @param ContainerBuilder $container A ContainerBuilder instance
  */
 protected function loadDoctrine(array $config, ContainerBuilder $container)
 {
     foreach ($config['doctrine'] as $name => $cache) {
         $clusterConfig = $config['clusters'][$cache['cluster']];
         $client = new Reference(sprintf('memcached.%s', $cache['cluster']));
         foreach ($cache['entity_managers'] as $em) {
             $definition = new Definition($container->getParameter('memcached.doctrine_cache.class'));
             $definition->setScope(ContainerInterface::SCOPE_CONTAINER);
             $definition->addMethodCall('setMemcached', array($client));
             $container->setDefinition(sprintf('doctrine.orm.%s_%s_cache', $em, $name), $definition);
         }
         foreach ($cache['document_managers'] as $dm) {
             $definition = new Definition($container->getParameter('memcached.doctrine_cache.class'));
             $definition->setScope(ContainerInterface::SCOPE_CONTAINER);
             $definition->addMethodCall('setMemcached', array($client));
             $container->setDefinition(sprintf('doctrine.odm.mongodb.%s_%s_cache', $dm, $name), $definition);
         }
     }
 }
开发者ID:avatarnewyork,项目名称:memcached-bundle,代码行数:25,代码来源:AequasiMemcachedExtension.php

示例12: getAllParameters

 private function getAllParameters()
 {
     $service = new Definition();
     $service->setClass('stdClass');
     $service->setAbstract(true);
     $service->setFactoryClass('stdClass');
     $service->setFactoryMethod('get');
     $service->setFactoryService('service.fact');
     $service->setFile('/file.php');
     $service->setLazy(true);
     $service->addMethodCall('methodCall1');
     $service->addMethodCall('methodCall2', array('arg1', 'arg2'));
     $service->addMethodCall('methodCall3', array(new Reference('arg.one')));
     $service->setProperty('prop1', 'val1');
     $service->setProperty('prop2', new Reference('prop.one'));
     $service->setPublic(false);
     $service->setScope('request');
     $service->setSynchronized(true);
     $service->setSynthetic(true);
     return new ServiceElement('service.two', $service);
 }
开发者ID:vierbergenlars,项目名称:manipulator-bundle,代码行数:21,代码来源:ServiceElementTest.php

示例13: load

 public function load(array $configs, ContainerBuilder $container)
 {
     $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.yml');
     $config = array();
     foreach ($configs as $subConfig) {
         $config = array_merge($config, $subConfig);
     }
     foreach ($config['email'] as $alias => $options) {
         $optionId = sprintf('rage_notification.email.%s.message', $alias);
         $optionDef = new Definition($container->getParameter('rage_notification.email_message.class'));
         $optionDef->setScope(ContainerInterface::SCOPE_PROTOTYPE);
         $optionDef->addArgument(new Reference('mailer'));
         $optionDef->addArgument(new Reference('templating'));
         $optionDef->addArgument(new Reference('service_container'));
         if (!empty($options['from'])) {
             $optionDef->addMethodCall('setFrom', [$options['from']]);
         }
         if (!empty($options['reply_to'])) {
             $optionDef->addMethodCall('setReplyTo', [$options['reply_to']]);
         }
         if (!empty($options['embed_images'])) {
             $optionDef->addMethodCall('setEmbedImages', [$options['embed_images']['url'], $options['embed_images']['path']]);
         }
         if (!empty($options['template_path'])) {
             $optionDef->addMethodCall('setTemplatePath', [$options['template_path']]);
         }
         if (!empty($options['css_file'])) {
             $optionDef->addMethodCall('setCssFile', [$options['css_file']]);
         }
         $container->setDefinition($optionId, $optionDef);
         if ($alias === 'default') {
             $container->setAlias('rage_notification.email.message', $optionId);
         }
     }
 }
开发者ID:meniam,项目名称:notification-bundle,代码行数:36,代码来源:RageNotificationExtension.php

示例14: parseDefinition

 /**
  * Parses a definition.
  *
  * @param string $id
  * @param array  $service
  * @param string $file
  *
  * @throws InvalidArgumentException When tags are invalid
  */
 private function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     }
     if (!is_array($service)) {
         throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file));
     }
     if (isset($service['alias'])) {
         $public = !array_key_exists('public', $service) || (bool) $service['public'];
         $this->container->setAlias($id, new Alias($service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['scope'])) {
         $definition->setScope($service['scope']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['synchronized'])) {
         $definition->setSynchronized($service['synchronized']);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (isset($service['factory'])) {
         if (is_string($service['factory'])) {
             if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
                 $parts = explode(':', $service['factory']);
                 $definition->setFactory(array($this->resolveServices('@' . $parts[0]), $parts[1]));
             } else {
                 $definition->setFactory($service['factory']);
             }
         } else {
             $definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1]));
         }
     }
     if (isset($service['factory_class'])) {
         $definition->setFactoryClass($service['factory_class']);
     }
     if (isset($service['factory_method'])) {
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         $definition->setFactoryService($service['factory_service']);
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         if (is_string($service['configurator'])) {
             $definition->setConfigurator($service['configurator']);
         } else {
             $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
         }
     }
     if (isset($service['calls'])) {
         if (!is_array($service['calls'])) {
             throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['calls'] as $call) {
             $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             $definition->addMethodCall($call[0], $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
//.........这里部分代码省略.........
开发者ID:tahermarkos,项目名称:Transport,代码行数:101,代码来源:YamlFileLoader.php

示例15: parseDefinition

    /**
     * Parses a definition.
     *
     * @param string $id
     * @param array  $service
     * @param string $file
     *
     * @throws InvalidArgumentException When tags are invalid
     */
    private function parseDefinition($id, $service, $file)
    {
        if (is_string($service) && 0 === strpos($service, '@')) {
            $this->container->setAlias($id, substr($service, 1));

            return;
        } elseif (isset($service['alias'])) {
            $public = !array_key_exists('public', $service) || (Boolean) $service['public'];
            $this->container->setAlias($id, new Alias($service['alias'], $public));

            return;
        }

        if (isset($service['parent'])) {
            $definition = new DefinitionDecorator($service['parent']);
        } else {
            $definition = new Definition();
        }

        if (isset($service['class'])) {
            $definition->setClass($service['class']);
        }

        if (isset($service['scope'])) {
            $definition->setScope($service['scope']);
        }

        if (isset($service['synthetic'])) {
            $definition->setSynthetic($service['synthetic']);
        }

        if (isset($service['public'])) {
            $definition->setPublic($service['public']);
        }

        if (isset($service['abstract'])) {
            $definition->setAbstract($service['abstract']);
        }

        if (isset($service['factory_class'])) {
            $definition->setFactoryClass($service['factory_class']);
        }

        if (isset($service['factory_method'])) {
            $definition->setFactoryMethod($service['factory_method']);
        }

        if (isset($service['factory_service'])) {
            $definition->setFactoryService($service['factory_service']);
        }

        if (isset($service['file'])) {
            $definition->setFile($service['file']);
        }

        if (isset($service['arguments'])) {
            $definition->setArguments($this->resolveServices($service['arguments']));
        }

        if (isset($service['properties'])) {
            $definition->setProperties($this->resolveServices($service['properties']));
        }

        if (isset($service['configurator'])) {
            if (is_string($service['configurator'])) {
                $definition->setConfigurator($service['configurator']);
            } else {
                $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
            }
        }

        if (isset($service['calls'])) {
            foreach ($service['calls'] as $call) {
                $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
                $definition->addMethodCall($call[0], $args);
            }
        }

        if (isset($service['tags'])) {
            if (!is_array($service['tags'])) {
                throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $file));
            }

            foreach ($service['tags'] as $tag) {
                if (!isset($tag['name'])) {
                    throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
                }

                $name = $tag['name'];
                unset($tag['name']);

//.........这里部分代码省略.........
开发者ID:n3b,项目名称:symfony,代码行数:101,代码来源:YamlFileLoader.php


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