Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
medz authored and StyleCIBot committed Feb 26, 2019
1 parent 13c1367 commit eec56d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/Swoft/CorsBean.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Medz\Cors\Swoft;

use Swoft\App;
use Medz\Cors\Cors;
use Medz\Cors\CorsInterface;
use Swoft\App;

/**
* @\Swoft\Bean\Annotation\Bean('cors.main')
Expand All @@ -14,10 +14,11 @@ class CorsBean
/**
* The cors instance.
*/
static protected $cors;
protected static $cors;

/**
* Set a cors instance.
*
* @param \Medz\Cors\CorsInterface $cors
*/
public function setCors(CorsInterface $cors)
Expand All @@ -29,6 +30,7 @@ public function setCors(CorsInterface $cors)

/**
* Get the cors instance.
*
* @return \Medz\Cors\CorsInterface
*/
public function getCors(): CorsInterface
Expand All @@ -42,6 +44,7 @@ public function getCors(): CorsInterface

/**
* Has the http request is only preflight.
*
* @return bool
*/
public function onlyPreflight(): bool
Expand All @@ -53,8 +56,10 @@ public function onlyPreflight(): bool

/**
* Get the cors configures.
*
* @param string $key
* @param mixed $value
* @param mixed $value
*
* @return mixed
*/
public function getConfigure(string $key = '', $value = null)
Expand All @@ -64,6 +69,7 @@ public function getConfigure(string $key = '', $value = null)

/**
* Resolve the cors.
*
* @return \Medz\Cors\CorsInterface
*/
protected function createCors(): CorsInterface
Expand All @@ -75,7 +81,9 @@ protected function createCors(): CorsInterface

/**
* Parse settings.
*
* @param array $settings
*
* @return array
*/
protected function parseSettings(array $settings): array
Expand All @@ -94,8 +102,10 @@ protected function parseSettings(array $settings): array

/**
* Call "Medz\Cors\CorsInterface" methods.
*
* @param string $method
* @param array $parameters
* @param array $parameters
*
* @return mixed
*/
public function __call($method, $parameters)
Expand Down
12 changes: 8 additions & 4 deletions src/Swoft/CorsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Medz\Cors\Swoft;

use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Swoft\Core\RequestContext;
use Swoft\Http\Message\Middleware\MiddlewareInterface;

Expand All @@ -20,22 +20,23 @@ class CorsMiddleware implements MiddlewareInterface

/**
* The middleware handler.
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Server\RequestHandlerInterface $handler
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->cors->onlyPreflight()) {
if ($this->cors->isPreflightRequest('psr-7', $request)) {
if (! (($response = $this->getResponse()) instanceof ResponseInterface)) {
if (!(($response = $this->getResponse()) instanceof ResponseInterface)) {
$response = $handler->handle($request);
}

return $this
->handle($request, $response)
->withStatus(204);
;
}

return $handler->handle($request);
Expand All @@ -46,8 +47,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

/**
* The cors handle.
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param \Psr\Http\Message\ResponseInterface $response
*
* @return \Psr\Http\Message\ResponseInterface
*/
protected function handle(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
Expand All @@ -62,6 +65,7 @@ protected function handle(ServerRequestInterface $request, ResponseInterface $re

/**
* Using Swoft request context get response instance.
*
* @return \Psr\Http\Message\ResponseInterface|null
*/
protected function getResponse()
Expand Down

0 comments on commit eec56d3

Please sign in to comment.