本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::getParameterBag方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::getParameterBag方法的具体用法?PHP ContainerBuilder::getParameterBag怎么用?PHP ContainerBuilder::getParameterBag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::getParameterBag方法的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)
{
if ($container->has('fos_rest.serializer')) {
$class = $container->getParameterBag()->resolveValue($container->findDefinition('fos_rest.serializer')->getClass());
if (!is_subclass_of($class, 'FOS\\RestBundle\\Serializer\\Serializer')) {
throw new \InvalidArgumentException(sprintf('"fos_rest.serializer" must implement FOS\\RestBundle\\Serializer\\Serializer (instance of "%s" given).', $class));
}
return;
}
if (!$container->has('serializer') && !$container->has('jms_serializer.serializer')) {
throw new \InvalidArgumentException('Neither a service called "jms_serializer.serializer" nor "serializer" is available and no serializer is explicitly configured. You must either enable the JMSSerializerBundle, enable the FrameworkBundle serializer or configure a custom serializer.');
}
if ($container->has('serializer')) {
$class = $container->getParameterBag()->resolveValue($container->findDefinition('serializer')->getClass());
if (is_subclass_of($class, 'Symfony\\Component\\Serializer\\SerializerInterface')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.symfony');
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
} elseif (is_subclass_of($class, 'JMS\\Serializer\\SerializerInterface')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.jms');
} elseif (is_subclass_of($class, 'FOS\\RestBundle\\Serializer\\Serializer')) {
$container->setAlias('fos_rest.serializer', 'serializer');
} else {
throw new \InvalidArgumentException(sprintf('"fos_rest.serializer" must implement FOS\\RestBundle\\Serializer\\Serializer (instance of "%s" given).', $class));
}
return;
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_normalizer');
}
if ($container->has('jms_serializer.serializer')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.jms');
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
}
}
示例3: collect
/**
* Collect information about services and parameters from the cached dumped xml container
*
* @param Request $request The Request Object
* @param Response $response The Response Object
* @param \Exception $exception The Exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$parameters = array();
$services = array();
$this->loadContainerBuilder();
if ($this->containerBuilder !== false) {
foreach ($this->containerBuilder->getParameterBag()->all() as $key => $value) {
$service = substr($key, 0, strpos($key, '.'));
if (!isset($parameters[$service])) {
$parameters[$service] = array();
}
$parameters[$service][$key] = $value;
}
$serviceIds = $this->containerBuilder->getServiceIds();
foreach ($serviceIds as $serviceId) {
$definition = $this->resolveServiceDefinition($serviceId);
if ($definition instanceof Definition && $definition->isPublic()) {
$services[$serviceId] = array('class' => $definition->getClass(), 'scope' => $definition->getScope());
} elseif ($definition instanceof Alias) {
$services[$serviceId] = array('alias' => $definition);
} else {
continue;
// We don't want private services
}
}
ksort($services);
ksort($parameters);
}
$this->data['parameters'] = $parameters;
$this->data['services'] = $services;
}
示例4: 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;
}
}
}
示例5: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->has('swarrot.factory.default') || !$container->hasParameter('swarrot.provider_config')) {
return;
}
$providersIds = [];
foreach ($container->findTaggedServiceIds('swarrot.provider_factory') as $id => $tags) {
foreach ($tags as $tag) {
if (!isset($tag['alias'])) {
throw new \InvalidArgumentException(sprintf('The provider\'s alias is no defined for the service "%s"', $id));
}
$providersIds[$tag['alias']] = $id;
}
}
list($provider, $connections) = $container->getParameter('swarrot.provider_config');
if (!isset($providersIds[$provider])) {
throw new \InvalidArgumentException(sprintf('Invalid provider "%s"', $provider));
}
$id = $providersIds[$provider];
$definition = $container->getDefinition($id);
$className = $container->getParameterBag()->resolveValue($definition->getClass());
$reflection = new \ReflectionClass($className);
if (!$reflection->implementsInterface('Swarrot\\SwarrotBundle\\Broker\\FactoryInterface')) {
throw new \InvalidArgumentException(sprintf('The provider "%s" is not valid', $provider));
}
foreach ($connections as $name => $connectionConfig) {
$definition->addMethodCall('addConnection', [$name, $connectionConfig]);
}
$container->setAlias('swarrot.factory.default', $id);
$container->getParameterBag()->remove('swarrot.provider_config');
}
示例6: load
/**
* Loads the configuration.
*
* @param array $configs An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('assetic.xml');
$loader->load('templating_twig.xml');
// $loader->load('templating_php.xml'); // not ready yet
$config = self::processConfigs($configs, $container->getParameter('kernel.debug'), array_keys($container->getParameter('kernel.bundles')));
$container->setParameter('assetic.debug', $config['debug']);
$container->setParameter('assetic.use_controller', $config['use_controller']);
$container->setParameter('assetic.read_from', $config['read_from']);
$container->setParameter('assetic.write_to', $config['write_to']);
$container->setParameter('assetic.default_javascripts_output', $config['default_javascripts_output']);
$container->setParameter('assetic.default_stylesheets_output', $config['default_stylesheets_output']);
if (isset($config['closure'])) {
$container->setParameter('assetic.google_closure_compiler_jar', $config['closure']);
$loader->load('google_closure_compiler.xml');
}
if (isset($config['yui'])) {
$container->setParameter('assetic.yui_jar', $config['yui']);
$loader->load('yui_compressor.xml');
}
if ($container->getParameterBag()->resolveValue($container->getParameterBag()->get('assetic.use_controller'))) {
$loader->load('controller.xml');
$container->setParameter('assetic.twig_extension.class', '%assetic.twig_extension.dynamic.class%');
} else {
$loader->load('asset_writer.xml');
$container->setParameter('assetic.twig_extension.class', '%assetic.twig_extension.static.class%');
}
if ($container->hasParameter('assetic.less.compress')) {
$container->getDefinition('assetic.filter.less')->addMethodCall('setCompress', array('%assetic.less.compress%'));
}
$this->registerFormulaResources($container, $container->getParameterBag()->resolveValue($config['bundles']));
}
示例7: load
/**
* Loads the configuration.
*
* When the debug flag is true, files in an asset collections will be
* rendered individually.
*
* In XML:
*
* <assetic:config
* debug="true"
* use-controller="true"
* document-root="/path/to/document/root"
* closure="/path/to/google_closure/compiler.jar"
* yui="/path/to/yuicompressor.jar"
* default-javascripts-output="js/build/*.js"
* default-stylesheets-output="css/build/*.css"
* />
*
* In YAML:
*
* assetic:
* debug: true
* use_controller: true
* document_root: /path/to/document/root
* closure: /path/to/google_closure/compiler.jar
* yui: /path/to/yuicompressor.jar
* default_javascripts_output: js/build/*.js
* default_stylesheets_output: css/build/*.css
*
* @param array $configs An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('assetic.xml');
$loader->load('templating_twig.xml');
// $loader->load('templating_php.xml'); // not ready yet
$configuration = new Configuration();
$processor = new Processor();
$config = $processor->process($configuration->getConfigTree($container->getParameter('kernel.debug')), $configs);
$container->setParameter('assetic.debug', $config['debug']);
$container->setParameter('assetic.use_controller', $config['use_controller']);
$container->setParameter('assetic.document_root', $config['document_root']);
$container->setParameter('assetic.default_javascripts_output', $config['default_javascripts_output']);
$container->setParameter('assetic.default_stylesheets_output', $config['default_stylesheets_output']);
if (isset($config['closure'])) {
$container->setParameter('assetic.google_closure_compiler_jar', $config['closure']);
$loader->load('google_closure_compiler.xml');
}
if (isset($config['yui'])) {
$container->setParameter('assetic.yui_jar', $config['yui']);
$loader->load('yui_compressor.xml');
}
if ($container->getParameterBag()->resolveValue($container->getParameterBag()->get('assetic.use_controller'))) {
$loader->load('controller.xml');
$container->setParameter('assetic.twig_extension.class', '%assetic.twig_extension.dynamic.class%');
} else {
$loader->load('asset_writer.xml');
$container->setParameter('assetic.twig_extension.class', '%assetic.twig_extension.static.class%');
}
if ($container->hasParameter('assetic.less.compress')) {
$container->getDefinition('assetic.filter.less')->addMethodCall('setCompress', array('%assetic.less.compress%'));
}
}
示例8: 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);
}
}
示例9: 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));
}
}
示例10: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if (!$this->integrationExtension->isTransactionalAutoGenerateProxy()) {
// Transactional system or auto generate proxy is disabled
return;
}
$transactionalId = $this->integrationExtension->getTransactionalService();
// Validate transactional service
$transactionalDefinition = $container->getDefinition($transactionalId);
$class = $transactionalDefinition->getClass();
try {
$class = $container->getParameterBag()->resolveValue($class);
$refClass = new \ReflectionClass($class);
$requiredInterface = 'FivePercent\\Component\\Transactional\\TransactionalInterface';
if (!$refClass->implementsInterface($requiredInterface)) {
throw new \RuntimeException(sprintf('The transactional service with class "%s" should implement %s.', $class, $requiredInterface));
}
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('The transactional service with id "%s" is invalid.', $transactionalId), 0, $e);
}
// Get all services
$serviceIds = $container->getServiceIds();
$directory = $container->getParameter('kernel.cache_dir') . '/transactional';
foreach ($serviceIds as $serviceId) {
if ($container->hasAlias($serviceId)) {
// Not check in alias.
continue;
}
$serviceDefinition = $container->getDefinition($serviceId);
if ($serviceDefinition->isAbstract()) {
// Not check in abstract service.
continue;
}
$class = $serviceDefinition->getClass();
$class = $container->getParameterBag()->resolveValue($class);
if (!$class) {
continue;
}
try {
$proxyCodeGenerator = new ProxyFileGenerator($directory, $class);
} catch (\ReflectionException $e) {
$container->getCompiler()->addLogMessage(sprintf('%s Error with create proxy code generator for class "%s". Maybe class not found?', get_class($this), $class));
continue;
}
if ($proxyCodeGenerator->needGenerate()) {
// Generate proxy file
$filePath = $proxyCodeGenerator->generate();
$serviceDefinition->setClass($proxyCodeGenerator->getProxyClassName());
// Add "__setTransactional" method call for set transactional layer
$methodCalls = $serviceDefinition->getMethodCalls();
array_unshift($methodCalls, ['___setTransactional', [new Reference($transactionalId)]]);
$serviceDefinition->setMethodCalls($methodCalls);
// Add resource for control cache
$container->addResource(new FileResource($filePath));
$realClassReflection = new \ReflectionClass($class);
$container->addResource(new FileResource($realClassReflection->getFileName()));
}
}
}
示例11: testDefaultConfiguration
public function testDefaultConfiguration()
{
// An extension is only loaded in the container if a configuration is provided for it.
// Then, we need to explicitely load it.
$this->container->loadFromExtension($this->extension->getAlias());
$this->container->compile();
$this->assertTrue($this->container->getParameterBag()->has('gg_team_breadcrumb'));
}
示例12: loadInternal
/** {@inheritdoc} */
protected function loadInternal(array $mergedConfig, ContainerBuilder $container)
{
$container->getParameterBag()->set('basster_legacy_bridge.legacy_path', $mergedConfig['legacy_path']);
$container->getParameterBag()->set('basster_legacy_bridge.prepend_script', $mergedConfig['prepend_script']);
$container->getParameterBag()->set('basster_legacy_bridge.append_script', $mergedConfig['append_script']);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
}
示例13: process
public function process(ContainerBuilder $container)
{
if ($container->hasDefinition('assetic.filter.yui_css') && !$container->getParameterBag()->resolveValue($container->getParameter('assetic.filter.yui_css.jar'))) {
throw new \RuntimeException('The "assetic.filters.yui_css" configuration requires a "jar" value.');
}
if ($container->hasDefinition('assetic.filter.yui_js') && !$container->getParameterBag()->resolveValue($container->getParameter('assetic.filter.yui_js.jar'))) {
throw new \RuntimeException('The "assetic.filters.yui_js" configuration requires a "jar" value.');
}
}
示例14: testLoad
public function testLoad()
{
$this->skrzAutowiringExtension->load(["autowiring" => ["ignored_services" => [1], "preferred_services" => [2], "autoscan_psr4" => [3]]], $this->containerBuilder);
$parameterBag = $this->containerBuilder->getParameterBag();
$this->assertSame([1], $parameterBag->get("autowiring.ignored_services"));
$this->assertSame([2], $parameterBag->get("autowiring.preferred_services"));
$this->assertSame([3], $parameterBag->get("autowiring.autoscan_psr4"));
$this->assertSame(["@Component", "@Controller", "@Repository", "@Service"], $parameterBag->get("autowiring.fast_annotation_checks"));
}
示例15: registerToContainer
/**
* Register the sections configuration as service-container parameters
* and a RequestMatcher service.
*
* The following pattern is used, where '{service-prefix}' is the value of $servicePrefix
* and '{section-name}' the name the processed section (repeated for each registered section).
*
* Like:
*
* '{service-prefix}.{section-name}.host' => 'example.com'
* '{service-prefix}.{section-name}.host_pattern' => '^example\.com$'
* '{service-prefix}.{section-name}.prefix' => '/'
* '{service-prefix}.{section-name}.path' => '^/(?!(backend|api)/)'
* '{service-prefix}.{section-name}.request_matcher' => {RequestMatcher service}
*
* Note: when the host is empty the 'host_pattern' is '.*' (as the route requirement)
* cannot be empty. The host pattern for the request_matcher is null then.
*
* @param ContainerBuilder $container
*/
public function registerToContainer(ContainerBuilder $container)
{
foreach ($this->resolveSections($this->sections) as $name => $config) {
$servicePrefix = rtrim($config['service_prefix'], '.') . '.';
$container->setParameter($servicePrefix . $name . '.host', (string) $config['host']);
$container->setParameter($servicePrefix . $name . '.host_pattern', (string) ($config['host_pattern'] ?: '.*'));
$container->setParameter($servicePrefix . $name . '.prefix', $config['prefix']);
$container->setParameter($servicePrefix . $name . '.path', $config['path']);
$container->register($servicePrefix . $name . '.request_matcher', RequestMatcher::class)->setArguments([$container->getParameterBag()->escapeValue($config['path']), $container->getParameterBag()->escapeValue($config['host_pattern'])]);
}
}