for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Chrisyue\PhpM3u8\Line;
class Line
{
const TYPE_URI = 'uri';
const TYPE_TAG = 'tag';
private $tag;
private $value;
public function __construct($tag = null, $value = null)
if (null === $tag && null === $value) {
throw new \InvalidArgumentException('$tag and $value can not both be null');
}
$this->tag = $tag;
$this->value = $value;
static public function fromString($line)
$line = trim($line);
if (empty($line)) {
return;
if ('#' !== $line[0]) {
return new Line(null, $line);
$line = ltrim($line, '#');
list($tag, $value) = array_pad(explode(':', $line, 2), 2, true);
return new self($tag, $value);
public function getTag()
return $this->tag;
public function getValue()
return $this->value;
public function isType($type)
return $this->getType() === $type;
public function __toString()
if ($this->isType(Line::TYPE_URI)) {
if (true === $this->value) {
return sprintf('#%s', $this->tag);
if (false === $this->value) {
return '';
return sprintf('#%s:%s', $this->tag, $this->value);
private function getType()
if (null !== $this->tag) {
return self::TYPE_TAG;
return self::TYPE_URI;