Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
19
vendor/asm89/stack-cors/LICENSE
vendored
Normal file
19
vendor/asm89/stack-cors/LICENSE
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2013-2017 Alexander <iam.asm89@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
83
vendor/asm89/stack-cors/README.md
vendored
Normal file
83
vendor/asm89/stack-cors/README.md
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
# Stack/Cors
|
||||
|
||||
Library and middleware enabling cross-origin resource sharing for your
|
||||
http-{foundation,kernel} using application. It attempts to implement the
|
||||
[W3C Recommendation] for cross-origin resource sharing.
|
||||
|
||||
[W3C Recommendation]: http://www.w3.org/TR/cors/
|
||||
|
||||
Master [](http://travis-ci.org/asm89/stack-cors)
|
||||
|
||||
## Installation
|
||||
|
||||
Require `asm89/stack-cors` using composer.
|
||||
|
||||
## Usage
|
||||
|
||||
This package can be used as a library or as [stack middleware].
|
||||
|
||||
[stack middleware]: http://stackphp.com/
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Description | Default value |
|
||||
|------------------------|------------------------------------------------------------|---------------|
|
||||
| allowedMethods | Matches the request method. | `array()` |
|
||||
| allowedOrigins | Matches the request origin. | `array()` |
|
||||
| allowedOriginsPatterns | Matches the request origin with `preg_match`. | `array()` |
|
||||
| allowedHeaders | Sets the Access-Control-Allow-Headers response header. | `array()` |
|
||||
| exposedHeaders | Sets the Access-Control-Expose-Headers response header. | `false` |
|
||||
| maxAge | Sets the Access-Control-Max-Age response header. | `false` |
|
||||
| supportsCredentials | Sets the Access-Control-Allow-Credentials header. | `false` |
|
||||
|
||||
The _allowedMethods_ and _allowedHeaders_ options are case-insensitive.
|
||||
|
||||
You don't need to provide both _allowedOrigins_ and _allowedOriginsPatterns_. If one of the strings passed matches, it is considered a valid origin.
|
||||
|
||||
If `array('*')` is provided to _allowedMethods_, _allowedOrigins_ or _allowedHeaders_ all methods / origins / headers are allowed.
|
||||
|
||||
### Example: using the library
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Asm89\Stack\CorsService;
|
||||
|
||||
$cors = new CorsService(array(
|
||||
'allowedHeaders' => array('x-allowed-header', 'x-other-allowed-header'),
|
||||
'allowedMethods' => array('DELETE', 'GET', 'POST', 'PUT'),
|
||||
'allowedOrigins' => array('localhost'),
|
||||
'allowedOriginsPatterns' => array('/localhost:\d/'),
|
||||
'exposedHeaders' => false,
|
||||
'maxAge' => false,
|
||||
'supportsCredentials' => false,
|
||||
));
|
||||
|
||||
$cors->addActualRequestHeaders(Response $response, $origin);
|
||||
$cors->handlePreflightRequest(Request $request);
|
||||
$cors->isActualRequestAllowed(Request $request);
|
||||
$cors->isCorsRequest(Request $request);
|
||||
$cors->isPreflightRequest(Request $request);
|
||||
```
|
||||
|
||||
## Example: using the stack middleware
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Asm89\Stack\Cors;
|
||||
|
||||
$app = new Cors($app, array(
|
||||
// you can use array('*') to allow any headers
|
||||
'allowedHeaders' => array('x-allowed-header', 'x-other-allowed-header'),
|
||||
// you can use array('*') to allow any methods
|
||||
'allowedMethods' => array('DELETE', 'GET', 'POST', 'PUT'),
|
||||
// you can use array('*') to allow requests from any origin
|
||||
'allowedOrigins' => array('localhost'),
|
||||
// you can enter regexes that are matched to the origin request header
|
||||
'allowedOriginsPatterns' => array('/localhost:\d/'),
|
||||
'exposedHeaders' => false,
|
||||
'maxAge' => false,
|
||||
'supportsCredentials' => false,
|
||||
));
|
||||
```
|
43
vendor/asm89/stack-cors/composer.json
vendored
Normal file
43
vendor/asm89/stack-cors/composer.json
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"name": "asm89/stack-cors",
|
||||
"description": "Cross-origin resource sharing library and stack middleware",
|
||||
"keywords": ["stack", "cors"],
|
||||
"homepage": "https://github.com/asm89/stack-cors",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alexander",
|
||||
"email": "iam.asm89@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"symfony/http-foundation": "~2.7|~3.0|~4.0",
|
||||
"symfony/http-kernel": "~2.7|~3.0|~4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.0 || ^4.8.10",
|
||||
"squizlabs/php_codesniffer": "^2.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Asm89\\Stack\\": "src/Asm89/Stack/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Asm89\\Stack\\": "test/Asm89/Stack/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit",
|
||||
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src",
|
||||
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.2-dev"
|
||||
}
|
||||
}
|
||||
}
|
64
vendor/asm89/stack-cors/src/Asm89/Stack/Cors.php
vendored
Normal file
64
vendor/asm89/stack-cors/src/Asm89/Stack/Cors.php
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of asm89/stack-cors.
|
||||
*
|
||||
* (c) Alexander <iam.asm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Asm89\Stack;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class Cors implements HttpKernelInterface
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
|
||||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* @var \Asm89\Stack\CorsService
|
||||
*/
|
||||
private $cors;
|
||||
|
||||
private $defaultOptions = array(
|
||||
'allowedHeaders' => array(),
|
||||
'allowedMethods' => array(),
|
||||
'allowedOrigins' => array(),
|
||||
'allowedOriginsPatterns' => array(),
|
||||
'exposedHeaders' => false,
|
||||
'maxAge' => false,
|
||||
'supportsCredentials' => false,
|
||||
);
|
||||
|
||||
public function __construct(HttpKernelInterface $app, array $options = array())
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->cors = new CorsService(array_merge($this->defaultOptions, $options));
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
if (!$this->cors->isCorsRequest($request)) {
|
||||
return $this->app->handle($request, $type, $catch);
|
||||
}
|
||||
|
||||
if ($this->cors->isPreflightRequest($request)) {
|
||||
return $this->cors->handlePreflightRequest($request);
|
||||
}
|
||||
|
||||
if (!$this->cors->isActualRequestAllowed($request)) {
|
||||
return new Response('Not allowed.', 403);
|
||||
}
|
||||
|
||||
$response = $this->app->handle($request, $type, $catch);
|
||||
|
||||
return $this->cors->addActualRequestHeaders($response, $request);
|
||||
}
|
||||
}
|
203
vendor/asm89/stack-cors/src/Asm89/Stack/CorsService.php
vendored
Normal file
203
vendor/asm89/stack-cors/src/Asm89/Stack/CorsService.php
vendored
Normal file
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of asm89/stack-cors.
|
||||
*
|
||||
* (c) Alexander <iam.asm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Asm89\Stack;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CorsService
|
||||
{
|
||||
private $options;
|
||||
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
$this->options = $this->normalizeOptions($options);
|
||||
}
|
||||
|
||||
private function normalizeOptions(array $options = array())
|
||||
{
|
||||
$options += array(
|
||||
'allowedOrigins' => array(),
|
||||
'allowedOriginsPatterns' => array(),
|
||||
'supportsCredentials' => false,
|
||||
'allowedHeaders' => array(),
|
||||
'exposedHeaders' => array(),
|
||||
'allowedMethods' => array(),
|
||||
'maxAge' => 0,
|
||||
);
|
||||
|
||||
// normalize array('*') to true
|
||||
if (in_array('*', $options['allowedOrigins'])) {
|
||||
$options['allowedOrigins'] = true;
|
||||
}
|
||||
if (in_array('*', $options['allowedHeaders'])) {
|
||||
$options['allowedHeaders'] = true;
|
||||
} else {
|
||||
$options['allowedHeaders'] = array_map('strtolower', $options['allowedHeaders']);
|
||||
}
|
||||
|
||||
if (in_array('*', $options['allowedMethods'])) {
|
||||
$options['allowedMethods'] = true;
|
||||
} else {
|
||||
$options['allowedMethods'] = array_map('strtoupper', $options['allowedMethods']);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function isActualRequestAllowed(Request $request)
|
||||
{
|
||||
return $this->checkOrigin($request);
|
||||
}
|
||||
|
||||
public function isCorsRequest(Request $request)
|
||||
{
|
||||
return $request->headers->has('Origin') && !$this->isSameHost($request);
|
||||
}
|
||||
|
||||
public function isPreflightRequest(Request $request)
|
||||
{
|
||||
return $this->isCorsRequest($request)
|
||||
&& $request->getMethod() === 'OPTIONS'
|
||||
&& $request->headers->has('Access-Control-Request-Method');
|
||||
}
|
||||
|
||||
public function addActualRequestHeaders(Response $response, Request $request)
|
||||
{
|
||||
if (!$this->checkOrigin($request)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response->headers->set('Access-Control-Allow-Origin', $request->headers->get('Origin'));
|
||||
|
||||
if (!$response->headers->has('Vary')) {
|
||||
$response->headers->set('Vary', 'Origin');
|
||||
} else {
|
||||
$response->headers->set('Vary', $response->headers->get('Vary') . ', Origin');
|
||||
}
|
||||
|
||||
if ($this->options['supportsCredentials']) {
|
||||
$response->headers->set('Access-Control-Allow-Credentials', 'true');
|
||||
}
|
||||
|
||||
if ($this->options['exposedHeaders']) {
|
||||
$response->headers->set('Access-Control-Expose-Headers', implode(', ', $this->options['exposedHeaders']));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function handlePreflightRequest(Request $request)
|
||||
{
|
||||
if (true !== $check = $this->checkPreflightRequestConditions($request)) {
|
||||
return $check;
|
||||
}
|
||||
|
||||
return $this->buildPreflightCheckResponse($request);
|
||||
}
|
||||
|
||||
private function buildPreflightCheckResponse(Request $request)
|
||||
{
|
||||
$response = new Response();
|
||||
|
||||
if ($this->options['supportsCredentials']) {
|
||||
$response->headers->set('Access-Control-Allow-Credentials', 'true');
|
||||
}
|
||||
|
||||
$response->headers->set('Access-Control-Allow-Origin', $request->headers->get('Origin'));
|
||||
|
||||
if ($this->options['maxAge']) {
|
||||
$response->headers->set('Access-Control-Max-Age', $this->options['maxAge']);
|
||||
}
|
||||
|
||||
$allowMethods = $this->options['allowedMethods'] === true
|
||||
? strtoupper($request->headers->get('Access-Control-Request-Method'))
|
||||
: implode(', ', $this->options['allowedMethods']);
|
||||
$response->headers->set('Access-Control-Allow-Methods', $allowMethods);
|
||||
|
||||
$allowHeaders = $this->options['allowedHeaders'] === true
|
||||
? strtoupper($request->headers->get('Access-Control-Request-Headers'))
|
||||
: implode(', ', $this->options['allowedHeaders']);
|
||||
$response->headers->set('Access-Control-Allow-Headers', $allowHeaders);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function checkPreflightRequestConditions(Request $request)
|
||||
{
|
||||
if (!$this->checkOrigin($request)) {
|
||||
return $this->createBadRequestResponse(403, 'Origin not allowed');
|
||||
}
|
||||
|
||||
if (!$this->checkMethod($request)) {
|
||||
return $this->createBadRequestResponse(405, 'Method not allowed');
|
||||
}
|
||||
|
||||
$requestHeaders = array();
|
||||
// if allowedHeaders has been set to true ('*' allow all flag) just skip this check
|
||||
if ($this->options['allowedHeaders'] !== true && $request->headers->has('Access-Control-Request-Headers')) {
|
||||
$headers = strtolower($request->headers->get('Access-Control-Request-Headers'));
|
||||
$requestHeaders = array_filter(explode(',', $headers));
|
||||
|
||||
foreach ($requestHeaders as $header) {
|
||||
if (!in_array(trim($header), $this->options['allowedHeaders'])) {
|
||||
return $this->createBadRequestResponse(403, 'Header not allowed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function createBadRequestResponse($code, $reason = '')
|
||||
{
|
||||
return new Response($reason, $code);
|
||||
}
|
||||
|
||||
private function isSameHost(Request $request)
|
||||
{
|
||||
return $request->headers->get('Origin') === $request->getSchemeAndHttpHost();
|
||||
}
|
||||
|
||||
private function checkOrigin(Request $request)
|
||||
{
|
||||
if ($this->options['allowedOrigins'] === true) {
|
||||
// allow all '*' flag
|
||||
return true;
|
||||
}
|
||||
$origin = $request->headers->get('Origin');
|
||||
|
||||
if (in_array($origin, $this->options['allowedOrigins'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->options['allowedOriginsPatterns'] as $pattern) {
|
||||
if (preg_match($pattern, $origin)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkMethod(Request $request)
|
||||
{
|
||||
if ($this->options['allowedMethods'] === true) {
|
||||
// allow all '*' flag
|
||||
return true;
|
||||
}
|
||||
|
||||
$requestMethod = strtoupper($request->headers->get('Access-Control-Request-Method'));
|
||||
return in_array($requestMethod, $this->options['allowedMethods']);
|
||||
}
|
||||
}
|
Reference in a new issue