for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Chrisyue\PhpM3u8\Parser;
use Chrisyue\PhpM3u8\Line\Line;
use Chrisyue\PhpM3u8\Rule\ParsingRules;
use Chrisyue\PhpM3u8\Line\Lines;
use Chrisyue\PhpM3u8\Parser\DataBuilder;
use Chrisyue\PhpM3u8\Definition\TagDefinitions;
use Chrisyue\PhpM3u8\Config;
class Parser
{
private $tagDefinitions;
private $valueParsers;
private $dataBuilder;
public function __construct(TagDefinitions $tagDefinitions, Config $valueParsers, DataBuilder $dataBuilder)
$this->tagDefinitions = $tagDefinitions;
$this->valueParsers = $valueParsers;
$this->dataBuilder = $dataBuilder;
}
public function parse(Lines $lines)
foreach ($lines as $line) {
if ($line->isType(Line::TYPE_URI)) {
$this->dataBuilder->addUri($line->getValue());
continue;
$tag = $line->getTag();
$definition = $this->tagDefinitions->findOneByTag($tag);
if (null === $definition) {
$valueType = $definition->getValueType();
$value = $line->getValue();
$parse = $this->valueParsers->get($valueType);
if (is_callable($parse)) {
$value = 'attribute-list' === $valueType ? $parse($value, $definition->getAttributeTypes()) : $parse($value);
$this->dataBuilder->addTag($definition, $value);
return $this->dataBuilder->getResult();