/**
  * __construct function.
  *
  * @access public
  * @param Container $container
  */
 public function __construct(Container $container)
 {
     // Getting all symfony parameters
     $this->parameters = $container->getParameterBag()->all();
     // Getting all parameters keys
     $this->keys = array_keys($this->parameters);
 }
 /**
  * __construct function.
  *
  * Constructing the discriminator mapping from parameters and entities:
  * - Search parameters starting with "discriminator_map"
  * - Fetching map from entities configuration
  * The Entity disciminator map has priority against parameter map
  *
  * @access public
  * @param Container $container
  */
 public function __construct(Container $container)
 {
     // Getting all symfony parameters
     $parameters = $container->getParameterBag()->all();
     // Getting all parameters keys
     $parametesKeys = array_keys($parameters);
     // Matching parameters with specific key "discriminator_map"
     $matches = preg_grep('/^inheritance_joined_map\\..+/i', $parametesKeys);
     // Looping on matching configurations
     foreach ($matches as $match) {
         // Looping on map name
         foreach ($parameters[$match] as $ename => $parent) {
             // Looping on each map for a specific entity
             foreach ($parent['map'] as $name => $class) {
                 // Adding the map to the mapping
                 $this->mapping[$parent['entity']][$name] = $class;
             }
         }
     }
     // The mapping defined in the entity has priority against parameters
     // Loop on entities in mapping to get the original mapping
     foreach (array_keys($this->mapping) as $entityName) {
         // Loop on map defined in entity
         foreach ($this->getEntityDiscriminatorMap($entityName) as $name => $map) {
             // Adding the map to the mapping
             $this->mapping[$entityName][$name] = $map;
         }
     }
 }
예제 #3
0
 public function getHttpKernel()
 {
     if (!$this->silexKernel) {
         $this->silexKernel = new SilexKernel($this->httpConfig, $this->isDebugMode);
         $this->silexKernel->addControllerInjectedArg($this);
         $this->silexKernel->addExtraParameters($this->container->getParameterBag()->all());
     }
     return $this->silexKernel;
 }
예제 #4
0
 public function filterLoad(AssetInterface $asset)
 {
     $content = $asset->getContent();
     /**
      * Find All Params In %%
      */
     $regex_pattern = '/\\%[a-z0-9A-Z\\._]+\\%/';
     $boolean = preg_match_all($regex_pattern, $content, $matches_out);
     $replaces = array();
     if ($boolean) {
         $matches = array_unique($matches_out[0]);
         foreach ($matches as $match) {
             if ($value = $this->container->getParameterBag()->resolveValue($match)) {
                 $replaces[$match] = $value;
             }
         }
         $content = str_replace(array_keys($replaces), array_values($replaces), $content);
     }
     $asset->setContent($content);
 }
예제 #5
0
 public function generateI18nPatterns($routeName, Route $route)
 {
     $patterns = [];
     /** @var FrozenParameterBag $parameterBag */
     $parameterBag = $this->container->getParameterBag();
     if (empty($this->offices)) {
         $this->offices = $this->container->get('doctrine')->getRepository('OctavaMuiBundle:Office')->getRoutingOffices();
     }
     $translation = null;
     if ($structureId = $route->getDefault(Structure::ROUTING_ID_NAME)) {
         $structureRepository = $this->container->get('doctrine.orm.entity_manager')->getRepository('OctavaStructureBundle:Structure');
         $translation = $structureRepository->getTranslations($structureRepository->getById($structureId));
     }
     foreach (array_keys($this->offices) as $locale) {
         if ($translation !== null && empty($translation[$locale]['state'])) {
             // отключенная страница
             continue;
         }
         $office = $this->offices[$locale];
         $i18nPattern = $route->getPath();
         $paths = $route->getOption('translatable_path');
         if (!empty($paths[$locale])) {
             $i18nPattern = $paths[$locale];
         }
         if ($office->getIncludeLangInUrl()) {
             $i18nPattern = '/{_locale}' . $i18nPattern;
         }
         if (null !== ($prefix = $route->getOption('i18n_prefix'))) {
             $prefix = $parameterBag->resolveValue($prefix);
             $i18nPattern = $prefix . $i18nPattern;
         }
         $host = $office->getHost();
         if (empty($patterns[$i18nPattern][$host])) {
             $patterns[$i18nPattern][$host] = [];
         }
         $patterns[$i18nPattern][$host][] = $locale;
     }
     return $patterns;
 }
예제 #6
0
 public function testGetParameterBag()
 {
     $sc = new Container();
     $this->assertEquals(array(), $sc->getParameterBag()->all(), '->getParameterBag() returns an empty array if no parameter has been defined');
 }
예제 #7
0
 /**
  * @Inject("@Service_container")
  * @param Container $container
  */
 public function setContainer(Container $container)
 {
     $this->parameterBag = $container->getParameterBag();
 }
예제 #8
0
 public function __construct(Container $container, LoggerInterface $logger)
 {
     $this->initConfig($container->getParameterBag()->all());
     $this->logger = $logger;
 }
<?php

use Symfony\Component\DependencyInjection\Container;
require_once __DIR__ . '/bootstrap.php';
$container = new Container();
$container->set('foo', new stdClass());
dump($container->get('foo'));
$container->setParameter('bar', TRUE);
dump($container->getParameterBag()->all());