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


PHP Container::set方法代码示例

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


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

示例1: loadConfig

 /**
  * Loads the config
  */
 private function loadConfig()
 {
     $directories = [BASE_DIR . '/config', '/etc/blackhole-bot/'];
     $locator = new FileLocator($directories);
     $loader = new YamlConfigLoader($locator);
     $this->container->set('config', (new Processor())->processConfiguration($this, $loader->load($locator->locate('blackhole.yml'))));
 }
开发者ID:jlkaufman,项目名称:blackhole-bot,代码行数:10,代码来源:Configuration.php

示例2: setUp

 protected function setUp()
 {
     $this->container = new Container();
     $this->container->set('doctrine.orm.entity_manager', EntityManager::create(array('driver' => 'pdo_sqlite', 'memory' => true), Setup::createAnnotationMetadataConfiguration(array())));
     $this->bundle = new DateIntervalBundle();
     $this->bundle->setContainer($this->container);
 }
开发者ID:clubdesarrolladores,项目名称:php-symfony-dateinterval,代码行数:7,代码来源:DateIntervalBundleTest.php

示例3: createContainer

 public function createContainer($client, $handler)
 {
     $container = new Container();
     $container->set('gbprod.elasticsearch_extra.put_index_mappings_handler', $handler);
     $container->set('m6web_elasticsearch.client.my_client', $client);
     return $container;
 }
开发者ID:gbprod,项目名称:elasticsearch-extra-bundle,代码行数:7,代码来源:PutIndexMappingsCommand.php

