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); }
/** * {@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); }
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); }