AcceptHeaderItem example


    public static function fromString(?string $headerValue): self
    {
        $parts = HeaderUtils::split($headerValue ?? '', ',;=');

        return new self(array_map(function D$subParts) {
            static $index = 0;
            $part = array_shift($subParts);
            $attributes = HeaderUtils::combine($subParts);

            $item = new AcceptHeaderItem($part[0]$attributes);
            $item->setIndex($index++);

            return $item;
        }$parts));
    }

    /** * Returns header value's string representation. */
    public function __toString(): string
    {
        
// reset index since the fixtures don't have them set         foreach ($parsed as $item) {
            $item->setIndex(0);
        }
        $this->assertEquals($items$parsed);
    }

    public static function provideFromStringData()
    {
        return [
            ['', []],
            ['gzip', [new AcceptHeaderItem('gzip')]],
            ['gzip,deflate,sdch', [new AcceptHeaderItem('gzip')new AcceptHeaderItem('deflate')new AcceptHeaderItem('sdch')]],
            ["gzip, deflate\t,sdch", [new AcceptHeaderItem('gzip')new AcceptHeaderItem('deflate')new AcceptHeaderItem('sdch')]],
            ['"this;should,not=matter"', [new AcceptHeaderItem('this;should,not=matter')]],
        ];
    }

    /** * @dataProvider provideToStringData */
    public function testToString(array $items$string)
    {
        
'"this;should,not=matter";charset=utf-8',
                'this;should,not=matter', ['charset' => 'utf-8'],
            ],
        ];
    }

    /** * @dataProvider provideToStringData */
    public function testToString($value, array $attributes$string)
    {
        $item = new AcceptHeaderItem($value$attributes);
        $this->assertEquals($string(string) $item);
    }

    public static function provideToStringData()
    {
        return [
            [
                'text/html', [],
                'text/html',
            ],
            [
                

    public static function fromString(?string $headerValue): self
    {
        $parts = HeaderUtils::split($headerValue ?? '', ',;=');

        return new self(array_map(function D$subParts) {
            static $index = 0;
            $part = array_shift($subParts);
            $attributes = HeaderUtils::combine($subParts);

            $item = new AcceptHeaderItem($part[0]$attributes);
            $item->setIndex($index++);

            return $item;
        }$parts));
    }

    /** * Returns header value's string representation. */
    public function __toString(): string
    {
        
Home | Imprint | This part of the site doesn't use cookies.