PHP Class Imbo\EventListener\Cors

This event listener will listen to all incoming OPTIONS requests and adds the correct headers required for CORS to function properly - all configured on a per-user/resource base.
Author: Espen Hovlandsdal ([email protected])
Inheritance: implements Imbo\EventListener\ListenerInterface
Show file Open project: imbo/imbo Class Usage Examples

Public Methods

Method Description
__construct ( array $params = [] ) Class constructor
getAllowedOrigins ( ) : array Returns an array of allowed origins
getSubscribedEvents ( )
invoke ( Imbo\EventManager\EventInterface $event ) Handle other requests
options ( Imbo\EventManager\EventInterface $event ) Handle the OPTIONS requests
setExposedHeaders ( Imbo\EventManager\EventInterface $event ) Right before the response is sent to the client, whitelist all included Imbo-headers in the "Access-Control-Expose-Headers"-header
subscribe ( Imbo\EventManager\EventInterface $event ) Subscribe to events based on configuration parameters

Private Methods

Method Description
originIsAllowed ( string $origin ) : boolean Check if the given origin is defined as an allowed origin

Method Details

__construct() public method

Class constructor
public __construct ( array $params = [] )
$params array Parameters for the listener

getAllowedOrigins() public method

Returns an array of allowed origins
public getAllowedOrigins ( ) : array
return array The defined allowed origins

getSubscribedEvents() public static method

public static getSubscribedEvents ( )

invoke() public method

Handle other requests
public invoke ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The event instance

options() public method

Handle the OPTIONS requests
public options ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The event instance

setExposedHeaders() public method

Right before the response is sent to the client, whitelist all included Imbo-headers in the "Access-Control-Expose-Headers"-header
public setExposedHeaders ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The event instance

subscribe() public method

Subscribe to events based on configuration parameters
public subscribe ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The event instance