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


PHP DependencyInjection\Container类代码示例

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


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

示例1: 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

示例2: 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

示例3: setUp

 protected function setUp()
 {
     $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->setMethods(['isGranted'])->getMock();
     $this->container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->setMethods(['get'])->getMock();
     $this->container->expects($this->any())->method('get')->with('oro_security.security_facade')->willReturn($this->securityFacade);
     $this->emailVoter = new EmailVoter($this->container);
 }
开发者ID:Maksold,项目名称:platform,代码行数:7,代码来源:EmailVoterTest.php

示例4: setUp

 public function setUp()
 {
     $container = new Container();
     $container->set('api_validator.decoder.json', new JsonDecoder());
     $this->decoderProvider = new DecoderProvider(array('json' => 'api_validator.decoder.json'));
     $this->decoderProvider->setContainer($container);
 }
开发者ID:seblegall,项目名称:api-validator-bundle,代码行数:7,代码来源:DecoderProviderTest.php

示例5: test_config_values_passed_to_datatable_instance

 public function test_config_values_passed_to_datatable_instance()
 {
     $config = new Config();
     $config->setId('some_key');
     $config->setEntityName('EntityName');
     $config->setEntityAlias('en');
     $config->setFields(['k' => 'v']);
     $config->setRenderers(['k1' => 'v1']);
     $config->setWhere('where = :yes');
     $config->setWhereParams(['k3' => 'v3']);
     $config->setOrderField('Order');
     $config->setOrderDirection('ASC');
     $config->setAction(true);
     $config->setSearch(false);
     $config->setSearchFields(['k2' => 'v2']);
     $config->setJoins([['field' => 'F', 'alias' => 'a', 'type' => 'T'], ['field' => 'F1', 'alias' => 'a1', 'type' => 'T1']]);
     $datatableProphecy = $this->prophesize('\\RP\\DatatableBundle\\Util\\Datatable');
     $datatable = $datatableProphecy->reveal();
     $datatableProphecy->setEntity('EntityName', 'en')->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->setFields(['k' => 'v'])->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->setRenderers(['k1' => 'v1'])->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->setWhere('where = :yes', ['k3' => 'v3'])->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->setOrder('Order', 'ASC')->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->setHasAction(true)->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->setSearch(false)->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->setSearchFields(['k2' => 'v2'])->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->addJoin('F', 'a', 'T')->willReturn($datatable)->shouldBeCalledTimes(1);
     $datatableProphecy->addJoin('F1', 'a1', 'T1')->willReturn($datatable)->shouldBeCalledTimes(1);
     $container = new Container();
     $container->set('datatable', $datatable);
     $factory = new Factory();
     $factory->setContainer($container);
     $this->assertEquals($datatable, $factory->create($config));
 }
开发者ID:ruslan-polutsygan,项目名称:datatable-bundle,代码行数:34,代码来源:FactoryTest.php

示例6: register

 public function register(Container $container)
 {
     $container["data_collectors.swiftmailer.message_logger"] = function () {
         return new \Swift_Plugins_MessageLogger();
     };
     $container["data_collectors.swiftmailer.collector_container"] = function (Container $app) {
         $container = new SymfonyContainer();
         $container->setParameter("swiftmailer.mailers", ["default" => $app["swiftmailer.options"]]);
         $container->setParameter("swiftmailer.default_mailer", "default");
         $container->setParameter("swiftmailer.mailer.default.spool.enabled", $app["swiftmailer.use_spool"]);
         $container->set("swiftmailer.mailer.default.plugin.messagelogger", $app["data_collectors.swiftmailer.message_logger"]);
         return $container;
     };
     $container->extend('mailer', function (\Swift_Mailer $mailer, Container $container) {
         $mailer->registerPlugin($container['data_collectors.swiftmailer.message_logger']);
         return $mailer;
     });
     $container->extend('data_collectors', function (array $collectors, Container $container) {
         $collectors['swiftmailer'] = function ($container) {
             return new MessageDataCollector($container["data_collectors.swiftmailer.collector_container"]);
         };
         return $collectors;
     });
     $container->extend('data_collector.templates', function ($templates) {
         $templates[] = ['swiftmailer', '@Swiftmailer/Collector/swiftmailer.html.twig'];
         return $templates;
     });
     $container->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $loader) {
         $loader->addPath(dirname(dirname((new \ReflectionClass(MessageDataCollector::class))->getFileName())) . '/Resources/views', 'Swiftmailer');
         return $loader;
     });
 }
开发者ID:texthtml,项目名称:silex-swiftmailer-profiler,代码行数:32,代码来源:SwiftmailerProfilerServiceProvider.php

示例7: __construct

 /**
  * __construct function.
  *
  * @access public
  * @param Container $container
  */
 public function __construct(Container $container)
 {
     // Getting all symfony parameters
     $this->parameters = $container->getParameterBag()->all();
     // Getting all parameters keys
     $this->keys = array_keys($this->parameters);
 }
开发者ID:xavier-dubreuil,项目名称:LightCMS,代码行数:13,代码来源:ParametersService.php

