ICanBoogie/HTTP v2.6.0
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • Exception
    • HTTP
      • Headers
      • Request
      • RequestDispatcher

Classes

  • CallableDispatcher
  • DispatcherProvider
  • File
  • FileInfo
  • FileList
  • FileResponse
  • Headers
  • ProvideDispatcher
  • RedirectResponse
  • Request
  • RequestDispatcher
  • RequestOptionsMapper
  • RequestRange
  • Response
  • Status
  • WeightedDispatcher

Interfaces

  • Dispatcher
  • Exception
  • FileOptions
  • RequestMethods
  • RequestOptions
  • ResponseStatus
  • SecurityError

Exceptions

  • AuthenticationRequired
  • ClientError
  • DispatcherNotDefined
  • DispatcherProviderNotDefined
  • ForceRedirect
  • MethodNotSupported
  • NotFound
  • PermissionRequired
  • ServerError
  • ServiceUnavailable
  • StatusCodeNotValid

Functions

  • dispatch
  • get_dispatcher
  • get_initial_request

Class Request

An HTTP request.

<?php

use ICanBoogie\HTTP\Request;

# Creating the main request

$request = Request::from($_SERVER);

# Creating a request from scratch, with the current environment.

$request = Request::from([

    Request::OPTION_URI => '/path/to/my/page.html?page=2',
    Request::OPTION_USER_AGENT => 'Mozilla'
    Request::OPTION_IS_GET => true,
    Request::OPTION_IS_XHR => true,
    Request::OPTION_IS_LOCAL => true

], $_SERVER);
ICanBoogie\HTTP\Request implements ArrayAccess, IteratorAggregate, ICanBoogie\HTTP\RequestMethods, ICanBoogie\HTTP\RequestOptions uses ICanBoogie\Accessor\AccessorTrait (not available)
Namespace: ICanBoogie\HTTP
See: http://en.wikipedia.org/wiki/Uniform_resource_locator
Located at Request.php

Methods summary

public static ICanBoogie\HTTP\Request
# get_current_request( )

Returns the current request.

Returns the current request.

Returns

ICanBoogie\HTTP\Request
protected
# get_files( )
public static ICanBoogie\HTTP\Request
# from( array $properties = null, array $env = [] )

A request may be created from the $_SERVER super global array. In that case $_SERVER is used as environment the request is created with the following properties:

A request may be created from the $_SERVER super global array. In that case $_SERVER is used as environment the request is created with the following properties:

  • ICanBoogie\HTTP\Request::$cookie: a reference to the $_COOKIE super global array.
  • ICanBoogie\HTTP\Request::$path_params: initialized to an empty array.
  • ICanBoogie\HTTP\Request::$query_params: a reference to the $_GET super global array.
  • ICanBoogie\HTTP\Request::$request_params: a reference to the $_POST super global array.
  • ICanBoogie\HTTP\Request::$files: a reference to the $_FILES super global array.

A request may also be created from an array of properties, in which case most of them are mapped to the $env constructor param. For instance, is_xhr set the HTTP_X_REQUESTED_WITH environment property to 'XMLHttpRequest'. In fact, only the following options are preserved:

  • Request::OPTION_PATH_PARAMS
  • Request::OPTION_QUERY_PARAMS
  • Request::OPTION_REQUEST_PARAMS
  • Request::OPTION_FILES: The files associated with the request.
  • Request::OPTION_HEADERS: The header fields of the request. If specified, the headers available in the environment are ignored.

Parameters

$properties
Properties of the request.
$env
Environment, usually the $_SERVER array.

Returns

ICanBoogie\HTTP\Request

Throws

InvalidArgumentException
in attempt to use an unsupported option.
protected static ICanBoogie\HTTP\Request
# from_server( )

Creates an instance from the $_SERVER array.

Creates an instance from the $_SERVER array.

Returns

ICanBoogie\HTTP\Request
protected static ICanBoogie\HTTP\Request
# from_uri( string $uri, array $env )

Creates an instance from an URI.

Creates an instance from an URI.

Parameters

$uri
$env

Returns

ICanBoogie\HTTP\Request
protected static ICanBoogie\HTTP\Request
# from_options( array $options, array $env )

Creates an instance from an array of properties.

Creates an instance from an array of properties.

Parameters

$options
$env

Returns

ICanBoogie\HTTP\Request
protected static ICanBoogie\HTTP\RequestOptionsMapper
# get_options_mapper( )

Returns

ICanBoogie\HTTP\RequestOptionsMapper
protected
# __construct( array $properties, array $env = [] )

Initialize the properties ICanBoogie\HTTP\Request::$env, ICanBoogie\HTTP\Request::$headers and ICanBoogie\HTTP\Request::$context.