示例4: setUp

    protected function setUp()
    {
        parent::setUp();

        $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');

        $this->container = new ContainerBuilder();
        $this->container->addScope(new Scope('request'));
        $this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
        $this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper'));
        $this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))
            ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')));
        $this->container->register('twig', 'Twig_Environment');
        $this->container->register('templating.engine.twig', $this->getMockClass('Symfony\\Bundle\\TwigBundle\\TwigEngine'))
            ->addArgument(new Definition($this->getMockClass('Twig_Environment')))
            ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Templating\\TemplateNameParserInterface')))
            ->addArgument(new Definition($this->getMockClass('Symfony\Component\Config\FileLocatorInterface')))
            ->addArgument(new Definition($this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables'), array(new Definition($this->getMockClass('Symfony\\Component\\DependencyInjection\\Container')))));
        $this->container->setParameter('kernel.bundles', array());
        $this->container->setParameter('kernel.cache_dir', __DIR__);
        $this->container->setParameter('kernel.debug', false);
        $this->container->setParameter('kernel.root_dir', __DIR__);
        $this->container->register('profiler', $this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\Profiler'))
            ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\ProfilerStorageInterface')));
        $this->container->setParameter('data_collector.templates', array());
        $this->container->set('kernel', $this->kernel);
    }
开发者ID:n3b,项目名称:symfony,代码行数:27,代码来源:WebProfilerExtensionTest.php

示例5: prepareController

 /**
  * Mock the controller.
  *
  * @return \PHPUnit_Framework_MockObject_MockObject|PackageController
  */
 private function prepareController()
 {
     $manager = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->setMethods(null)->getMock();
     $config = new Config();
     $config->merge(array('repositories' => array('packagist' => false)));
     $loader = new RootPackageLoader($manager, $config);
     $rootPackage = $loader->load(json_decode($this->readFixture('composer.json'), true));
     $loader = new ArrayLoader();
     $json = json_decode($this->readFixture('installed.json'), true);
     $packages = [];
     foreach ($json as $package) {
         $packages[] = $loader->load($package);
     }
     $manager->setLocalRepository(new WritableArrayRepository($packages));
     $composer = $this->getMockBuilder(Composer::class)->setMethods(['getPackage', 'getRepositoryManager'])->getMock();
     $composer->method('getPackage')->willReturn($rootPackage);
     $composer->method('getRepositoryManager')->willReturn($manager);
     $controller = $this->getMockBuilder(PackageController::class)->setMethods(['getComposer', 'forward'])->getMock();
     $controller->method('getComposer')->willReturn($composer);
     $home = $this->getMock(HomePathDeterminator::class, ['homeDir']);
     $home->method('homeDir')->willReturn($this->getTempDir());
     $composerJson = $this->provideFixture('composer.json');
     $this->provideFixture('composer.lock');
     $this->provideFixture('installed.json', 'vendor/composer/installed.json');
     $container = new Container();
     $container->set('tenside.home', $home);
     $container->set('tenside.composer_json', new ComposerJson($composerJson));
     /** @var PackageController $controller */
     $controller->setContainer($container);
     return $controller;
 }
开发者ID:tenside,项目名称:core-bundle,代码行数:36,代码来源:PackageControllerTest.php

示例6: setUp

 protected function setUp()
 {
     $this->controller = $controller = $this->getMock("Thelia\\Controller\\BaseController", ["getParser", "render", "renderRaw"]);
     /**
      * Reset static :: $formDefinition on controllers
      */
     $this->definitionReflection = $reflection = (new \ReflectionObject($this->controller))->getProperty('formDefinition');
     $reflection->setAccessible(true);
     $this->formDefinition = $reflection->getValue();
     $reflection->setValue(null);
     /**
      * Add the test type to the factory and
      * the form to the container
      */
     $factory = new FormFactoryBuilder();
     $factory->addExtension(new CoreExtension());
     $factory->addType(new TestType());
     /**
      * Construct the container
      */
     $container = new Container();
     $container->set("thelia.form_factory_builder", $factory);
     $container->set("thelia.translator", new Translator($container));
     $container->setParameter("thelia.parser.forms", array("test_form" => "Thelia\\Tests\\Resources\\Form\\TestForm"));
     $request = new Request();
     $request->setSession(new Session(new MockArraySessionStorage()));
     $container->set("request", $request);
     $container->set("thelia.forms.validator_builder", new ValidatorBuilder());
     $container->set("event_dispatcher", new EventDispatcher());
     $this->controller->setContainer($container);
 }
开发者ID:badelas,项目名称:thelia,代码行数:31,代码来源:BaseControllerTest.php

示例7: setUp

 protected function setUp()
 {
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $translator->expects($this->any())->method('trans')->will($this->returnArgument(0));
     $registry = $this->getMockForAbstractClass('Doctrine\\Common\\Persistence\\ManagerRegistry', [], '', false);
     $registry->expects($this->any())->method('getManagerForClass')->will($this->returnValue($this->em));
     $this->formFactory = Forms::createFormFactoryBuilder()->addExtensions([new PreloadedExtension(['oro_type_filter' => new FilterType($translator), 'oro_type_choice_filter' => new ChoiceFilterType($translator), 'entity' => new EntityType($registry), 'oro_type_entity_filter' => new EntityFilterType($translator)], []), new CsrfExtension($this->getMock('Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface'))])->getFormFactory();
     $classMetaData = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $classMetaData->expects($this->any())->method('getName')->will($this->returnValue('OroSegment:Segment'));
     $classMetaData->expects($this->any())->method('getIdentifier')->will($this->returnValue(['id']));
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($classMetaData));
     $this->dynamicSegmentQueryBuilder = $this->getMockBuilder('Oro\\Bundle\\SegmentBundle\\Query\\DynamicSegmentQueryBuilder')->disableOriginalConstructor()->getMock();
     $this->staticSegmentQueryBuilder = $this->getMockBuilder('Oro\\Bundle\\SegmentBundle\\Query\\StaticSegmentQueryBuilder')->disableOriginalConstructor()->getMock();
     $this->entityNameProvider = $this->getMock('Oro\\Bundle\\SegmentBundle\\Provider\\EntityNameProvider');
     $this->entityNameProvider->expects($this->any())->method('getEntityName')->will($this->returnValue('Namespace\\Entity'));
     $this->entityConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $this->extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $this->entityConfigProvider->expects($this->any())->method('getConfigManager')->will($this->returnValue($configManager));
     $configManager->expects($this->any())->method('getEntityManager')->will($this->returnValue($this->em));
     $staticQBServiceID = uniqid('static');
     $dynamicQBServiceID = uniqid('dynamic');
     $container = new Container();
     $container->set($staticQBServiceID, $this->staticSegmentQueryBuilder);
     $container->set($dynamicQBServiceID, $this->dynamicSegmentQueryBuilder);
     $this->filter = new SegmentFilter($this->formFactory, new FilterUtility(), new ServiceLink($container, $dynamicQBServiceID), new ServiceLink($container, $staticQBServiceID), $this->entityNameProvider, $this->entityConfigProvider, $this->extendConfigProvider);
     $this->filter->init('segment', ['entity' => '']);
 }
开发者ID:nmallare,项目名称:platform,代码行数:29,代码来源:SegmentFilterTest.php

示例8: getContainer

 private function getContainer($eventDispatcher)
 {
     $container = new Container();
     $container->set('fm_elfinder.loader', $this->getElFinderLoaderMock());
     $container->set('http_kernel', $this->getHttpKernelMock());
     $container->set('event_dispatcher', $eventDispatcher);
     return $container;
 }
开发者ID:jstnthms,项目名称:FMElfinderBundle,代码行数:8,代码来源:ElFinderControllerTest.php

示例9: testCall

 public function testCall()
 {
     $service = $this->getCallbackMock();
     $service->expects($this->once())->method('__invoke');
     $this->container->set('foo_api', $service);
     $this->binding->on('foo', '0', 'foo_api');
     $this->binding->call(new Request('foo', '0', []));
 }
开发者ID:skolodyazhnyy,项目名称:service-bus-bundle,代码行数:8,代码来源:ContainerBindingTest.php

示例10: testMapping

 public function testMapping()
 {
     $this->container->set("value_from_the_container", 123);
     $plan = $this->getBuildPlanOfObjectUsing("value_from_the_container");
     $serializedPlan = $this->haringo->serializeBuildPlan($plan);
     $unserializedPlan = $this->haringo->deserializeBuildPlan($serializedPlan);
     $builtObject = $this->haringo->buildObjectBasedOn($unserializedPlan);
     $this->assertEquals(123, $builtObject->val);
 }
开发者ID:lukaszmakuch,项目名称:sf-container-haringo-val,代码行数:9,代码来源:ExtensionTest.php

示例11: getTemplating

 /**
  * Retrieve the templating service
  * 
  * @return \Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine
  */
 public function getTemplating()
 {
     if (defined('IN_MAUTIC_CONSOLE')) {
         //enter the request scope in order to be use the templating.helper.assets service
         $this->container->enterScope('request');
         $this->container->set('request', new Request(), 'request');
     }
     return $this->container->get('templating');
 }
开发者ID:Yame-,项目名称:mautic,代码行数:14,代码来源:TemplatingHelper.php

示例12: testShouldInitializeDependencies

 public function testShouldInitializeDependencies()
 {
     $dependency = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $object = $this->getMock('Oro\\Component\\Layout\\Tests\\Unit\\Extension\\Theme\\Stubs\\LayoutUpdateWithDependency');
     $object->expects($this->once())->method('setContainer')->with($this->identicalTo($dependency));
     $this->container->set('dependency_service_id', $dependency);
     $this->initializer->addKnownDependency('\\Symfony\\Component\\DependencyInjection\\ContainerAwareInterface', 'setContainer', 'dependency_service_id');
     $this->initializer->initialize($object);
 }
开发者ID:Maksold,项目名称:platform,代码行数:9,代码来源:DependencyInitializerTest.php

示例13: testPutFast

 public function testPutFast()
 {
     $job = $this->getMockBuilder(Job::class)->getMock();
     $registry = $this->getMockBuilder(QueueManagerRegistry::class)->disableOriginalConstructor()->getMock();
     $registry->expects($this->once())->method('put')->with('test_worker', [])->willReturn($job);
     $this->container->set('mcfedr_queue_manager.registry', $registry);
     $putJob = $this->manager->put('test_worker', []);
     $this->assertEquals($job, $putJob);
 }
开发者ID:mcfedr,项目名称:doctrine-delay-queue-driver-bundle,代码行数:9,代码来源:DoctrineDelayQueueManagerTest.php

示例14: createContext

 protected function createContext()
 {
     $container = new Container(new ParameterBag());
     $helper = new Helper($container);
     $httpKernel = new Kernel($container);
     $container->set('simple_http.helper', $helper);
     $container->set('simple_http.kernel', $httpKernel);
     return [$helper, $httpKernel, $container];
 }
开发者ID:bogeux,项目名称:SimpleHttpBundle,代码行数:9,代码来源:AbstractTests.php

示例15: getContainer

 /**
  * Returns a valid Container
  *
  * @return \Symfony\Component\DependencyInjection\Container
  */
 protected function getContainer(MockGenerator $mg, Pheanstalk $pheanstalk)
 {
     $container = new Container();
     $container->setParameter('kernel.root_dir', sys_get_temp_dir());
     $container->set('pheanstalk', $pheanstalk);
     $container->set('logger', $mg->getLoggerMock());
     $container->set('pheanstalk.queue.tube_collection', $this->mg->getTubeColletionMock(array($mg->getTubeMock())));
     return $container;
 }
开发者ID:nesQuick,项目名称:pheanstalk,代码行数:14,代码来源:MessageQueueWorkerCommandTest.php


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