/** * Looks for the first suitable parser to parse the file. * * {@inheritdoc} */ public function parse(string $file) : array { foreach ($this->parsers as $parser) { if ($parser->canParse($file)) { return $parser->parse($file); } } throw ParseExceptionFactory::createForParserNoFoundForFile($file); }
/** * {@inheritDoc} * * @param string $file Local YAML file * * @throws ParseException */ public function parse(string $file) : array { if (false === file_exists($file)) { throw InvalidArgumentExceptionFactory::createForFileCouldNotBeFound($file); } try { $data = $this->yamlParser->parse(file_get_contents($file)); // $data is null only if the YAML file was empty; otherwise an exception is thrown return null === $data ? [] : $data; } catch (\Exception $exception) { if ($exception instanceof SymfonyParseException) { throw ParseExceptionFactory::createForInvalidYaml($file, 0, $exception); } throw ParseExceptionFactory::createForUnparsableFile($file, 0, $exception); } }