コード例 #1
0
 /**
  * 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
0
 /**
  * @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
0
 /**
  * {@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
0
 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
0
 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();
     }
 }