@@ -23,12 +23,12 @@ |
||
23 | 23 | */ |
24 | 24 | static public function register(Application $app, |
25 | 25 | callable $callback = null, |
26 | - $prefix='/docs') |
|
26 | + $prefix = '/docs') |
|
27 | 27 | { |
28 | - $app->addRoute('GET', $prefix.'/swagger.json', function (Application $app)use($callback){ |
|
28 | + $app->addRoute('GET', $prefix.'/swagger.json', function(Application $app)use($callback){ |
|
29 | 29 | $swagger = new Swagger(); |
30 | 30 | $swagger->appendControllers($app, $app->getControllers()); |
31 | - if($callback){ |
|
31 | + if ($callback) { |
|
32 | 32 | $callback($swagger); |
33 | 33 | } |
34 | 34 | return new Response($swagger->toJson()); |
@@ -64,12 +64,12 @@ |
||
64 | 64 | * The value overrides the Swagger Object schemes definition. |
65 | 65 | * @var string[] |
66 | 66 | */ |
67 | - public $schemes=['http']; |
|
67 | + public $schemes = ['http']; |
|
68 | 68 | /** |
69 | 69 | * Declares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is false. |
70 | 70 | * @var bool |
71 | 71 | */ |
72 | - public $deprecated=false; |
|
72 | + public $deprecated = false; |
|
73 | 73 | /** |
74 | 74 | * A declaration of which security schemes are applied for this operation. The list of values describes |
75 | 75 | * alternative security schemes that can be used (that is, there is a logical OR between the security |
@@ -52,18 +52,18 @@ |
||
52 | 52 | * A list of MIME types the APIs can produce. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types. |
53 | 53 | * @var string[] |
54 | 54 | */ |
55 | - public $produces= ['application/json']; |
|
55 | + public $produces = ['application/json']; |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @var PathItemObject[] |
59 | 59 | */ |
60 | - public $paths=[]; |
|
60 | + public $paths = []; |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * An object to hold data types produced and consumed by operations. |
64 | 64 | * @var RefSchemaObject[]|SimpleModelSchemaObject[]|PrimitiveSchemaObject[]|ArraySchemaObject[] |
65 | 65 | */ |
66 | - public $definitions=[]; |
|
66 | + public $definitions = []; |
|
67 | 67 | /** |
68 | 68 | * An object to hold parameters that can be used across operations. This property does not define global |
69 | 69 | * parameters for all operations. |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * Required. The title of the application. |
10 | 10 | * @var string |
11 | 11 | */ |
12 | - public $title=''; |
|
12 | + public $title = ''; |
|
13 | 13 | /** |
14 | 14 | * A short description of the application. GFM syntax can be used for rich text representation |
15 | 15 | * @var string |
@@ -34,5 +34,5 @@ discard block |
||
34 | 34 | * Required Provides the version of the application API (not to be confused with the specification version) |
35 | 35 | * @var string |
36 | 36 | */ |
37 | - public $version=''; |
|
37 | + public $version = ''; |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * representation. |
11 | 11 | * @var string |
12 | 12 | */ |
13 | - public $description=''; |
|
13 | + public $description = ''; |
|
14 | 14 | /** |
15 | 15 | * A definition of the response structure. It can be a primitive, an array or an object. If this field |
16 | 16 | * does not exist, it means no content is returned as part of the response. As an extension to the Schema |
@@ -55,12 +55,12 @@ |
||
55 | 55 | */ |
56 | 56 | public function rule($rule, $fields) |
57 | 57 | { |
58 | - if(is_string($rule)){ |
|
58 | + if (is_string($rule)) { |
|
59 | 59 | $rules = explode('|', $rule); |
60 | - foreach ($rules as $r){ |
|
60 | + foreach ($rules as $r) { |
|
61 | 61 | $params = explode(':', trim($r)); |
62 | 62 | $rule = $params[0]; |
63 | - $params = isset($params[1])?explode(',', $params[1]):[]; |
|
63 | + $params = isset($params[1]) ? explode(',', $params[1]) : []; |
|
64 | 64 | |
65 | 65 | call_user_func_array([$this, 'parent::rule'], array_merge([$rule, $fields], $params)); |
66 | 66 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use EnableDIAnnotations; |
16 | 16 | |
17 | 17 | protected $settings = array( |
18 | - 'origin' => '*', // Wide Open! |
|
18 | + 'origin' => '*', // Wide Open! |
|
19 | 19 | 'allowMethods' => 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS', |
20 | 20 | ); |
21 | 21 | protected function setOrigin(Request $req, Response $rsp) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } |
67 | 67 | } |
68 | 68 | else { // Otherwise, use request headers |
69 | - $allowHeaders = $req->headers->get("Access-Control-Request-Headers", null ,false); |
|
69 | + $allowHeaders = $req->headers->get("Access-Control-Request-Headers", null, false); |
|
70 | 70 | } |
71 | 71 | if (isset($allowHeaders)) { |
72 | 72 | $rsp->headers->set('Access-Control-Allow-Headers', $allowHeaders); |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | $response = new Response("", 200); |
100 | 100 | } |
101 | 101 | else { |
102 | - try{ |
|
102 | + try { |
|
103 | 103 | $response = $next($request); |
104 | - }catch(\Exception $e){ |
|
104 | + }catch (\Exception $e) { |
|
105 | 105 | $response = $this->exceptionRenderer->render($e); |
106 | 106 | } |
107 | 107 | } |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | if (is_array($allowHeaders)) { |
65 | 65 | $allowHeaders = implode(", ", $allowHeaders); |
66 | 66 | } |
67 | - } |
|
68 | - else { // Otherwise, use request headers |
|
67 | + } else { // Otherwise, use request headers |
|
69 | 68 | $allowHeaders = $req->headers->get("Access-Control-Request-Headers", null ,false); |
70 | 69 | } |
71 | 70 | if (isset($allowHeaders)) { |
@@ -81,8 +80,7 @@ discard block |
||
81 | 80 | $this->setAllowCredentials($req, $rsp); |
82 | 81 | $this->setAllowMethods($req, $rsp); |
83 | 82 | $this->setAllowHeaders($req, $rsp); |
84 | - } |
|
85 | - else { |
|
83 | + } else { |
|
86 | 84 | $this->setOrigin($req, $rsp); |
87 | 85 | $this->setExposeHeaders($req, $rsp); |
88 | 86 | $this->setAllowCredentials($req, $rsp); |
@@ -97,11 +95,10 @@ discard block |
||
97 | 95 | public function handle(Request $request, \Closure $next) { |
98 | 96 | if ($request->getMethod() == 'OPTIONS') { |
99 | 97 | $response = new Response("", 200); |
100 | - } |
|
101 | - else { |
|
98 | + } else { |
|
102 | 99 | try{ |
103 | 100 | $response = $next($request); |
104 | - }catch(\Exception $e){ |
|
101 | + } catch(\Exception $e){ |
|
105 | 102 | $response = $this->exceptionRenderer->render($e); |
106 | 103 | } |
107 | 104 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function eraseMapping($target) |
29 | 29 | { |
30 | - if(!isset($this->mappings[$target])){ |
|
30 | + if (!isset($this->mappings[$target])) { |
|
31 | 31 | return null; |
32 | 32 | } |
33 | 33 | $ori = $this->mappings[$target]; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function getMapping($target) |
43 | 43 | { |
44 | - if(!array_key_exists($target, $this->mappings)){ |
|
44 | + if (!array_key_exists($target, $this->mappings)) { |
|
45 | 45 | return null; |
46 | 46 | } |
47 | 47 | return $this->mappings[$target]; |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | 'params'=>$params |
61 | 61 | ]; |
62 | 62 | |
63 | - if($return instanceof Response){ //直接返回Response时, 对return不再做映射 |
|
63 | + if ($return instanceof Response) { //直接返回Response时, 对return不再做映射 |
|
64 | 64 | return $return; |
65 | 65 | } |
66 | 66 | $mappings = $this->getMappings(); |
67 | 67 | |
68 | 68 | $output = []; |
69 | - foreach($mappings as $key=>$map){ |
|
69 | + foreach ($mappings as $key=>$map) { |
|
70 | 70 | $val = \JmesPath\search($map->source, $input); |
71 | - if(substr($key, 0, strlen('response.')) == 'response.'){ |
|
71 | + if (substr($key, 0, strlen('response.')) == 'response.') { |
|
72 | 72 | $key = substr($key, strlen('response.')); |
73 | 73 | } |
74 | 74 | ArrayHelper::set($output, $key, $val); |
@@ -14,11 +14,11 @@ |
||
14 | 14 | */ |
15 | 15 | public function render(\Exception $e) |
16 | 16 | { |
17 | - if($e instanceof HttpException){ |
|
17 | + if ($e instanceof HttpException) { |
|
18 | 18 | return new Response($e->getMessage(), $e->getStatusCode()); |
19 | - } if($e instanceof \InvalidArgumentException){ |
|
19 | + } if ($e instanceof \InvalidArgumentException) { |
|
20 | 20 | return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST); |
21 | - }else{ |
|
21 | + }else { |
|
22 | 22 | return new Response($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); |
23 | 23 | } |
24 | 24 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | return new Response($e->getMessage(), $e->getStatusCode()); |
19 | 19 | } if($e instanceof \InvalidArgumentException){ |
20 | 20 | return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST); |
21 | - }else{ |
|
21 | + } else{ |
|
22 | 22 | return new Response($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); |
23 | 23 | } |
24 | 24 | } |