本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::get方法的具体用法?PHP ContainerBuilder::get怎么用?PHP ContainerBuilder::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProviderIsAdded
public function testProviderIsAdded()
{
$targetService = new Definition();
$targetService->setClass('Faker\\Generator');
$provider = $this->getMock('Acme\\Faker\\Provider\\CustomFakeDataProvider');
$providerService = new Definition();
$providerService->setClass(get_class($provider));
$providerService->addTag('bazinga_faker.provider');
$builder = new ContainerBuilder();
$builder->addDefinitions(array('faker.generator' => $targetService, 'acme.faker.provider.custom' => $providerService));
$builder->addCompilerPass(new AddProvidersPass());
$builder->compile();
$this->assertNotEmpty($builder->getServiceIds(), 'The services have been injected.');
$this->assertNotEmpty($builder->get('faker.generator'), 'The faker.generator service has been injected.');
$this->assertNotEmpty($builder->get('acme.faker.provider.custom'), 'The provider service has been injected.');
/*
* Schema:
*
* [0] The list of methods.
* [0] The name of the method to call.
* [1] The arguments to pass into the method call.
* [0] First argument to pass into the method call.
* ...
*/
$targetMethodCalls = $builder->getDefinition('faker.generator')->getMethodCalls();
$this->assertNotEmpty($targetMethodCalls, 'The faker.generator service got method calls added.');
$this->assertEquals('addProvider', $targetMethodCalls[0][0], 'The faker.generator service got a provider added.');
$this->assertEquals('acme.faker.provider.custom', $targetMethodCalls[0][1][0], 'The faker.generator service got the correct provider added.');
}
示例2: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$configuration = $container->getParameter('knp_rad_auto_registration.configuration');
$enable = $configuration['enable'];
$generator = $container->get('knp_rad_auto_registration.service_name_generator.bundle_service_name_generator');
foreach ($container->findTaggedServiceIds('knp_rad_auto_registration.definition_builder') as $id => $tags) {
$builder = $container->get($id);
if (false === $builder->isActive()) {
continue;
}
if (false === in_array($builder->getName(), $this->sections)) {
continue;
}
if (false === array_key_exists($builder->getName(), $enable)) {
continue;
}
$definitions = $builder->buildDefinitions($enable[$builder->getName()]);
foreach ($definitions as $class => $definition) {
$serviceId = $generator->generateFromClassname($class);
if (true === $container->hasDefinition($serviceId)) {
continue;
}
if (true === $container->hasAlias($serviceId)) {
continue;
}
$container->setDefinition($serviceId, $definition);
}
}
}
示例3: array
/**
* @param null $configPath
* @param array $configFilenames
*/
function __construct($configPath = null, $configFilenames = array())
{
$configPath = $configPath == null ? __DIR__ . '/../../../../../../app/config' : $configPath;
$this->container = new ContainerBuilder();
// Load app parameters and config files into container
$loader = new YamlFileLoader($this->container, new FileLocator($configPath));
$loader->load('parameters.yml');
foreach ($configFilenames as $filename) {
$loader->load($filename);
}
$appName = $this->container->getParameter('application_name');
$appVersion = $this->container->getParameter('application_version');
parent::__construct($appName, $appVersion);
// Set dispatcher definition, register listeners and subscribers
$dispatcherDef = $this->container->register('event_dispatcher', 'Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher');
$dispatcherDef->addArgument($this->container);
$this->registerEventListeners();
$this->container->compile();
// Once container is compiled we can get the event_dispatcher from dic
$this->dispatcher = $this->container->get('event_dispatcher');
// Add console commands (services console.command tagged)
foreach ($this->getTaggedCommands() as $id) {
$command = $this->container->get($id);
$this->add($command);
}
}
示例4: process
public function process(ContainerBuilder $container)
{
$enableCache = $container->getParameter('antares_accessible.cache.enable');
// Annotation reader
$annotationsReader = $container->get('antares_accessible.annotations.reader');
if ($annotationsReader instanceof NullService) {
if ($enableCache) {
$debug = $container->getParameter('kernel.debug');
$annotationCacheDriver = $container->get('antares_accessible.annotations.cache_driver');
$annotationsCache = new ChainCache([new ArrayCache(), $annotationCacheDriver]);
Configuration::setAnnotationReader(new CachedReader(new AnnotationReader(), $annotationsCache, $debug));
}
} else {
Configuration::setAnnotationReader($annotationsReader);
}
// Constraints validator
$constraintsValidator = $container->get('antares_accessible.constraints_validation.validator');
if (!$constraintsValidator instanceof NullService) {
Configuration::setConstraintsValidator($constraintsValidator);
}
// Cache driver
if ($enableCache) {
$cacheDriver = $container->get('antares_accessible.cache.driver');
Configuration::setCacheDriver($cacheDriver);
}
// Enable the constraints validation of Initialize annotations values
$constraintsValidationEnabled = $container->getParameter('antares_accessible.constraints_validation.enable');
Configuration::setConstraintsValidationEnabled($constraintsValidationEnabled);
// Enable the constraints validation of Initialize annotations values
$validateInitializeValues = $container->getParameter('antares_accessible.constraints_validation.validate_initialize_values');
Configuration::setInitializeValuesValidationEnabled($validateInitializeValues);
}
示例5: process
/**
* @param ContainerBuilder $container
*
* @throws \InvalidArgumentException
*/
public function process(ContainerBuilder $container)
{
$config = $container->getExtensionConfig('elastica')[0];
$jsonLdFrameLoader = $container->get('nemrod.elastica.jsonld.frame.loader.filesystem');
$confManager = $container->getDefinition('nemrod.elastica.config_manager');
$filiationBuilder = $container->get('nemrod.filiation.builder');
$jsonLdFrameLoader->setFiliationBuilder($filiationBuilder);
foreach ($config['indexes'] as $name => $index) {
$indexName = isset($index['index_name']) ? $index['index_name'] : $name;
foreach ($index['types'] as $typeName => $settings) {
$jsonLdFrameLoader->setEsIndex($name);
$frame = $jsonLdFrameLoader->load($settings['frame'], null, true, true, true);
$type = !empty($frame['@type']) ? $frame['@type'] : $settings['type'];
if (empty($type)) {
throw \Exception("You must provide a RDF Type.");
}
//type
$typeId = 'nemrod.elastica.type.' . $name . '.' . $typeName;
$indexId = 'nemrod.elastica.index.' . $name;
$typeDef = new DefinitionDecorator('nemrod.elastica.type.abstract');
$typeDef->replaceArgument(0, $type);
$typeDef->setFactory(array(new Reference($indexId), 'getType'));
$typeDef->addTag('nemrod.elastica.type', array('index' => $name, 'name' => $typeName, 'type' => $type));
$container->setDefinition($typeId, $typeDef);
//registering config to configManager
$confManager->addMethodCall('setTypeConfigurationArray', array($name, $typeName, $type, $frame));
}
}
}
示例6: getAnalyzerCommand
protected function getAnalyzerCommand()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load('Config/services.yml');
return new AnalyzerCommand($container->get('analyzer'), $container->get('logger'));
}
示例7: testQueryService
public function testQueryService()
{
$this->loadConfiguration($this->container, 'xiti_analytics');
$this->container->compile();
$query = $this->container->get('request_lab_xiti_analytics.query');
$this->assertInstanceOf('RequestLab\\XitiAnalytics\\Query', $query);
}
开发者ID:RequestLab,项目名称:XitiAnalyticsBundle,代码行数:7,代码来源:AbstractRequestLabXitiAnalyticsExtensionTest.php
示例8: testReconnectConfiguration
public function testReconnectConfiguration()
{
$this->initContainer();
$this->loadConfiguration($this->container, 'reconnect_config');
$this->container->compile();
$this->assert->boolean($this->container->has('m6_redis'))->isIdenticalTo(true)->and()->object($serviceRedis = $this->container->get('m6_redis'))->isInstanceOf('M6Web\\Bundle\\RedisBundle\\Redis\\Redis');
}
示例9: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
try {
// We have the service fork.settings and it's not empty
if ($container->has('fork.settings') && !is_a($container->get('fork.settings'), 'stdClass')) {
// we must set these parameters to be usable
$container->setParameter('mailmotor.mail_engine', $container->get('fork.settings')->get('Mailmotor', 'mail_engine'));
$container->setParameter('mailmotor.api_key', $container->get('fork.settings')->get('Mailmotor', 'api_key'));
$container->setParameter('mailmotor.list_id', $container->get('fork.settings')->get('Mailmotor', 'list_id'));
// When in fork cms installer, we don't have the service fork.settings
// but we must set the parameters
} else {
// we must set these parameters to be usable
$container->setParameter('mailmotor.mail_engine', 'not_implemented');
$container->setParameter('mailmotor.api_key', null);
$container->setParameter('mailmotor.list_id', null);
}
} catch (\Exception $e) {
// this might fail in the test so we have this as fallback
// we must set these parameters to be usable
$container->setParameter('mailmotor.mail_engine', 'not_implemented');
$container->setParameter('mailmotor.api_key', null);
$container->setParameter('mailmotor.list_id', null);
}
}
示例10: updateUser
/**
* Updates a user.
*
* @param UserInterface $user
* @param Boolean $andFlush Whether to flush the changes (default true)
*/
public function updateUser(UserInterface $user, $andFlush = true)
{
parent::updateUser($user, $andFlush);
if ($this->container->getParameter('ephp_acl.access_log.enable')) {
$accessClassName = $this->accessClass;
try {
$request = $this->container->get('request');
// \Ephp\UtilityBundle\Utility\Debug::vd($request);
$check_ip = $this->container->getParameter('ephp_acl.access_log.check_ip');
if ($check_ip) {
$_access = $this->objectManager->getRepository($accessClassName);
/* @var $_access Ephp\ACLBundle\Model\BaseAccessLogRepository */
$_access->checkIp($user, $request->server->get('REMOTE_ADDR'));
}
$access = new $accessClassName();
/* @var $access \Ephp\ACLBundle\Model\BaseAccessLog */
$access->setUser($user);
/* @var $request \Symfony\Component\HttpFoundation\Request */
$access->setIp($request->server->get('REMOTE_ADDR'));
foreach ($request->cookies as $name => $cookie) {
$access->addCookie($name, $cookie);
}
$access->setLoggedAt(new \DateTime());
$access->addNote('user_agent', $request->server->get('HTTP_USER_AGENT'));
$access->addNote('accept_language', $request->server->get('HTTP_ACCEPT_LANGUAGE'));
$this->objectManager->persist($access);
$this->objectManager->flush();
// \Ephp\UtilityBundle\Utility\Debug::pr($request->server);
$request->getSession()->set('access.log', $access->getId());
} catch (CheckIpException $e) {
throw $e;
} catch (\Exception $e) {
}
}
}
示例11: get
/**
* Returns task
*
* @param string $alias name of the task
* @param array $options configuration options for the task
* @return Task
*/
public function get($alias, array $options = array())
{
$serviceId = $this->tasks[$alias];
$task = $this->container->get($serviceId);
$task->setOptions($options);
return $task;
}
示例12: process
public function process(ContainerBuilder $container)
{
$reader = $container->get('annotation_reader');
$factory = $container->get('jms_di_extra.metadata.metadata_factory');
$converter = $container->get('jms_di_extra.metadata.converter');
$directories = $this->getScanDirectories($container);
if (!$directories) {
$container->getCompiler()->addLogMessage('No directories configured for AnnotationConfigurationPass.');
return;
}
$files = $this->finder->findFiles($directories);
$container->addResource(new ServiceFilesResource($files, $directories));
foreach ($files as $file) {
$container->addResource(new FileResource($file));
require_once $file;
$className = $this->getClassName($file);
if (null === ($metadata = $factory->getMetadataForClass($className))) {
continue;
}
if (null === $metadata->getOutsideClassMetadata()->id) {
continue;
}
foreach ($converter->convert($metadata) as $id => $definition) {
$container->setDefinition($id, $definition);
}
}
}
示例13: __construct
/**
* Set up application:
*/
public function __construct()
{
$this->filesystem = new Filesystem();
$this->container = $this->getContainer();
$this->setDispatcher($this->container->get('event_dispatcher'));
parent::__construct(self::APP_NAME, self::APP_VERSION);
}
示例14: get
/**
* @throws NotFoundException
*
* @param string $serviceId
* @return mixed
*/
public function get($serviceId)
{
if (!$this->has($serviceId)) {
throw NotFoundException::constructWithThingNotFound($serviceId);
}
return $this->symfonyServiceContainer->get($serviceId);
}
示例15: testTemplatingConfiguration
public function testTemplatingConfiguration()
{
$this->loadConfiguration($this->container, 'simple');
$this->container->compile();
$helper = $this->container->get('fm_tinymce.templating.helper');
$this->assertInstanceOf('FM\\TinyMCEBundle\\Templating\\TinyMCEHelper', $helper);
}