1<?php
2/**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link      http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license   http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10namespace Zend\Http\Header;
11
12/**
13 * @throws Exception\InvalidArgumentException
14 * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41
15 */
16class TransferEncoding implements HeaderInterface
17{
18    /**
19     * @var string
20    */
21    protected $value;
22
23    public static function fromString($headerLine)
24    {
25        list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
26
27        // check to ensure proper header type for this factory
28        if (strtolower($name) !== 'transfer-encoding') {
29            throw new Exception\InvalidArgumentException(
30                'Invalid header line for Transfer-Encoding string: "' . $name . '"'
31            );
32        }
33
34        // @todo implementation details
35        $header = new static($value);
36
37        return $header;
38    }
39
40    public function __construct($value = null)
41    {
42        if ($value) {
43            HeaderValue::assertValid($value);
44            $this->value = $value;
45        }
46    }
47
48    public function getFieldName()
49    {
50        return 'Transfer-Encoding';
51    }
52
53    public function getFieldValue()
54    {
55        return $this->value;
56    }
57
58    public function toString()
59    {
60        return 'Transfer-Encoding: ' . $this->getFieldValue();
61    }
62}
63