for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Chrisyue\PhpM3u8\M3u8\Transformer;
abstract class AbstractAttributeList implements TransformerInterface
{
public function transform($origin)
preg_match_all('/(?<=^|,)[A-Z0-9-]+=("?).+?\1(?=,|$)/', $origin, $matches);
$result = $this->initResult();
$parsed = false;
foreach ($matches[0] as $attr) {
list($name, $value) = explode('=', $attr);
foreach ($this->getTransformers() as $property => $transformer) {
if (null !== $result->$property || $transformer->getName() !== $name) {
continue;
}
$result->$property = $transformer->transform($value);
$parsed = true;
break;
return $parsed ? $result : null;
public function reverse($result)
$attributes = [];
$attributes[$transformer->getName()] = $result->$property;
$keyVals = [];
foreach ($attributes as $name => $attribute) {
$keyVals[] = sprintf('%s=%s', $name, $attribute);
return implode(',', $keyVals);
abstract protected function getTransformers();
abstract protected function initResult();