for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Serhii Nekhaienko <[email protected]>
* @license GPL
* @copyright Serhii Nekhaienko © 2018
* @version 4.0.0
* @project browser-detector
*/
namespace EndorphinStudio\Detector;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
* Class for loading data from yml files
* @pattern Singleton
* @package EndorphinStudio\Detector
class YamlLoader
{
private $parameters = [];
* @throws ParseException
public function __construct()
$this->load();
}
* Load data from yml files into associative array
private function load(): void
$parameters = [];
$parser = new Parser();
$dataDir = \dirname(__DIR__) . '/var/data/';
foreach (new \DirectoryIterator($dataDir) as $file) {
if ($file->getExtension() === '.yml') {
$data = $parser->parseFile($file->getRealPath());
$parameters = \array_merge($parameters, $data);
$this->parameters = $parameters;
* Return list of params (key must be os, device, .etc)
* @param string $name
* @return array
* @throws DetectorException
public function getParameter(string $name): array
if (!array_key_exists($name, $this->parameters)) {
throw new DetectorException(sprintf('% not exist in data' . $name), 1);
return $this->parameters[$name];