Пример #1
0
 public function load($resource, $type = null)
 {
     if (false == class_exists('Yosymfony\\Toml\\Toml')) {
         throw new \RuntimeException('Yosymfony\\Toml parser is required to read toml files.');
     }
     if (null === $type) {
         $resource = $this->getLocation($resource);
     }
     $data = Toml::parse($resource);
     $repository = new Repository();
     $repository->load($data ? $data : array());
     return $this->parseImports($repository, $resource);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = null)
 {
     if (null === $type) {
         $resource = $this->getLocation($resource);
         $data = $this->loadFile($resource);
     } else {
         $data = $resource;
     }
     $parsed = $this->parseResource($data);
     $errorMsg = $this->getLastErrorMessage(json_last_error());
     if ($errorMsg) {
         $msg = $type ? sprintf('JSON parse error: %s', $errorMsg) : sprintf('JSON parse error: %s at %s', $errorMsg, $resource);
         throw new \RuntimeException($msg);
     }
     $repository = new Repository();
     $repository->load($parsed ? $parsed : array());
     return $this->parseImports($repository, $resource);
 }
Пример #3
0
 public function load($resource, $type = null)
 {
     if (false == class_exists('Symfony\\Component\\Yaml\\Yaml')) {
         throw new \RuntimeException('Symfony\\Component\\Yaml\\Yaml parser is required to read yaml files.');
     }
     if (null === $type) {
         $resource = $this->getLocation($resource);
     }
     if (is_file($resource)) {
         if (!is_readable($resource)) {
             throw new \RuntimeException(sprintf('Unable to parse "%s" as the file is not readable.', $resource));
         }
         $resource = file_get_contents($resource);
     }
     $data = Yaml::parse($resource);
     $repository = new Repository();
     $repository->load($data ? $data : array());
     return $this->parseImports($repository, $resource);
 }
Пример #4
0
 /**
  * @param Repository $repository
  */
 private function checkDefinitions(Repository $repository)
 {
     $intersection = $repository->intersection($this->globalRepository);
     $intersection->validateWith(new ConfigDefinition());
 }
Пример #5
0
 public function testRepositoryIntersection()
 {
     $repositoryA = new Repository();
     $repositoryA['port'] = 25;
     $repositoryA['server'] = 'localhost';
     $repositoryB = new Repository();
     $repositoryB['port'] = 24;
     $repositoryB['server'] = 'mail.yourname.com';
     $repositoryB['secure'] = true;
     $intersection = $repositoryA->intersection($repositoryB);
     $this->assertInstanceOf('Yosymfony\\ConfigLoader\\RepositoryInterface', $intersection);
     $this->assertCount(2, $intersection);
     $this->assertEquals($intersection['port'], 25);
     $this->assertEquals($intersection['server'], 'localhost');
     $this->assertArrayNotHasKey('secure', $intersection);
     $this->assertCount(2, $repositoryA);
 }