ICanBoogie
  • Documentation
  • API Reference
  • HTTP v2.5.0
Namespaces
  • ICanBoogie
    • Exception
    • HTTP
      • Headers
      • Request
      • RequestDispatcher
Classes
  • CacheControl
  • ContentDisposition
  • ContentType
  • Date
  • Header
  • HeaderParameter

Class Header

Base class for header fields.

Classes that extend the class and support attributes must defined them during construct:

<?php

namespace ICanBoogie\HTTP\Headers;

class ContentDisposition extends Header
{
    public function __construct($value=null, array $attributes=[])
    {
        $this->parameters['filename'] = new HeaderParameter('filename');

        parent::__construct($value, $attributes);
    }
}

Magic properties are automatically mapped to parameters. The value of a parameter is accessed through its corresponding property:

<?php

$cd = new ContentDisposition;
$cd->filename = "Statistics.csv";
echo $cd->filename;
// "Statistics.csv"

The instance of the parameter itself is accessed using the header as an array:

<?php

$cd = new ContentDisposition;
$cd['filename']->value = "Statistics.csv";
$cd['filename']->language = "en";

An alias to the ICanBoogie\HTTP\Headers\Header::$value property can be defined by using the VALUE_ALIAS constant. The following code defines type as an alias:

<?php

class ContentDisposition extends Header
{
    const VALUE_ALIAS = 'type';
}
ICanBoogie\HTTP\Headers\Header implements ArrayAccess

Direct known subclasses

ICanBoogie\HTTP\Headers\ContentDisposition, ICanBoogie\HTTP\Headers\ContentType

Abstract
Namespace: ICanBoogie\HTTP\Headers
Located at Headers/Header.php

Methods summary

public static from( string|ICanBoogie\HTTP\Headers\Header $source ) : ICanBoogie\HTTP\Headers\Header

Creates a ICanBoogie\HTTP\Headers\Header instance from the provided source.

Creates a ICanBoogie\HTTP\Headers\Header instance from the provided source.

Parameters

$source

The source to create the instance from. If the source is an instance of ICanBoogie\HTTP\Headers\Header it is returned as is.

Returns

ICanBoogie\HTTP\Headers\Header
protected static parse( string $source ) : array

Parse the provided source and extract its value and parameters.

Parse the provided source and extract its value and parameters.

Parameters

$source
The source to create the instance from.

Returns

array

Throws

InvalidArgumentException

if $source is not a string nor an object implementing __toString().

public offsetExists( string $attribute ) : boolean

Checks if a parameter exists.

Checks if a parameter exists.

Parameters

$attribute

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public offsetUnset( string $attribute )

Sets the value of a parameter to null.

Sets the value of a parameter to null.

Parameters

$attribute

Implementation of

ArrayAccess::offsetUnset()
public offsetSet( string $attribute, mixed $value )

Sets the value of a parameter.

Sets the value of a parameter.

If the value is an instance of ICanBoogie\HTTP\Headers\HeaderParameter then the parameter is replaced, otherwise the value of the current parameter is updated and its language is set to null.

Parameters

$attribute
$value

Throws

ICanBoogie\OffsetNotDefined
in attempt to access a parameter that is not defined.

Implementation of

ArrayAccess::offsetSet()
public offsetGet( string $attribute ) : ICanBoogie\HTTP\Headers\HeaderParameter

Returns a ICanBoogie\HTTP\Headers\HeaderParameter instance.

Returns a ICanBoogie\HTTP\Headers\HeaderParameter instance.

Parameters

$attribute

Returns

ICanBoogie\HTTP\Headers\HeaderParameter

Throws

ICanBoogie\OffsetNotDefined
in attempt to access a parameter that is not defined.

Implementation of

ArrayAccess::offsetGet()
public __construct( string $value = null, array $parameters = [] )

Initializes the $name, ICanBoogie\HTTP\Headers\Header::$value and ICanBoogie\HTTP\Headers\Header::$parameters properties.

Initializes the $name, ICanBoogie\HTTP\Headers\Header::$value and ICanBoogie\HTTP\Headers\Header::$parameters properties.

To enable future extensions, unrecognized parameters are ignored. Supported parameters must be defined by a child class before it calls its parent.

Parameters

$value
$parameters
public __get( string $property ) : mixed

Returns the value of a defined parameter.

Returns the value of a defined parameter.

The method also handles the alias of the ICanBoogie\HTTP\Headers\Header::$value property.

Parameters

$property

Returns

mixed

Throws

ICanBoogie\PropertyNotDefined
in attempt to access a parameter that is not defined.
public __set( string $property, mixed $value )

Sets the value of a supported parameter.

Sets the value of a supported parameter.

The method also handles the alias of the ICanBoogie\HTTP\Headers\Header::$value property.

Parameters

$property
$value

Throws

ICanBoogie\PropertyNotDefined
in attempt to access a parameter that is not defined.
public __unset( string $property )

Unsets the matching parameter.

Unsets the matching parameter.

Parameters

$property

Throws

ICanBoogie\PropertyNotDefined
in attempt to access a parameter that is not defined.
public __toString( void ) : string

Renders the instance's value and parameters into a string.

Renders the instance's value and parameters into a string.

Returns

string

Constants summary

VALUE_ALIAS
null

Properties summary

public $value : string

The value of the header.

The value of the header.


		
protected $parameters : ICanBoogie\HTTP\Headers\HeaderParameter[]

The parameters supported by the header.

The parameters supported by the header.

[]
HTTP v2.5.0 – Check on GitHub – API documentation generated by ApiGen