904ac936d7845491d9c3425eb542d5ce9b94b83b
[yaffs-website] / vendor / asm89 / stack-cors / README.md
1 # Stack/Cors
2
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.
6
7 [W3C Recommendation]: http://www.w3.org/TR/cors/
8
9 Master [![Build Status](https://secure.travis-ci.org/asm89/stack-cors.png?branch=master)](http://travis-ci.org/asm89/stack-cors)
10
11 ## Installation
12
13 Require `asm89/stack-cors` using composer.
14
15 ## Usage
16
17 This package can be used as a library or as [stack middleware].
18
19 [stack middleware]: http://stackphp.com/
20
21 ### Example: using the library
22
23 ```php
24 <?php
25
26 use Asm89\Stack\CorsService;
27
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,
33     'maxAge'              => false,
34     'supportsCredentials' => false,
35 ));
36
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);
42 ```
43
44 ## Example: using the stack middleware
45
46 ```php
47 <?php
48
49 use Asm89\Stack\Cors;
50
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,
59     'maxAge'              => false,
60     'supportsCredentials' => false,
61 ));
62 ```