Initialize the properties ICanBoogie\HTTP\Request::$env, ICanBoogie\HTTP\Request::$headers and ICanBoogie\HTTP\Request::$context.

If the ICanBoogie\HTTP\Request::$params property is null it is set with an union of ICanBoogie\HTTP\Request::$path_params, ICanBoogie\HTTP\Request::$request_params and ICanBoogie\HTTP\Request::$query_params.

Parameters

$properties
Initial properties.
$env
Environment of the request, usually the $_SERVER super global.

Throws

ICanBoogie\HTTP\MethodNotSupported
when the request method is not supported.
public
# __clone( )

Clone ICanBoogie\HTTP\Request::$headers and ICanBoogie\HTTP\Request::$context, and unset ICanBoogie\HTTP\Request::$params.

Clone ICanBoogie\HTTP\Request::$headers and ICanBoogie\HTTP\Request::$context, and unset ICanBoogie\HTTP\Request::$params.

public ICanBoogie\HTTP\Response
# __invoke( )

Alias for ICanBoogie\HTTP\Request::send().

Alias for ICanBoogie\HTTP\Request::send().

Returns

ICanBoogie\HTTP\Response
The response to the request.
public ICanBoogie\HTTP\Response
# send( string|null $method = null, array $params = null )

Dispatch the request.

Dispatch the request.

The ICanBoogie\HTTP\Request::$parent property is used for request chaining.

Note: If an exception is thrown during dispatch ICanBoogie\HTTP\Request::$current_request is not updated!

Note: If the request is changed because of the $method or $params parameters, it is the changed instance that is dispatched, not the actual instance.

Parameters

$method
Use this parameter to change the request method.
$params

Use this parameter to change the ICanBoogie\HTTP\Request::$request_params property of the request.

Returns

ICanBoogie\HTTP\Response
The response to the request.

Throws

Exception
re-throws exception raised during dispatch.
protected ICanBoogie\HTTP\Response
# dispatch( )

Dispatches the request using the dispatch() helper.

Dispatches the request using the dispatch() helper.

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Request
# with( array $options )

Returns a new instance with the specified changed properties.

Returns a new instance with the specified changed properties.

Parameters

$options

Returns

ICanBoogie\HTTP\Request

Throws

InvalidArgumentException
protected ICanBoogie\HTTP\Request
# adapt( string $method, array $params = null )

Adapts the request to the specified method and params.

Adapts the request to the specified method and params.

Parameters

$method
The method.
$params
The params.

Returns

ICanBoogie\HTTP\Request

The same instance is returned if the method is the same and the params are null. Otherwise a changed request is returned.

public mixed
# __call( $method, $arguments )

Overrides the method to provide a virtual method for each request method.

Overrides the method to provide a virtual method for each request method.

Example:

<?php

Request::from('/api/core/aloha')->get();

Parameters

$method
$arguments

Returns

mixed
public boolean
# offsetExists( string $param )

Checks if the specified param exists in the request's params.

Checks if the specified param exists in the request's params.

Parameters

$param
The name of the parameter.

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed|null
# offsetGet( string $param )

Get the specified param from the request's params.

Get the specified param from the request's params.

Parameters

$param
The name of the parameter.

Returns

mixed|null
The value of the parameter, or null if the parameter does not exists.

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( string $param, mixed $value )

Set the specified param to the specified value.

Set the specified param to the specified value.

Parameters

$param
The name of the parameter.
$value
The value of the parameter.

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( mixed $param )

Remove the specified param from the request's parameters.

Remove the specified param from the request's parameters.

Parameters

$param

Implementation of

ArrayAccess::offsetUnset()
public ArrayIterator
# getIterator( )

Returns an array iterator for the params.

Returns an array iterator for the params.

Returns

ArrayIterator

Implementation of

IteratorAggregate::getIterator()
protected ICanBoogie\HTTP\Request
# get_parent( )

Returns the parent request.

Returns the parent request.

Returns

ICanBoogie\HTTP\Request
protected ICanBoogie\HTTP\Request\Context
# get_context( )

Returns the request's context.

Returns the request's context.

Returns

ICanBoogie\HTTP\Request\Context
protected ICanBoogie\HTTP\Headers\CacheControl
# get_cache_control( )

Returns the Cache-Control header.

Returns the Cache-Control header.

Returns

ICanBoogie\HTTP\Headers\CacheControl
protected string
# get_script_name( )

Returns the script name.

Returns the script name.

The setter is volatile, the value is returned from the ENV key SCRIPT_NAME.

Returns

string
protected string
# get_method( )

