Nelmio\Alice\Throwable\Exception\Parser\ParseExceptionFactory::createForUnparsableFile PHP Method

createForUnparsableFile() public static method

public static createForUnparsableFile ( string $file, integer $code, Throwable $previous = null ) : UnparsableFileException
$file string
$code integer
$previous Throwable
return UnparsableFileException
    public static function createForUnparsableFile(string $file, int $code = 0, \Throwable $previous = null) : UnparsableFileException
    {
        return new UnparsableFileException(sprintf('Could not parse the file "%s".', $file), $code, $previous);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@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);
     }
 }