nijens /
openapi-bundle
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | * This file is part of the OpenapiBundle package. |
||
| 7 | * |
||
| 8 | * (c) Niels Nijens <[email protected]> |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Nijens\OpenapiBundle\Json\Loader; |
||
| 15 | |||
| 16 | use Nijens\OpenapiBundle\Json\Exception\LoaderLoadException; |
||
| 17 | use stdClass; |
||
| 18 | use Symfony\Component\Yaml\Exception\ParseException; |
||
| 19 | use Symfony\Component\Yaml\Yaml; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Loads JSON schema files in YAML format. |
||
| 23 | * |
||
| 24 | * @author Niels Nijens <[email protected]> |
||
| 25 | */ |
||
| 26 | final class YamlLoader implements LoaderInterface |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | public function supports(string $file): bool |
||
| 32 | { |
||
| 33 | return in_array(pathinfo($file, PATHINFO_EXTENSION), ['yaml', 'yml']); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * {@inheritdoc} |
||
| 38 | */ |
||
| 39 | public function load(string $file): stdClass |
||
| 40 | { |
||
| 41 | try { |
||
| 42 | return Yaml::parseFile($file, Yaml::PARSE_OBJECT_FOR_MAP | Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 43 | } catch (ParseException $exception) { |
||
| 44 | throw new LoaderLoadException($exception->getMessage(), 0, $exception); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 |