PHP Class Psr7Middlewares\Middleware\Cors

显示文件 Open project: oscarotero/psr7-middlewares

Public Methods

Method Description
__construct ( Neomerx\Cors\Contracts\Strategies\SettingsStrategyInterface $settings = null ) Defines the settings used.
__invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface Execute the middleware.
allowCredentials ( boolean $allow = true ) : self If access with credentials is supported by the resource.
allowedHeaders ( array $headers, boolean $force = false ) : self Set allowed headers.
allowedMethods ( array $methods, boolean $force = false ) : self Set allowed methods.
allowedOrigins ( array $origins ) : self Set allowed origins.
checkHost ( boolean $checkHost = true ) : self If request 'Host' header should be checked against server's origin.
exposedHeaders ( array $headers ) : self Set headers other than the simple ones that might be exposed to user agent.
maxAge ( integer $maxAge ) : self Set pre-flight cache max period in seconds.
origin ( string | array $origin ) : self Set the server origin.

Method Details

__construct() public method

Defines the settings used.
public __construct ( Neomerx\Cors\Contracts\Strategies\SettingsStrategyInterface $settings = null )
$settings Neomerx\Cors\Contracts\Strategies\SettingsStrategyInterface

__invoke() public method

Execute the middleware.
public __invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
return Psr\Http\Message\ResponseInterface

allowCredentials() public method

If access with credentials is supported by the resource.
See also: Neomerx\Cors\Contracts\Strategies::setRequestCredentialsSupported
public allowCredentials ( boolean $allow = true ) : self
$allow boolean
return self

allowedHeaders() public method

Set allowed headers.
See also: Neomerx\Cors\Contracts\Strategies::setRequestAllowedHeaders
See also: Neomerx\Cors\Contracts\Strategies::setForceAddAllowedHeadersToPreFlightResponse
public allowedHeaders ( array $headers, boolean $force = false ) : self
$headers array
$force boolean If allowed headers should be added to pre-flight response
return self

allowedMethods() public method

Set allowed methods.
See also: Neomerx\Cors\Contracts\Strategies::setRequestAllowedMethods
See also: Neomerx\Cors\Contracts\Strategies::setForceAddAllowedMethodsToPreFlightResponse
public allowedMethods ( array $methods, boolean $force = false ) : self
$methods array
$force boolean If allowed methods should be added to pre-flight response
return self

allowedOrigins() public method

Set allowed origins.
See also: Neomerx\Cors\Contracts\Strategies::setRequestAllowedOrigins
public allowedOrigins ( array $origins ) : self
$origins array
return self

checkHost() public method

If request 'Host' header should be checked against server's origin.
See also: Neomerx\Cors\Contracts\Strategies::setCheckHost
public checkHost ( boolean $checkHost = true ) : self
$checkHost boolean
return self

exposedHeaders() public method

Set headers other than the simple ones that might be exposed to user agent.
See also: Neomerx\Cors\Contracts\Strategies::setResponseExposedHeaders
public exposedHeaders ( array $headers ) : self
$headers array
return self

maxAge() public method

Set pre-flight cache max period in seconds.
See also: Neomerx\Cors\Contracts\Strategies::setPreFlightCacheMaxAge
public maxAge ( integer $maxAge ) : self
$maxAge integer
return self

origin() public method

Set the server origin.
See also: Neomerx\Cors\Contracts\Strategies::setServerOrigin
public origin ( string | array $origin ) : self
$origin string | array
return self