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