示例8: __construct

 /**
  * FormFactory constructor.
  * @param Container $container
  */
 public function __construct(Container $container)
 {
     # configuring the form factory
     $this->formFactory = Forms::createFormFactoryBuilder()->addExtension(new DoctrineOrmExtension(new ExtendedEntityManager($container->get('models'))))->addExtension(new ValidatorExtension(Validation::createValidator()))->getFormFactory();
     # registering all necessary smarty plugins
     new SmartyPlugins($this->getFormHelper(), $container->get('template'));
 }
开发者ID:bcremer,项目名称:shopware-symfony-forms,代码行数:11,代码来源:FormFactory.php

示例9: __construct

 /**
  * @param EntityManager $entityManager
  */
 public function __construct(EntityManager $entityManager, Container $container)
 {
     $this->em = $entityManager;
     $this->qb = $entityManager->createQueryBuilder();
     $this->mailer = $container->get('mailer');
     $this->templating = $container->get('templating');
 }
开发者ID:riki343,项目名称:naidusvoe,代码行数:10,代码来源:Notifier.php

示例10: getIndexManager

 public static function getIndexManager(Container $container = null, $vertical)
 {
     if ($vertical != '') {
         return $container->get('rmc_' . $vertical . '.post_solr_service');
     }
     return NULL;
 }
开发者ID:jignesh-russmediatech,项目名称:rmcdemo,代码行数:7,代码来源:AdSolrIndexServiceFactory.php

示例11: getEntityManager

 /**
  * Get an EntityManager
  * @return EntityManager
  */
 public function getEntityManager()
 {
     if ($this->em === null) {
         $this->setEntityManager($this->container->get('doctrine')->getManager($this->emName));
     }
     return $this->em;
 }
开发者ID:qbbr,项目名称:SphinxsearchBundle,代码行数:11,代码来源:Bridge.php

示例12: 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

示例13: warmUp

 public function warmUp($cacheDir)
 {
     // we need the directory no matter the hydrator cache generation strategy.
     $hydratorCacheDir = $this->container->getParameter('doctrine.odm.mongodb.hydrator_dir');
     if (!file_exists($hydratorCacheDir)) {
         if (false === @mkdir($hydratorCacheDir, 0777, true)) {
             throw new \RuntimeException(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir)));
         }
     } else {
         if (!is_writable($hydratorCacheDir)) {
             throw new \RuntimeException(sprintf('Doctrine Hydrator directory (%s) is not writeable for the current system user.', $hydratorCacheDir));
         }
     }
     // if hydrators are autogenerated we don't need to generate them in the cache warmer.
     if ($this->container->getParameter('doctrine.odm.mongodb.auto_generate_hydrator_classes') === true) {
         return;
     }
     $documentManagers = $this->container->getParameter('doctrine.odm.mongodb.document_managers');
     foreach ($documentManagers as $documentManagerName) {
         $dm = $this->container->get(sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManagerName));
         /* @var $dm Doctrine\ODM\MongoDB\DocumentManager */
         $classes = $dm->getMetadataFactory()->getAllMetadata();
         $dm->getHydratorFactory()->generateHydratorClasses($classes);
     }
 }
开发者ID:noelg,项目名称:symfony-demo,代码行数:25,代码来源:HydratorCacheWarmer.php

示例14: doFilter

 private function doFilter(AssetInterface $asset)
 {
     $content = $asset->getContent();
     $callback = function ($matches) {
         $fs = new Filesystem();
         $resource = $matches['resource'];
         preg_match("/(\\@{1,2})([A-Z][A-Za-z0-9\\_\\-]*)/", $resource, $matches);
         if ($resource[1] == "@") {
             $resource = substr($resource, 1);
         }
         try {
             $bundle = $this->container->get('kernel')->getBundle($matches[2]);
             $path = $this->container->get('kernel')->locateResource($resource);
             if ($fs->exists($path)) {
                 if (preg_match("/Resources\\/public\\/(.*)/", $path, $matches2)) {
                     $path = 'bundles/' . preg_replace('/bundle$/', '', strtolower($bundle->getName())) . '/' . $matches2[1];
                     if ($matches[1] == "@@") {
                         return $this->container->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . $path;
                     }
                     try {
                         return $this->container->get('templating.helper.assets')->getUrl($path);
                     } catch (InactiveScopeException $e) {
                         return "../" . $path;
                     }
                 }
             }
         } catch (Exception $e) {
         }
         return $resource;
     };
     $pattern = "/(?P<resource>\\@{1,2}[A-Za-z\\_]+Bundle[A-Za-z0-9\\_\\.\\/\\-]*)/";
     $asset->setContent(preg_replace_callback($pattern, $callback, $content));
 }
开发者ID:hexmedia,项目名称:administrator-bundle,代码行数:33,代码来源:AssetsUrl.php

示例15: getRepository

 /**
  * Get entity for storage users
  *
  * @return \Doctrine\ORM\EntityRepository|null
  */
 public function getRepository()
 {
     if ($this->entity) {
         return $this->container->get('doctrine.orm.entity_manager')->getRepository($this->entity);
     }
     return null;
 }
开发者ID:timiki,项目名称:users-bundle,代码行数:12,代码来源:EntityProvider.php


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