Пример #1
0
 /**
  * {@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()]);
     }
 }
Пример #2
0
 /**
  * {@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;
 }
Пример #3
0
 /**
  * Loads the Toml File
  *
  * @param string $file
  *
  * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
  * @return array
  */
 protected function loadFile($file)
 {
     if (!stream_is_local($file)) {
         throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
     }
     if (!file_exists($file)) {
         throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
     }
     return Toml::Parse($file);
 }
Пример #4
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);
 }
Пример #5
0
 public function __construct($override_path = null)
 {
     $env_path = getenv('KOSH_CONFIG');
     if ($env_path !== false) {
         $override_path = $env_path;
     }
     $this->mConfigFile = new ConfigFile($override_path);
     if ($this->mConfigFile->isValid()) {
         if ($this->mConfigFile->isURL()) {
             $tmpConfig = file_get_contents($this->mConfigFile->getFilename());
             $this->mData = Toml::Parse($tmpConfig);
         } else {
             $this->mData = Toml::Parse($this->mConfigFile->getFilename());
         }
     }
 }
Пример #6
0
 /**
  * parse toml
  *
  * @param  string  $file
  * @return array
  */
 protected function parseToml($file)
 {
     $cacheDir = sprintf('%s/framework/cache/tomlara/', storage_path());
     $cacheFile = $cacheDir . basename($file) . '.cache.php';
     if (@filemtime($cacheFile) < filemtime($file)) {
         $content = null === ($toml = Toml::Parse($file)) ? [] : $toml;
         array_walk_recursive($content, [$this, 'parseFunc']);
         if (!file_exists($cacheDir)) {
             @mkdir($cacheDir, 0644);
         }
         file_put_contents($cacheFile, '<?php' . PHP_EOL . PHP_EOL . 'return ' . var_export($content, true) . ';');
     } else {
         $content = (require $cacheFile);
     }
     return $content;
 }
 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);
 }
Пример #8
0
 public function testArrayOfTables()
 {
     $tb = new TomlBuilder();
     $result = $tb->addArrayTables('fruit')->addValue('name', 'apple')->addArrayTables('fruit.variety')->addValue('name', 'red delicious')->addArrayTables('fruit.variety')->addValue('name', 'granny smith')->addArrayTables('fruit')->addValue('name', 'banana')->addArrayTables('fruit.variety')->addValue('name', 'platain')->getTomlString();
     $this->assertNotNull(Toml::Parse($result));
 }
Пример #9
0
 public function testStringEmpty()
 {
     $array = Toml::parse('');
 }
Пример #10
0
 /**
  * Loads in the given file and parses it.
  *
  * @param string $file File to load
  *
  * @return array The parsed file data
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function loadFile($file = null)
 {
     $this->file = $file;
     $contents = $this->parseVars(Utils::getContent($file));
     return TomlLib::Parse($contents);
 }
Пример #11
0
 /**
  * Parse toml files.
  *
  * @param  array  $paths
  * @return array
  */
 private function parseToml(array $paths)
 {
     $toml = [];
     foreach ($paths as $path) {
         $toml[basename($path, '.toml')] = Toml::Parse($path);
     }
     return $toml;
 }
Пример #12
0
 /**
  * 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;
 }