本文整理匯總了PHP中Symfony\Component\DependencyInjection\ContainerInterface::getParameterBag方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContainerInterface::getParameterBag方法的具體用法?PHP ContainerInterface::getParameterBag怎麽用?PHP ContainerInterface::getParameterBag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::getParameterBag方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: direct
/**
* Direct helper implementation:
* - return service if exists
* - else return parameter if exists
*
* @param string $name
*/
public function direct($name)
{
if ($this->_container->has($name)) {
return $this->_container->getService($name);
} else {
if ($this->_container->getParameterBag()->has($name)) {
return $this->_container->getParameter($name);
}
}
return null;
}
示例2: resolveValue
/**
* @param ContainerInterface $container
* @param mixed $value
*
* @return mixed
*/
private function resolveValue(ContainerInterface $container, $value)
{
if ($container instanceof Container) {
// Use the container methods if available
return $container->getParameterBag()->resolveValue($value);
}
// Fallback
if (is_array($value)) {
foreach ($value as $key => $val) {
$value[$key] = $this->resolveValue($container, $val);
}
return $value;
}
if (!is_string($value)) {
return $value;
}
$escapedValue = preg_replace_callback('/%%|%([^%\\s]++)%/', function ($match) use($container, $value) {
// skip %%
if (!isset($match[1])) {
return '%%';
}
$resolved = $container->getParameter($match[1]);
if (is_string($resolved) || is_numeric($resolved)) {
return (string) $resolved;
}
throw new \RuntimeException(sprintf('The container parameter "%s" must be a string or a numeric, but it is of type %s.', $match[1], $value, gettype($resolved)));
}, $value);
return str_replace('%%', '%', $escapedValue);
}
示例3: load
/**
* {@inheritDoc}
*/
public function load($filename)
{
// The aim is not to throw an exception if the file is not found
if (false === file_exists($filename)) {
return array();
}
$yaml = Yaml::parse(file_get_contents($filename));
$config = $this->container->getParameterBag()->resolveValue($yaml);
$processor = new Processor();
$configuration = new ServerConfiguration();
$servers = $processor->processConfiguration($configuration, $config);
$list = array();
foreach ($servers as $name => $s) {
$list[$name] = new Server($s['host'], $s['user'], $s['dir'], $s['password'], $s['port'], $s['options']);
}
return $list;
}
示例4: generateI18nPatterns
public function generateI18nPatterns($routeName, Route $route)
{
$patterns = [];
/** @var \Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag $parameterBag */
$parameterBag = $this->container->getParameterBag();
$locales = $route->getOption('i18n_locales') ?: $this->locales;
$locales = $parameterBag->resolveValue($locales);
foreach ($locales as $locale) {
$i18nPattern = $route->getPath();
// prefix with locale if requested
if (DefaultPatternGenerationStrategy::STRATEGY_PREFIX === $this->strategy || DefaultPatternGenerationStrategy::STRATEGY_PREFIX === $route->getOption('i18n_strategy') || DefaultPatternGenerationStrategy::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) {
$i18nPattern = '/{_locale}' . $i18nPattern;
if (null !== $route->getOption('i18n_prefix')) {
$prefix = $route->getOption('i18n_prefix');
$prefix = $parameterBag->resolveValue($prefix);
$i18nPattern = $prefix . $i18nPattern;
}
}
$patterns[$i18nPattern][] = $locale;
}
return $patterns;
}
示例5: __construct
public function __construct(ContainerInterface $container)
{
$this->session = $container->get('session');
$this->session->start();
$this->em = $container->get('doctrine.orm.entity_manager');
// Load global yml configuration (ex: config.yml)
$this->gParameterBag = $container->getParameterBag();
// If found cache in session load it
if ($this->session->has(self::SESSION_VARS_CACHE)) {
$this->settingCache = $this->session->get(self::SESSION_VARS_CACHE);
}
// If session cache is not valid load from db
if (is_null($this->settingCache)) {
$this->loadSettingFromDb();
}
}