3 Library and middleware enabling cross-origin resource sharing for your
4 http-{foundation,kernel} using application. It attempts to implement the
5 [W3C Recommendation] for cross-origin resource sharing.
7 [W3C Recommendation]: http://www.w3.org/TR/cors/
9 Master [![Build Status](https://secure.travis-ci.org/asm89/stack-cors.png?branch=master)](http://travis-ci.org/asm89/stack-cors)
13 Require `asm89/stack-cors` using composer.
17 This package can be used as a library or as [stack middleware].
19 [stack middleware]: http://stackphp.com/
21 ### Example: using the library
26 use Asm89\Stack\CorsService;
28 $cors = new CorsService(array(
29 'allowedHeaders' => array('x-allowed-header', 'x-other-allowed-header'),
30 'allowedMethods' => array('DELETE', 'GET', 'POST', 'PUT'),
31 'allowedOrigins' => array('localhost'),
32 'exposedHeaders' => false,
34 'supportsCredentials' => false,
37 $cors->addActualRequestHeaders(Response $response, $origin);
38 $cors->handlePreflightRequest(Request $request);
39 $cors->isActualRequestAllowed(Request $request);
40 $cors->isCorsRequest(Request $request);
41 $cors->isPreflightRequest(Request $request);
44 ## Example: using the stack middleware
51 $app = new Cors($app, array(
52 // you can use array('*') to allow any headers
53 'allowedHeaders' => array('x-allowed-header', 'x-other-allowed-header'),
54 // you can use array('*') to allow any methods
55 'allowedMethods' => array('DELETE', 'GET', 'POST', 'PUT'),
56 // you can use array('*') to allow requests from any origin
57 'allowedOrigins' => array('localhost'),
58 'exposedHeaders' => false,
60 'supportsCredentials' => false,