@@ -22,10 +22,10 @@ This package can be used as a library or as [stack middleware].
22
22
23
23
| Option | Description | Default value |
24
24
| ------------------------| ------------------------------------------------------------| ---------------|
25
- | allowedMethods | Matches the request method. | ` array() ` |
26
- | allowedOrigins | Matches the request origin. | ` array() ` |
27
- | allowedOriginsPatterns | Matches the request origin with ` preg_match ` . | ` array() ` |
28
- | allowedHeaders | Sets the Access-Control-Allow-Headers response header. | ` array() ` |
25
+ | allowedMethods | Matches the request method. | ` [] ` |
26
+ | allowedOrigins | Matches the request origin. | ` [] ` |
27
+ | allowedOriginsPatterns | Matches the request origin with ` preg_match ` . | ` [] ` |
28
+ | allowedHeaders | Sets the Access-Control-Allow-Headers response header. | ` [] ` |
29
29
| exposedHeaders | Sets the Access-Control-Expose-Headers response header. | ` false ` |
30
30
| maxAge | Sets the Access-Control-Max-Age response header. | ` false ` |
31
31
| supportsCredentials | Sets the Access-Control-Allow-Credentials header. | ` false ` |
@@ -34,7 +34,7 @@ The _allowedMethods_ and _allowedHeaders_ options are case-insensitive.
34
34
35
35
You don't need to provide both _ allowedOrigins_ and _ allowedOriginsPatterns_ . If one of the strings passed matches, it is considered a valid origin.
36
36
37
- If ` array( '*') ` is provided to _ allowedMethods_ , _ allowedOrigins_ or _ allowedHeaders_ all methods / origins / headers are allowed.
37
+ If ` [ '*'] ` is provided to _ allowedMethods_ , _ allowedOrigins_ or _ allowedHeaders_ all methods / origins / headers are allowed.
38
38
39
39
### Example: using the library
40
40
@@ -43,15 +43,15 @@ If `array('*')` is provided to _allowedMethods_, _allowedOrigins_ or _allowedHea
43
43
44
44
use Asm89\Stack\CorsService;
45
45
46
- $cors = new CorsService(array(
47
- 'allowedHeaders' => array( 'x-allowed-header', 'x-other-allowed-header') ,
48
- 'allowedMethods' => array( 'DELETE', 'GET', 'POST', 'PUT') ,
49
- 'allowedOrigins' => array( 'http://localhost') ,
50
- 'allowedOriginsPatterns' => array( '/localhost:\d/') ,
46
+ $cors = new CorsService([
47
+ 'allowedHeaders' => [ 'x-allowed-header', 'x-other-allowed-header'] ,
48
+ 'allowedMethods' => [ 'DELETE', 'GET', 'POST', 'PUT'] ,
49
+ 'allowedOrigins' => [ 'http://localhost'] ,
50
+ 'allowedOriginsPatterns' => [ '/localhost:\d/'] ,
51
51
'exposedHeaders' => false,
52
52
'maxAge' => false,
53
53
'supportsCredentials' => false,
54
- ) );
54
+ ] );
55
55
56
56
$cors->addActualRequestHeaders(Response $response, $origin);
57
57
$cors->handlePreflightRequest(Request $request);
@@ -67,17 +67,17 @@ $cors->isPreflightRequest(Request $request);
67
67
68
68
use Asm89\Stack\Cors;
69
69
70
- $app = new Cors($app, array(
71
- // you can use array( '*') to allow any headers
72
- 'allowedHeaders' => array( 'x-allowed-header', 'x-other-allowed-header') ,
70
+ $app = new Cors($app, [
71
+ // you can use [ '*'] to allow any headers
72
+ 'allowedHeaders' => [ 'x-allowed-header', 'x-other-allowed-header'] ,
73
73
// you can use array('*') to allow any methods
74
- 'allowedMethods' => array( 'DELETE', 'GET', 'POST', 'PUT') ,
74
+ 'allowedMethods' => [ 'DELETE', 'GET', 'POST', 'PUT'] ,
75
75
// you can use array('*') to allow requests from any origin
76
- 'allowedOrigins' => array( 'localhost') ,
76
+ 'allowedOrigins' => [ 'localhost'] ,
77
77
// you can enter regexes that are matched to the origin request header
78
- 'allowedOriginsPatterns' => array( '/localhost:\d/') ,
78
+ 'allowedOriginsPatterns' => [ '/localhost:\d/'] ,
79
79
'exposedHeaders' => false,
80
80
'maxAge' => false,
81
81
'supportsCredentials' => false,
82
- ) );
82
+ ] );
83
83
```
0 commit comments