@@ -21,11 +21,11 @@ |
||
21 | 21 | */ |
22 | 22 | public static function factory($typeResponse, Request $request, Response $response) |
23 | 23 | { |
24 | - if(is_bool($typeResponse)) { |
|
25 | - return $response->setContent((string)$typeResponse)->send(); |
|
24 | + if (is_bool($typeResponse)) { |
|
25 | + return $response->setContent((string) $typeResponse)->send(); |
|
26 | 26 | } |
27 | 27 | $baseResponse = RouteResponse::create($typeResponse); |
28 | - if(is_array($typeResponse)) { |
|
28 | + if (is_array($typeResponse)) { |
|
29 | 29 | return (new JsonResponse($baseResponse, $request, $response))->render(); |
30 | 30 | } |
31 | 31 | return (new TextPlainResponse($baseResponse, $request, $response))->render(); |
@@ -20,7 +20,7 @@ |
||
20 | 20 | */ |
21 | 21 | public static function getContainer(): Container |
22 | 22 | { |
23 | - if( null === self::$instance) { |
|
23 | + if (null === self::$instance) { |
|
24 | 24 | $container = new Container(); |
25 | 25 | $container->addServiceProvider(new RouteServiceProvider()); |
26 | 26 | self::$instance = $container; |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | public function getRoute() |
133 | 133 | { |
134 | 134 | return [ |
135 | - 'name' => $this->getName(), |
|
136 | - 'path' => $this->getUrl(), |
|
137 | - 'callable' => $this->getCallable(), |
|
138 | - 'parameters' => self::resolveParameters() |
|
135 | + 'name' => $this->getName(), |
|
136 | + 'path' => $this->getUrl(), |
|
137 | + 'callable' => $this->getCallable(), |
|
138 | + 'parameters' => self::resolveParameters() |
|
139 | 139 | ]; |
140 | 140 | } |
141 | 141 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function getRequest(): Request |
148 | 148 | { |
149 | - return $this->request; |
|
149 | + return $this->request; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function getResponse(): Response |
158 | 158 | { |
159 | - return $this->response; |
|
159 | + return $this->response; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | $url = trim($url, '/'); |
65 | 65 | $path = preg_replace_callback('#:([\w]+)#', [$this, 'attributesMatch'], $this->getUrl()); |
66 | - if(!preg_match("#^$path$#i", $url, $matches)) { |
|
66 | + if (!preg_match("#^$path$#i", $url, $matches)) { |
|
67 | 67 | return false; |
68 | 68 | } |
69 | 69 | array_shift($matches); |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * @return string |
79 | 79 | */ |
80 | 80 | private function attributesMatch($match) { |
81 | - if(isset(self::$attributes[$match[1]])) { |
|
82 | - return '(' . self::$attributes[$match[1]] . ')'; |
|
81 | + if (isset(self::$attributes[$match[1]])) { |
|
82 | + return '('.self::$attributes[$match[1]].')'; |
|
83 | 83 | } |
84 | 84 | return '([^/]+)'; |
85 | 85 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function run() |
197 | 197 | { |
198 | - if(is_string($this->getCallable())) { |
|
198 | + if (is_string($this->getCallable())) { |
|
199 | 199 | return $this->handleRequestController(); |
200 | 200 | } |
201 | 201 | return $this->handleRequestCallable(); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | protected static function getPointersAndReturnRequired(int $position) |
62 | 62 | { |
63 | - return self::$parameters[ array_flip( self::$numberOfParameters)[$position] ]; |
|
63 | + return self::$parameters[array_flip(self::$numberOfParameters)[$position]]; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,16 +71,16 @@ discard block |
||
71 | 71 | { |
72 | 72 | $attributes = []; |
73 | 73 | $parameters = self::getParametersObject(); |
74 | - if(count($parameters) > 0) { |
|
74 | + if (count($parameters) > 0) { |
|
75 | 75 | foreach ($parameters as $parameter) { |
76 | 76 | /** @var \ReflectionParameter $parameter */ |
77 | - if(!$parameter->getClass()) { |
|
77 | + if (!$parameter->getClass()) { |
|
78 | 78 | self::$numberOfParameters[] = $parameter->getPosition(); |
79 | 79 | $attributes[$parameter->getPosition()] = self::getPointersAndReturnRequired($parameter->getPosition()); |
80 | 80 | continue; |
81 | 81 | } |
82 | 82 | $className = $parameter->getClass()->getName(); |
83 | - if(self::checkClassRegisterContainer($className)) { |
|
83 | + if (self::checkClassRegisterContainer($className)) { |
|
84 | 84 | $attributes[$parameter->getPosition()] = Kernel::getContainer()->get($className); |
85 | 85 | } |
86 | 86 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | protected static function checkClassRegisterContainer(string $className) |
98 | 98 | { |
99 | - if(!Kernel::getContainer()->has($className)) { |
|
99 | + if (!Kernel::getContainer()->has($className)) { |
|
100 | 100 | throw new ContainerException("Class [{$className}] not registered in the container."); |
101 | 101 | } |
102 | 102 | return true; |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | */ |
110 | 110 | protected static function getParametersObject() |
111 | 111 | { |
112 | - if( self::$reflectionObject instanceof \ReflectionClass) { |
|
112 | + if (self::$reflectionObject instanceof \ReflectionClass) { |
|
113 | 113 | $method = self::$reflectionObject->getMethod(self::$resolveMethodName); |
114 | 114 | return $method->getParameters(); |
115 | 115 | } |
116 | - if ( self::$reflectionObject instanceof \ReflectionFunction) { |
|
116 | + if (self::$reflectionObject instanceof \ReflectionFunction) { |
|
117 | 117 | return self::$reflectionObject->getParameters(); |
118 | 118 | } |
119 | 119 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function uri() : string |
102 | 102 | { |
103 | - return trim(strtok( $_SERVER['REQUEST_URI'], '?'), '/'); |
|
103 | + return trim(strtok($_SERVER['REQUEST_URI'], '?'), '/'); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | */ |
121 | 121 | protected function checkCommonProblems() |
122 | 122 | { |
123 | - if(static::hasRouteValid()) { |
|
123 | + if (static::hasRouteValid()) { |
|
124 | 124 | return false; |
125 | 125 | } |
126 | - if(empty( $this->routeStack)) { |
|
126 | + if (empty($this->routeStack)) { |
|
127 | 127 | throw new \InvalidArgumentException('Routing empty'); |
128 | 128 | } |
129 | - if(!isset($this->routeStack[static::method()])) { |
|
129 | + if (!isset($this->routeStack[static::method()])) { |
|
130 | 130 | throw new MethodNotAllowedException('Requested method was not scaled.'); |
131 | 131 | } |
132 | 132 | return true; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | { |
146 | 146 | $route = new Route($path, $callable); |
147 | 147 | $this->routeStack[$method][] = $route; |
148 | - if($name) { |
|
148 | + if ($name) { |
|
149 | 149 | $this->routesGroupByName[$name] = $route; |
150 | 150 | } |
151 | 151 | return $route; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | { |
161 | 161 | foreach ($this->routeStack[static::method()] as $key => $route) { |
162 | 162 | /** @var $route Route */ |
163 | - if($route->extractParameters(static::uri())) { |
|
163 | + if ($route->extractParameters(static::uri())) { |
|
164 | 164 | return $route->run(); |
165 | 165 | } |
166 | 166 | } |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function goUrl($name, $params = []) |
179 | 179 | { |
180 | - if(!isset($this->routesGroupByName[$name])) { |
|
181 | - throw new UnregisteredRouteException('Unregistered route by name ' . $name); |
|
180 | + if (!isset($this->routesGroupByName[$name])) { |
|
181 | + throw new UnregisteredRouteException('Unregistered route by name '.$name); |
|
182 | 182 | } |
183 | 183 | /** @var Route $route */ |
184 | 184 | $route = $this->routesGroupByName[$name]; |