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 11declare(strict_types=1); 12 13namespace DeviceDetector\Yaml; 14 15use Exception; 16 17/** 18 * Class Pecl 19 * 20 * Parses a YAML file with LibYAML library 21 * @see http://php.net/manual/en/function.yaml-parse-file.php 22 */ 23class Pecl implements ParserInterface 24{ 25 /** 26 * Parses the file with the given filename using PECL and returns the converted content 27 28 * @param string $file The path to the YAML file to be parsed 29 * 30 * @return mixed The YAML converted to a PHP value or FALSE on failure 31 * 32 * @throws Exception If the YAML extension is not installed 33 */ 34 public function parseFile(string $file) 35 { 36 if (false === \function_exists('yaml_parse_file')) { 37 throw new Exception('Pecl YAML extension is not installed'); 38 } 39 40 return \yaml_parse_file($file); 41 } 42} 43