Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 protected function getTokenResultReplacement($token)
 {
     $matches = array();
     if (!preg_match('/^\\$(.+?)\\/(.+)$/', $token, $matches) || $matches < 3) {
         throw new \InvalidArgumentException(sprintf('IncludeTokenProcessor received invalid input, token expected to have the form "$root/path/to/file"; received "%s"', $token));
     }
     $root = $matches[1];
     if (!isset($this->roots[$root])) {
         throw new \InvalidArgumentException(sprintf('IncludeTokenProcessor encountered unknown $root key "%s"', $root));
     }
     return $this->loader->load(sprintf('%s/%s/%s', $this->roots[$root], ResourceLocations::RESOURCES_DIRECTORY, $matches[2]));
 }
Exemplo n.º 2
0
 /**
  * Load the given configuration file, and its relative environment-specific file (see class docs), and merge the
  * contents with the existing configuration.
  *
  * @param string|array $config The base filename to load, or an array of values to merge in directly.
  * @param null|string|array $rootKey The root key to merge the values to, will be created if it does not exist. If
  *   omitted, the values will be merged to the root of the existing config.
  * @param boolean $preferExisting Whether to prefer values from the passed-in config over the existing values (the
  *   default) or to prefer existing values over passed-in values (if this argument is true).
  *
  * @return self
  *
  * @throws \InvalidArgumentException
  */
 public function merge($config, $rootKey = null, $preferExisting = false)
 {
     LoggerRegistry::debug('Configuration::merge({config}, {rootKey}, {preferExisting})', array('config' => TypeUtilities::describe($config), 'rootKey' => TypeUtilities::describe($rootKey), 'preferExisting' => TypeUtilities::describe($preferExisting)));
     // Load using the container's ConfigLoader.
     $data = $this->loader->load($config);
     // Push the data down the hierarchy to the specified root key.
     $rootKey = $this->normaliseKey($rootKey);
     while (!empty($rootKey)) {
         $k = array_pop($rootKey);
         $data = array($k => $data);
     }
     // Combine the arrays depending on the $preferExisting flag.
     $this->data = $preferExisting ? ArrayUtilities::combine($data, $this->data) : ArrayUtilities::combine($this->data, $data);
     return $this;
 }
Exemplo n.º 3
0
 public function testNoDefaultLoadersConfig()
 {
     $loaderNoDefaults = new ConfigLoader(new SitegearEnvironmentInfoProvider('testing'), false);
     $this->assertEmpty($loaderNoDefaults->load($this->fixtures() . 'test-no-env-specific.json'));
     $this->assertEmpty($loaderNoDefaults->load($this->fixtures() . 'test-with-env-specific.json'));
 }