/** * {@inheritdoc} */ public function parse(string $payload) : array { try { return YosymfonyToml::parse($payload); } catch (TomlParseException $exception) { throw new ParseException(['message' => 'Unable to parse the TOML string.', 'line' => $exception->getParsedLine()]); } }
/** * {@inheritdoc} * * @throws \RuntimeException If the `yosymfonytoml` library is not installed or the toml file is not valid */ public function load() { try { $this->content = Toml::parse($this->entity); } catch (\Exception $e) { throw new \RuntimeException(sprintf("'%s' failed to load with the error '%s'", $this->entity, $e)); } return $this; }
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); }
public function createFromFile($configFile) { $configPath = PathFactory::instance()->create($configFile); $loadConfigFile = $configPath->normalize(); if (file_exists($loadConfigFile) === false) { throw new ConfigFileNotFoundException($loadConfigFile); } $configDirectory = $configPath->parent(); $configValues = Toml::parse($loadConfigFile); $result = $this->flattener->flatten($configValues); foreach ($result as $key => $fixturePath) { $fixtureRelativePath = RelativePath::fromString($fixturePath); $fixturePath = $configDirectory->join($fixtureRelativePath); $result[$key] = (string) $fixturePath->normalize(); } return new FixtureContainer($result); }
public function testStringEmpty() { $array = Toml::parse(''); }
/** * Loads an article by its file name. * * @param string $name The file name. * @return Article The parsed article. */ private function getArticleFromFile(string $name) : Article { // Check for a cache hit first. if ($this->cache->has($name)) { return $this->cache->get($name); } $path = $this->path . '/' . $name; if (!is_file($path)) { throw new \Exception('The article "' . $path . '" does not exist.'); } // This is blocking, but hopefully it only happens once. $data = file_get_contents($path); // If a TOML front matter block is given, parse the contained metadata. if (strpos($data, '+++') === 0) { $data = substr($data, 3); $pos = strpos($data, '+++'); $metatdata = substr($data, 0, $pos); $contents = ltrim(substr($data, $pos + 3)); } else { $contents = $data; } // Parse header into an array of options. $metatdata = Toml::parse($metatdata); // Parse the slug. $slug = str_replace('-', '/', substr($name, 0, 11)) . substr($name, 11, -3); $article = new Article($metatdata, $contents, $slug); $this->cache->set($name, $article); return $article; }