for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Borobudur-Http package.
*
* (c) Hexacodelabs <http://hexacodelabs.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Borobudur\Http\Header\Content;
use Borobudur\Http\Header\GenericHeader;
use Borobudur\Http\Header\HeaderInterface;
/**
* @author Iqbal Maulana <[email protected]>
* @created 7/20/15
class ContentLengthHeader implements HeaderInterface
{
* @var mixed
private $length;
* Constructor.
* @param mixed $length
public function __construct($length)
GenericHeader::assertHeaderValue(trim($length));
$this->length = trim($length);
}
* Factory create ContentLengthHeader from string representation.
* @param string $headerLine
* @return $this
public static function fromString($headerLine)
list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
GenericHeader::assertHeaderFieldName('Content-Length', $fieldName);
return new static($fieldValue);
* Get header field name.
* @return string
public function getFieldName()
return 'Content-Length';
* Get header field value.
* @return mixed
public function getFieldValue()
return (int) $this->length;
* Cast header to string.
public function __toString()
return sprintf('%s: %s', $this->getFieldName(), $this->getFieldValue());