Pecl.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Device Detector - The Universal Device Detection library for parsing User Agents |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * |
| 8 | * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later |
| 9 | */ |
| 10 | declare (strict_types=1); |
| 11 | namespace IAWPSCOPED\DeviceDetector\Yaml; |
| 12 | |
| 13 | use Exception; |
| 14 | /** |
| 15 | * Class Pecl |
| 16 | * |
| 17 | * Parses a YAML file with LibYAML library |
| 18 | * @see http://php.net/manual/en/function.yaml-parse-file.php |
| 19 | * @internal |
| 20 | */ |
| 21 | class Pecl implements ParserInterface |
| 22 | { |
| 23 | /** |
| 24 | * Parses the file with the given filename using PECL and returns the converted content |
| 25 | * @param string $file The path to the YAML file to be parsed |
| 26 | * |
| 27 | * @return mixed The YAML converted to a PHP value or FALSE on failure |
| 28 | * |
| 29 | * @throws Exception If the YAML extension is not installed |
| 30 | */ |
| 31 | public function parseFile(string $file) |
| 32 | { |
| 33 | if (!\function_exists('yaml_parse_file')) { |
| 34 | throw new Exception('Pecl YAML extension is not installed'); |
| 35 | } |
| 36 | return \yaml_parse_file($file); |
| 37 | } |
| 38 | } |
| 39 |