ICanBoogie/HTTP master
  • 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 RequestDispatcher

Dispatches HTTP requests.

Events

  • ICanBoogie\HTTP\RequestDispatcher::dispatch:before of class ICanBoogie\HTTP\RequestDispatcher\BeforeDispatchEvent.
  • ICanBoogie\HTTP\RequestDispatcher::dispatch of class ICanBoogie\HTTP\RequestDispatcher\DispatchEvent.
  • ICanBoogie\HTTP\RequestDispatcher::rescue of class ICanBoogie\Exception\RescueEvent.
ICanBoogie\HTTP\RequestDispatcher implements ArrayAccess, IteratorAggregate, ICanBoogie\HTTP\Dispatcher
Namespace: ICanBoogie\HTTP
Located at RequestDispatcher.php

Methods summary

public
# __construct( array $dispatchers = [] )

Initializes the ICanBoogie\HTTP\RequestDispatcher::$dispatchers property.

Initializes the ICanBoogie\HTTP\RequestDispatcher::$dispatchers property.

Dispatchers can be defined as callable or class name. If a dispatcher definition is not a callable it is used as class name to instantiate a dispatcher.

Parameters

$dispatchers
public ICanBoogie\HTTP\Response
# __invoke( ICanBoogie\HTTP\Request $request )

Dispatches the request to retrieve a ICanBoogie\HTTP\Response.

Dispatches the request to retrieve a ICanBoogie\HTTP\Response.

The request is dispatched by the dispatch() method. If an exception is thrown during the dispatch the ICanBoogie\HTTP\RequestDispatcher::rescue() method is used to rescue the exception and retrieve a ICanBoogie\HTTP\Response.

HEAD requests

If a ICanBoogie\HTTP\NotFound exception is caught during the dispatching of a request with a Request::METHOD_HEAD method the following happens:

  1. The request is cloned and the method of the cloned request is changed to Request::METHOD_GET.
  2. The cloned method is dispatched.
  3. If the result is not a ICanBoogie\HTTP\Response instance, the result is returned.
  4. Otherwise, a new ICanBoogie\HTTP\Response instance is created with a null body, but the status code and headers of the original response.
  5. The new response is returned.

Parameters

$request

Returns

ICanBoogie\HTTP\Response

Implementation of

ICanBoogie\HTTP\Dispatcher::__invoke()
public boolean
# offsetExists( string $dispatcher_id )

Checks if the dispatcher is defined.

Checks if the dispatcher is defined.

Parameters

$dispatcher_id
The identifier of the dispatcher.

Returns

boolean
true if the dispatcher is defined, false otherwise.

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( string $dispatcher_id )

Returns a dispatcher.

Returns a dispatcher.

Parameters

$dispatcher_id
The identifier of the dispatcher.

Returns

mixed

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( string $dispatcher_id, mixed $dispatcher )

Defines a dispatcher.

Defines a dispatcher.

Parameters

$dispatcher_id
The identifier of the dispatcher.
$dispatcher
The dispatcher class or callback.

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( string $dispatcher_id )

Removes a dispatcher.

Removes a dispatcher.

Parameters

$dispatcher_id
The identifier of the dispatcher.

Implementation of

ArrayAccess::offsetUnset()
public
# getIterator( )

Inheritdoc

Implementation of

IteratorAggregate::getIterator()
protected ICanBoogie\HTTP\Response
# dispatch( ICanBoogie\HTTP\Request $request )

Dispatches a request using the defined dispatchers.

Dispatches a request using the defined dispatchers.

The method iterates over the defined dispatchers until one of them returns a ICanBoogie\HTTP\Response instance. If an exception is throw during the dispatcher execution and the dispatcher implements the ICanBoogie\HTTP\Dispatcher interface then its Dispatcher::rescue method is invoked to rescue the exception, otherwise the exception is just re-thrown.

ICanBoogie\HTTP\RequestDispatcher\BeforeDispatchEvent is fired before dispatchers are traversed. If a response is provided the dispatchers are skipped.

ICanBoogie\HTTP\RequestDispatcher\DispatchEvent is fired before the response is returned. The event is fired event if the dispatchers did'nt return a response. It's the last chance to get one.

Parameters

$request

Returns

ICanBoogie\HTTP\Response

Throws

Exception

If the dispatcher that raised an exception during dispatch doesn't implement ICanBoogie\HTTP\Dispatcher.


ICanBoogie\HTTP\NotFound

when neither the events nor the dispatchers were able to provide a ICanBoogie\HTTP\Response.

protected ICanBoogie\HTTP\Response
# dispatch_with_dispatcher( ICanBoogie\HTTP\Dispatcher $dispatcher, ICanBoogie\HTTP\Request $request )

Dispatches the request using a dispatcher.

Dispatches the request using a dispatcher.

Parameters

$dispatcher
$request

Returns

ICanBoogie\HTTP\Response

Throws

Exception
public ICanBoogie\HTTP\Response
# rescue( ICanBoogie\HTTP\Exception $exception, ICanBoogie\HTTP\Request $request )

Tries to get a ICanBoogie\HTTP\Response object from an exception.

Tries to get a ICanBoogie\HTTP\Response object from an exception.

ICanBoogie\Exception\RescueEvent is fired with the exception as target. The response provided by one of the event hooks is returned. If there is no response the exception is thrown again.

If a response is finally obtained, the X-ICanBoogie-Rescued-Exception header is added to indicate where the exception was thrown from.

Parameters

$exception
The exception to rescue.
$request
The current request.

Returns

ICanBoogie\HTTP\Response

Throws

Exception
The exception is re-thrown if it could not be rescued.

Implementation of

ICanBoogie\HTTP\Dispatcher::rescue()
protected
# alter_response_with_exception( ICanBoogie\HTTP\Response $response, ICanBoogie\HTTP\Exception $exception )

Alters a response with an exception.

Alters a response with an exception.

The methods adds the X-ICanBoogie-Rescued-Exception header to the response, which describes the filename and the line where the exception occurred.

Parameters

$response
$exception

Properties summary

protected array $dispatchers

The dispatchers called during the dispatching of the request.

The dispatchers called during the dispatching of the request.

# []
protected array $dispatchers_weight

The weights of the dispatchers.

The weights of the dispatchers.

# []
protected $dispatchers_order
#
ICanBoogie/HTTP master API documentation generated by ApiGen