本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::getAliases方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::getAliases方法的具体用法?PHP ContainerBuilder::getAliases怎么用?PHP ContainerBuilder::getAliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::getAliases方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Processes the ContainerBuilder to resolve parameter placeholders.
*
* @param ContainerBuilder $container
*
* @throws ParameterNotFoundException
*/
public function process(ContainerBuilder $container)
{
$parameterBag = $container->getParameterBag();
foreach ($container->getDefinitions() as $id => $definition) {
try {
$definition->setClass($parameterBag->resolveValue($definition->getClass()));
$definition->setFile($parameterBag->resolveValue($definition->getFile()));
$definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
if ($definition->getFactoryClass(false)) {
$definition->setFactoryClass($parameterBag->resolveValue($definition->getFactoryClass(false)));
}
$factory = $definition->getFactory();
if (is_array($factory) && isset($factory[0])) {
$factory[0] = $parameterBag->resolveValue($factory[0]);
$definition->setFactory($factory);
}
$calls = array();
foreach ($definition->getMethodCalls() as $name => $arguments) {
$calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
}
$definition->setMethodCalls($calls);
$definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
} catch (ParameterNotFoundException $e) {
$e->setSourceId($id);
throw $e;
}
}
$aliases = array();
foreach ($container->getAliases() as $name => $target) {
$aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
}
$container->setAliases($aliases);
$parameterBag->resolve();
}
示例2: process
public function process(ContainerBuilder $container)
{
$hasChanged = false;
$aliases = $container->getAliases();
foreach ($container->getDefinitions() as $id => $definition) {
if ($definition->isPublic()) {
continue;
}
$referencingAliases = array_keys($aliases, $id, true);
$isReferenced = $this->isReferenced($container, $id);
if (1 === count($referencingAliases) && false === $isReferenced) {
$container->setDefinition(reset($referencingAliases), $definition);
$definition->setPublic(true);
$container->remove($id);
} else {
if (0 === count($referencingAliases) && false === $isReferenced) {
$container->remove($id);
$hasChanged = true;
}
}
}
if ($hasChanged) {
$this->process($container);
}
}
示例3: testCrossCheck
/**
* @dataProvider crossCheckLoadersDumpers
*/
public function testCrossCheck($fixture, $type)
{
$loaderClass = 'Symfony\\Component\\DependencyInjection\\Loader\\' . ucfirst($type) . 'FileLoader';
$dumperClass = 'Symfony\\Component\\DependencyInjection\\Dumper\\' . ucfirst($type) . 'Dumper';
$tmp = tempnam('sf_service_container', 'sf');
file_put_contents($tmp, file_get_contents(self::$fixturesPath . '/' . $type . '/' . $fixture));
$container1 = new ContainerBuilder();
$loader1 = new $loaderClass($container1, new FileLocator());
$loader1->load($tmp);
$dumper = new $dumperClass($container1);
file_put_contents($tmp, $dumper->dump());
$container2 = new ContainerBuilder();
$loader2 = new $loaderClass($container2, new FileLocator());
$loader2->load($tmp);
unlink($tmp);
$this->assertEquals($container2->getAliases(), $container1->getAliases(), 'loading a dump from a previously loaded container returns the same container');
$this->assertEquals($container2->getDefinitions(), $container1->getDefinitions(), 'loading a dump from a previously loaded container returns the same container');
$this->assertEquals($container2->getParameterBag()->all(), $container1->getParameterBag()->all(), '->getParameterBag() returns the same value for both containers');
$this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container');
$services1 = array();
foreach ($container1 as $id => $service) {
$services1[$id] = serialize($service);
}
$services2 = array();
foreach ($container2 as $id => $service) {
$services2[$id] = serialize($service);
}
unset($services1['service_container'], $services2['service_container']);
$this->assertEquals($services2, $services1, 'Iterator on the containers returns the same services');
}
示例4: 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;
}
示例5: process
public function process(ContainerBuilder $container)
{
$this->parameterBag = $container->getParameterBag();
foreach ($container->getDefinitions() as $definition) {
$definition->setClass($this->resolveValue($definition->getClass()));
$definition->setFile($this->resolveValue($definition->getFile()));
$definition->setArguments($this->resolveValue($definition->getArguments()));
$calls = array();
foreach ($definition->getMethodCalls() as $name => $arguments) {
$calls[$this->resolveValue($name)] = $this->resolveValue($arguments);
}
$definition->setMethodCalls($calls);
}
$aliases = array();
foreach ($container->getAliases() as $name => $target) {
$aliases[$this->resolveValue($name)] = $this->resolveValue($target);
}
$container->setAliases($aliases);
$injectors = array();
foreach ($container->getInterfaceInjectors() as $class => $injector) {
$injector->setClass($this->resolveValue($injector->getClass()));
$injectors[$this->resolveValue($class)] = $injector;
}
$container->setInterfaceInjectors($injectors);
$parameterBag = $container->getParameterBag();
foreach ($parameterBag->all() as $key => $value) {
$parameterBag->set($key, $this->resolveValue($value));
}
}
示例6: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$parameters = $container->getParameterBag()->all();
$definitions = $container->getDefinitions();
$aliases = $container->getAliases();
$exprLangProviders = $container->getExpressionLanguageProviders();
foreach ($container->getExtensions() as $extension) {
if ($extension instanceof PrependExtensionInterface) {
$extension->prepend($container);
}
}
foreach ($container->getExtensions() as $name => $extension) {
if (!($config = $container->getExtensionConfig($name))) {
// this extension was not called
continue;
}
$config = $container->getParameterBag()->resolveValue($config);
$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->setResourceTracking($container->isTrackingResources());
$tmpContainer->addObjectResource($extension);
foreach ($exprLangProviders as $provider) {
$tmpContainer->addExpressionLanguageProvider($provider);
}
$extension->load($config, $tmpContainer);
$container->merge($tmpContainer);
$container->getParameterBag()->add($parameters);
}
$container->addDefinitions($definitions);
$container->addAliases($aliases);
}
示例7: testGetServiceDefinitionWithReferenceToAlias
/**
* Tests that references to aliases work correctly.
*
* @covers ::getReferenceCall
*
* @dataProvider publicPrivateDataProvider
*/
public function testGetServiceDefinitionWithReferenceToAlias($public)
{
$bar_definition = new Definition('\\stdClass');
$bar_definition_php_array = array('class' => '\\stdClass');
if (!$public) {
$bar_definition->setPublic(FALSE);
$bar_definition_php_array['public'] = FALSE;
}
$bar_definition_php_array['arguments_count'] = 0;
$services['bar'] = $bar_definition;
$aliases['bar.alias'] = 'bar';
$foo = new Definition('\\stdClass');
$foo->addArgument(new Reference('bar.alias'));
$services['foo'] = $foo;
$this->containerBuilder->getAliases()->willReturn($aliases);
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->containerBuilder->getDefinition('bar')->willReturn($bar_definition);
$dump = $this->dumper->getArray();
if ($public) {
$service_definition = $this->getServiceCall('bar');
} else {
$service_definition = $this->getPrivateServiceCall('bar', $bar_definition_php_array, TRUE);
}
$data = array('class' => '\\stdClass', 'arguments' => $this->getCollection(array($service_definition)), 'arguments_count' => 1);
$this->assertEquals($this->serializeDefinition($data), $dump['services']['foo'], 'Expected definition matches dump.');
}
示例8: process
/**
* Processes the ContainerBuilder to resolve parameter placeholders.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$this->parameterBag = $container->getParameterBag();
foreach ($container->getDefinitions() as $id => $definition) {
try {
$definition->setClass($this->resolveValue($definition->getClass()));
$definition->setFile($this->resolveValue($definition->getFile()));
$definition->setArguments($this->resolveValue($definition->getArguments()));
$calls = array();
foreach ($definition->getMethodCalls() as $name => $arguments) {
$calls[$this->resolveValue($name)] = $this->resolveValue($arguments);
}
$definition->setMethodCalls($calls);
$definition->setProperties($this->resolveValue($definition->getProperties()));
} catch (ParameterNotFoundException $e) {
$e->setSourceId($id);
throw $e;
}
}
$aliases = array();
foreach ($container->getAliases() as $name => $target) {
$aliases[$this->resolveValue($name)] = $this->resolveValue($target);
}
$container->setAliases($aliases);
$parameterBag = $container->getParameterBag();
foreach ($parameterBag->all() as $key => $value) {
try {
$parameterBag->set($key, $this->resolveValue($value));
} catch (ParameterNotFoundException $e) {
$e->setSourceKey($key);
throw $e;
}
}
}
示例9: process
public function process(ContainerBuilder $container)
{
foreach ($container->getAliases() as $id => $alias) {
if ($alias->isPublic()) {
continue;
}
$container->removeAlias($id);
}
}
示例10: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
foreach (array_keys($container->getAliases()) as $alias) {
if (strpos($alias, 'hwi_oauth.resource_owner.') !== 0) {
continue;
}
$aliasIdParts = explode('.', $alias);
$resourceOwnerDefinition = $container->findDefinition($alias);
$resourceOwnerDefinition->addMethodCall('setName', array(end($aliasIdParts)));
}
}
示例11: updateReferences
/**
* Updates references to remove aliases.
*
* @param ContainerBuilder $container The container
* @param string $currentId The alias identifier being replaced
* @param string $newId The id of the service the alias points to
*/
private function updateReferences($container, $currentId, $newId)
{
foreach ($container->getAliases() as $id => $alias) {
if ($currentId === (string) $alias) {
$container->setAlias($id, $newId);
}
}
foreach ($container->getDefinitions() as $definition) {
$definition->setArguments($this->updateArgumentReferences($definition->getArguments(), $currentId, $newId));
$definition->setMethodCalls($this->updateArgumentReferences($definition->getMethodCalls(), $currentId, $newId));
}
}
示例12: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->hasParameter('cache.prefix.seed')) {
$seed = '.' . $container->getParameterBag()->resolveValue($container->getParameter('cache.prefix.seed'));
} else {
$seed = '_' . $container->getParameter('kernel.root_dir');
}
$seed .= '.' . $container->getParameter('kernel.name') . '.' . $container->getParameter('kernel.environment') . '.' . $container->getParameter('kernel.debug');
$aliases = $container->getAliases();
$attributes = array('provider', 'namespace', 'default_lifetime');
foreach ($container->findTaggedServiceIds('cache.pool') as $id => $tags) {
$adapter = $pool = $container->getDefinition($id);
if ($pool->isAbstract()) {
continue;
}
while ($adapter instanceof DefinitionDecorator) {
$adapter = $container->findDefinition($adapter->getParent());
if ($t = $adapter->getTag('cache.pool')) {
$tags[0] += $t[0];
}
}
if (!isset($tags[0]['namespace'])) {
$tags[0]['namespace'] = $this->getNamespace($seed, $id);
}
if (isset($tags[0]['clearer'])) {
$clearer = strtolower($tags[0]['clearer']);
while (isset($aliases[$clearer])) {
$clearer = (string) $aliases[$clearer];
}
} else {
$clearer = null;
}
unset($tags[0]['clearer']);
if (isset($tags[0]['provider'])) {
$tags[0]['provider'] = new Reference(static::getServiceProvider($container, $tags[0]['provider']));
}
$i = 0;
foreach ($attributes as $attr) {
if (isset($tags[0][$attr])) {
$pool->replaceArgument($i++, $tags[0][$attr]);
}
unset($tags[0][$attr]);
}
if (!empty($tags[0])) {
throw new InvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "clearer", "provider", "namespace" and "default_lifetime", found "%s".', $id, implode('", "', array_keys($tags[0]))));
}
if (null !== $clearer) {
$pool->addTag('cache.pool', array('clearer' => $clearer));
}
}
}
示例13: process
public function process(ContainerBuilder $container)
{
$this->container = $container;
foreach ($container->getDefinitions() as $id => $definition) {
$definition->setArguments($this->processArguments($definition->getArguments()));
$definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
}
foreach ($container->getAliases() as $id => $alias) {
$aliasId = (string) $alias;
if ($aliasId !== ($defId = $this->getDefinitionId($aliasId))) {
$container->setAlias($id, new Alias($defId, $alias->isPublic()));
}
}
}
示例14: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$parameters = $container->getParameterBag()->all();
$definitions = $container->getDefinitions();
$aliases = $container->getAliases();
foreach ($container->getExtensions() as $name => $extension) {
$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->addObjectResource($extension);
$extension->load($container->getExtensionConfig($name), $tmpContainer);
$container->merge($tmpContainer);
}
$container->addDefinitions($definitions);
$container->addAliases($aliases);
$container->getParameterBag()->add($parameters);
}
示例15: updateReferences
/**
* Updates references to remove aliases.
*
* @param ContainerBuilder $container The container
* @param string $currentId The alias identifier being replaced
* @param string $newId The id of the service the alias points to
*/
private function updateReferences($container, $currentId, $newId)
{
foreach ($container->getAliases() as $id => $alias) {
if ($currentId === (string) $alias) {
$container->setAlias($id, $newId);
}
}
foreach ($container->getDefinitions() as $id => $definition) {
$this->sourceId = $id;
$definition->setArguments($this->updateArgumentReferences($definition->getArguments(), $currentId, $newId));
$definition->setMethodCalls($this->updateArgumentReferences($definition->getMethodCalls(), $currentId, $newId));
$definition->setProperties($this->updateArgumentReferences($definition->getProperties(), $currentId, $newId));
$definition->setFactoryService($this->updateFactoryServiceReference($definition->getFactoryService(), $currentId, $newId));
}
}