本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::getDefinitions方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::getDefinitions方法的具体用法?PHP ContainerBuilder::getDefinitions怎么用?PHP ContainerBuilder::getDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::getDefinitions方法的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: getListenersIds
/**
* getListenersIds
*
* Searches for any number of defined listeners under the tag "*.event_listener"
*
* @return array listeners ids
*/
protected function getListenersIds()
{
$listenersIds = array();
if (!$this->containerBuilder->hasDefinition('event_dispatcher')) {
return $listenersIds;
}
$definition = $this->containerBuilder->getDefinition('event_dispatcher');
$dfs = $this->containerBuilder->getDefinitions();
foreach ($dfs as $k => $v) {
$tags = $v->getTags();
if (count($tags) <= 0) {
continue;
}
$keys = array_keys($tags);
$tag = $keys[0];
if (preg_match('/.+\\.event_listener/', $tag)) {
$services = $this->containerBuilder->findTaggedServiceIds($tag);
foreach ($services as $id => $events) {
$this->listeners[$id]['tag'] = $tags[$tag][0];
$listenersIds[$id] = $id;
}
}
}
return $listenersIds;
}
示例3: process
public function process(ContainerBuilder $container)
{
$fingersCrossedHandlersId = 'long_running.monolog.clear_fingers_crossed_handlers';
if ($container->has($fingersCrossedHandlersId)) {
$fingersCrossedServiceReferences = [];
foreach ($container->getDefinitions() as $serviceId => $definition) {
if (strpos($serviceId, 'monolog.handler.') === 0) {
$class = $container->getParameterBag()->resolveValue($definition->getClass());
if (is_a($class, 'Monolog\\Handler\\FingersCrossedHandler', true)) {
$fingersCrossedServiceReferences[] = new Reference($serviceId);
}
}
}
$definition = $container->getDefinition($fingersCrossedHandlersId);
$definition->replaceArgument(0, $fingersCrossedServiceReferences);
}
$bufferHandlersId = 'long_running.monolog.close_buffer_handlers';
if ($container->has($bufferHandlersId)) {
$bufferHandlerServiceReferences = [];
foreach ($container->getDefinitions() as $serviceId => $definition) {
if (strpos($serviceId, 'monolog.handler.') === 0) {
$class = $container->getParameterBag()->resolveValue($definition->getClass());
if (is_a($class, 'Monolog\\Handler\\BufferHandler', true)) {
$bufferHandlerServiceReferences[] = new Reference($serviceId);
}
}
}
$definition = $container->getDefinition($bufferHandlersId);
$definition->replaceArgument(0, $bufferHandlerServiceReferences);
}
}
示例4: testServicesAreCreated
public function testServicesAreCreated()
{
$this->extension->load($this->config, $this->containerBuilder);
$definitions = $this->containerBuilder->getDefinitions();
$this->assertEquals(6, count($definitions));
$this->assertTrue($this->containerBuilder->hasDefinition('apinnecke_oauth.service.xing'));
$this->assertTrue($this->containerBuilder->hasDefinition('apinnecke_oauth.service.facebook'));
}
示例5: getAllRouteCollectionProviders
/**
* @return RouteCollectionProviderInterface[]
*/
private function getAllRouteCollectionProviders() : array
{
$filters = [];
foreach ($this->containerBuilder->getDefinitions() as $name => $definition) {
if (is_subclass_of($definition->getClass(), RouteCollectionProviderInterface::class)) {
$filters[$name] = $definition;
}
}
return $filters;
}
示例6: 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;
}
}
}
示例7: 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);
}
示例8: process
public function process(ContainerBuilder $container)
{
$this->parameterBag = $parameterBag = $container->getParameterBag();
try {
$preferredServices = (array) $parameterBag->resolveValue("%autowiring.preferred_services%");
} catch (ParameterNotFoundException $exception) {
$preferredServices = [];
}
try {
$fastAnnotationChecksRegex = "/" . implode("|", array_map(function ($s) {
return preg_quote($s);
}, (array) $parameterBag->resolveValue("%autowiring.fast_annotation_checks%"))) . "/";
} catch (ParameterNotFoundException $exception) {
$fastAnnotationChecksRegex = null;
}
foreach ($container->getDefinitions() as $serviceId => $definition) {
if ($this->canDefinitionBeAutowired($serviceId, $definition) === false) {
continue;
}
try {
$className = $parameterBag->resolveValue($definition->getClass());
$reflectionClass = new ReflectionClass($className);
$this->autowireClass($className, $reflectionClass, $definition, $fastAnnotationChecksRegex, $preferredServices, $parameterBag);
// add files to cache
$container->addClassResource($reflectionClass);
} catch (AutowiringException $exception) {
throw new AutowiringException(sprintf("%s (service: %s)", $exception->getMessage(), $serviceId), $exception->getCode(), $exception);
}
}
}
示例9: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$throwingAutoloader = function ($class) {
throw new \ReflectionException(sprintf('Class %s does not exist', $class));
};
spl_autoload_register($throwingAutoloader);
try {
$this->container = $container;
foreach ($container->getDefinitions() as $id => $definition) {
if ($definition->isAutowired()) {
$this->completeDefinition($id, $definition);
}
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
spl_autoload_unregister($throwingAutoloader);
// Free memory and remove circular reference to container
$this->container = null;
$this->reflectionClasses = array();
$this->definedTypes = array();
$this->types = null;
$this->ambiguousServiceTypes = array();
if (isset($e)) {
throw $e;
}
}
示例10: process
/**
* Processes the ContainerBuilder to validate the Definition.
*
* @param ContainerBuilder $container
*
* @throws RuntimeException When the Definition is invalid
*/
public function process(ContainerBuilder $container)
{
foreach ($container->getDefinitions() as $id => $definition) {
// synthetic service is public
if ($definition->isSynthetic() && !$definition->isPublic()) {
throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id));
}
// synthetic service has non-prototype scope
if ($definition->isSynthetic() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
throw new RuntimeException(sprintf('A synthetic service ("%s") cannot be of scope "prototype".', $id));
}
// shared service has non-prototype scope
if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
throw new RuntimeException(sprintf('A shared service ("%s") cannot be of scope "prototype".', $id));
}
// non-synthetic, non-abstract service has class
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
if ($definition->getFactory()) {
throw new RuntimeException(sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id));
}
throw new RuntimeException(sprintf('The definition for "%s" has no class. If you intend to inject ' . 'this service dynamically at runtime, please mark it as synthetic=true. ' . 'If this is an abstract definition solely used by child definitions, ' . 'please add abstract=true, otherwise specify a class to get rid of this error.', $id));
}
// tag attribute values must be scalars
foreach ($definition->getTags() as $name => $tags) {
foreach ($tags as $attributes) {
foreach ($attributes as $attribute => $value) {
if (!is_scalar($value) && null !== $value) {
throw new RuntimeException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $id, $name, $attribute));
}
}
}
}
}
}
示例11: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('security.access.method_interceptor')) {
return;
}
$services = $container->findTaggedServiceIds('security.secure_service');
$secureNotAll = !$container->getParameter('security.extra.secure_all_services');
$parameterBag = $container->getParameterBag();
foreach ($container->getDefinitions() as $id => $definition) {
if ($secureNotAll && !isset($services[$id])) {
continue;
}
if (null === ($class = $definition->getClass()) || !class_exists($class)) {
if ($secureNotAll) {
throw new \RuntimeException(sprintf('Could not find class "%s" for "%s".', $class, $id));
}
continue;
}
if (null !== $definition->getFactoryMethod() || $definition->isAbstract() || $definition->isSynthetic()) {
if ($secureNotAll) {
throw new \RuntimeException(sprintf('You cannot secure service "%s", because it is either created by a factory, or an abstract/synthetic service.', $id));
}
continue;
}
$this->processDefinition($container, $id, $definition);
}
$this->writeCacheMetadata();
}
示例12: 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;
}
示例13: process
public function process(ContainerBuilder $container)
{
$definitions = new \SplPriorityQueue();
$order = PHP_INT_MAX;
foreach ($container->getDefinitions() as $id => $definition) {
if (!($decorated = $definition->getDecoratedService())) {
continue;
}
$definitions->insert(array($id, $definition), array($decorated[2], --$order));
}
foreach ($definitions as list($id, $definition)) {
list($inner, $renamedId) = $definition->getDecoratedService();
$definition->setDecoratedService(null);
if (!$renamedId) {
$renamedId = $id . '.inner';
}
// we create a new alias/service for the service we are replacing
// to be able to reference it in the new one
if ($container->hasAlias($inner)) {
$alias = $container->getAlias($inner);
$public = $alias->isPublic();
$container->setAlias($renamedId, new Alias((string) $alias, false));
} else {
$definition = $container->getDefinition($inner);
$public = $definition->isPublic();
$definition->setPublic(false);
$container->setDefinition($renamedId, $definition);
}
$container->setAlias($inner, new Alias($id, $public));
}
}
示例14: 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');
}
示例15: process
public function process(ContainerBuilder $container)
{
$throwingAutoloader = function ($class) {
throw new \ReflectionException(sprintf('Class %s does not exist', $class));
};
spl_autoload_register($throwingAutoloader);
try {
$this->container = $container;
foreach ($container->getDefinitions() as $id => $definition) {
$this->populateAvailableTypes($id, $definition);
}
$this->populateAvailableTypes('service_container', new Definition(get_class($container)));
foreach ($this->types as $type => $services) {
$this->registerService($type, $services);
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
spl_autoload_unregister($throwingAutoloader);
// Free memory and remove circular reference to container
$this->container = null;
$this->reflectionClasses = [];
$this->definedTypes = [];
$this->types = null;
if (isset($e)) {
throw $e;
}
}