Returns the request method.

Returns the request method.

This is the getter for the method magic property.

The method is retrieved from ICanBoogie\HTTP\Request::$env, if the key REQUEST_METHOD is not defined, the method defaults to ICanBoogie\HTTP\RequestMethods::METHOD_GET.

Returns

string
protected string|null
# get_query_string( )

Returns the query string of the request.

Returns the query string of the request.

The value is obtained from the QUERY_STRING key of the ICanBoogie\HTTP\Request::$env array.

Returns

string|null
protected integer|null
# get_content_length( )

Returns the content length of the request.

Returns the content length of the request.

The value is obtained from the CONTENT_LENGTH key of the ICanBoogie\HTTP\Request::$env array.

Returns

integer|null
protected string|null
# get_referer( )

Returns the referer of the request.

Returns the referer of the request.

The value is obtained from the HTTP_REFERER key of the ICanBoogie\HTTP\Request::$env array.

Returns

string|null
protected string|null
# get_user_agent( )

Returns the user agent of the request.

Returns the user agent of the request.

The value is obtained from the HTTP_USER_AGENT key of the ICanBoogie\HTTP\Request::$env array.

Returns

string|null
protected boolean
# get_is_delete( )

Checks if the request method is DELETE.

Checks if the request method is DELETE.

Returns

boolean
protected boolean
# get_is_get( )

Checks if the request method is GET.

Checks if the request method is GET.

Returns

boolean
protected boolean
# get_is_head( )

Checks if the request method is HEAD.

Checks if the request method is HEAD.

Returns

boolean
protected boolean
# get_is_options( )

Checks if the request method is OPTIONS.

Checks if the request method is OPTIONS.

Returns

boolean
protected boolean
# get_is_patch( )

Checks if the request method is PATCH.

Checks if the request method is PATCH.

Returns

boolean
protected boolean
# get_is_post( )

Checks if the request method is POST.

Checks if the request method is POST.

Returns

boolean
protected boolean
# get_is_put( )

Checks if the request method is PUT.

Checks if the request method is PUT.

Returns

boolean
protected boolean
# get_is_trace( )

Checks if the request method is TRACE.

Checks if the request method is TRACE.

Returns

boolean
protected boolean
# get_is_xhr( )

Checks if the request is a XMLHTTPRequest.

Checks if the request is a XMLHTTPRequest.

Returns

boolean
protected boolean
# get_is_local( )

Checks if the request is local.

Checks if the request is local.

Returns

boolean
protected string
# get_ip( )

Returns the remote IP of the request.

Returns the remote IP of the request.

If defined, the HTTP_X_FORWARDED_FOR header is used to retrieve the original IP.

If the REMOTE_ADDR header is empty the request is considered local thus ::1 is returned.

Returns

string

See

http://en.wikipedia.org/wiki/X-Forwarded-For
protected
# get_authorization( )
protected string
# get_uri( )

Returns the REQUEST_URI environment key.

Returns the REQUEST_URI environment key.

If the REQUEST_URI key is not defined by the environment, the value is fetched from the $_SERVER array. If the key is not defined in the $_SERVER array null is returned.

Returns

string
protected integer
# get_port( )

Returns the port of the request.

Returns the port of the request.

Returns

integer
protected string
# get_path( )

Returns the path of the request, that is the REQUEST_URI without the query string.

Returns the path of the request, that is the REQUEST_URI without the query string.

Returns

string
protected string
# get_normalized_path( )

Returns the $path property normalized using the \ICanBoogie\normalize_url_path() function.

Returns the $path property normalized using the \ICanBoogie\normalize_url_path() function.

Returns

string
protected mixed
# get_extension( )

Returns the extension of the path info.

Returns the extension of the path info.

Returns

mixed
protected
# lazy_set_params( $params )
protected array
# lazy_get_params( )

Returns the union of the ICanBoogie\HTTP\Request::$path_params, ICanBoogie\HTTP\Request::$request_params and ICanBoogie\HTTP\Request::$query_params properties.

Returns the union of the ICanBoogie\HTTP\Request::$path_params, ICanBoogie\HTTP\Request::$request_params and ICanBoogie\HTTP\Request::$query_params properties.

This method is the getter of the ICanBoogie\HTTP\Request::$params magic property.

Returns

array

Magic methods summary

public ICanBoogie\HTTP\Response
# connect( )

connect(array $params=null)

connect(array $params=null)

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Response
# delete( )

delete(array $params=null)

delete(array $params=null)

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Response
# get( )

get(array $params=null)

get(array $params=null)

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Response
# head( )

head(array $params=null)

head(array $params=null)

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Response
# options( )

options(array $params=null)

options(array $params=null)

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Response
# post( )

post(array $params=null)

post(array $params=null)

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Response
# put( )

put(array $params=null)

put(array $params=null)

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Response
# patch( )

patch(array $params=null)

patch(array $params=null)

Returns

ICanBoogie\HTTP\Response
public ICanBoogie\HTTP\Response
# trace( )

trace(array $params=null)

trace(array $params=null)

Returns

ICanBoogie\HTTP\Response

Constants summary

Constants inherited from ICanBoogie\HTTP\RequestMethods

METHOD_ANY, METHOD_CONNECT, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_PATCH, METHOD_POST, METHOD_PUT, METHOD_TRACE

Constants inherited from ICanBoogie\HTTP\RequestOptions

OPTION_CACHE_CONTROL, OPTION_CONTENT_LENGTH, OPTION_COOKIE, OPTION_FILES, OPTION_HEADERS, OPTION_IP, OPTION_IS_CONNECT, OPTION_IS_DELETE, OPTION_IS_GET, OPTION_IS_HEAD, OPTION_IS_LOCAL, OPTION_IS_OPTIONS, OPTION_IS_PATCH, OPTION_IS_POST, OPTION_IS_PUT, OPTION_IS_TRACE, OPTION_IS_XHR, OPTION_METHOD, OPTION_PATH, OPTION_PATH_PARAMS, OPTION_QUERY_PARAMS, OPTION_REFERER, OPTION_REQUEST_PARAMS, OPTION_URI, OPTION_USER_AGENT

Properties summary

public static array $methods
# [ self::METHOD_CONNECT, self::METHOD_DELETE, self::METHOD_GET, self::METHOD_HEAD, self::METHOD_OPTIONS, self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH, self::METHOD_TRACE ]
protected static ICanBoogie\HTTP\Request $current_request

Current request.

Current request.

#
public array $path_params

Parameters extracted from the request path.

Parameters extracted from the request path.

# []
public array $query_params

Parameters defined by the query string.

Parameters defined by the query string.

# []
public array $request_params

Parameters defined by the request body.

Parameters defined by the request body.

# []
public array $params

Union of ICanBoogie\HTTP\Request::$path_params, ICanBoogie\HTTP\Request::$request_params and ICanBoogie\HTTP\Request::$query_params.

Union of ICanBoogie\HTTP\Request::$path_params, ICanBoogie\HTTP\Request::$request_params and ICanBoogie\HTTP\Request::$query_params.

#
protected ICanBoogie\HTTP\Request\Context $context

General purpose container.

General purpose container.

#
public ICanBoogie\HTTP\Headers $headers

The headers of the request.

The headers of the request.

#
protected array $env

Request environment.

Request environment.

#
protected ICanBoogie\HTTP\FileList $files

Files associated with the request.

Files associated with the request.

#
public $cookie
#
protected ICanBoogie\HTTP\Request $parent

Parent request.

Parent request.

#

Magic properties

public read-only ICanBoogie\HTTP\Request\Context $context

the request's context.

public read-only ICanBoogie\HTTP\Request $parent

Parent request.

public read-only ICanBoogie\HTTP\FileList $files

The files associated with the request.

public read-only boolean $authorization

Authorization of the request.

public read-only integer $content_length

Length of the request content.

public read-only ICanBoogie\HTTP\Headers\CacheControl $cache_control
public read-only string $ip

Remote IP of the request.

public read-only boolean $is_delete

Is this a DELETE request?

public read-only boolean $is_get

Is this a GET request?

public read-only boolean $is_head

Is this a HEAD request?

public read-only boolean $is_options

Is this a OPTIONS request?

public read-only boolean $is_patch

Is this a PATCH request?

public read-only boolean $is_post

Is this a POST request?

public read-only boolean $is_put

Is this a PUT request?

public read-only boolean $is_trace

Is this a TRACE request?

public read-only boolean $is_local

Is this a local request?

public read-only boolean $is_xhr

Is this an Ajax request?

public read-only string $method

Method of the request.

public read-only string $normalized_path

Path of the request normalized using the \ICanBoogie\normalize_url_path() function.

public read-only string $path

Path info of the request.

public read-only string $extension

The extension of the path.

public read-only integer $port

Port of the request.

public read-only string $query_string

Query string of the request.

public read-only string $script_name

Name of the entered script.

public read-only string $referer

Referer of the request.

public read-only string $user_agent

User agent of the request.

public read-only string $uri

URI of the request. The QUERY_STRING value of the environment is overwritten when the instance is created with the $uri property.

ICanBoogie/HTTP v2.6.0 API documentation generated by ApiGen