@@ -36,9 +36,9 @@ |
||
36 | 36 | protected const DIRECTIVES = []; |
37 | 37 | |
38 | 38 | /** |
39 | - * @param Template $document |
|
40 | - * @return string |
|
41 | - */ |
|
39 | + * @param Template $document |
|
40 | + * @return string |
|
41 | + */ |
|
42 | 42 | protected function compile(Template $document): string |
43 | 43 | { |
44 | 44 | $compiler = new Compiler(); |
@@ -42,12 +42,12 @@ |
||
42 | 42 | protected function compile(Template $document): string |
43 | 43 | { |
44 | 44 | $compiler = new Compiler(); |
45 | - foreach (static::RENDERS as $renderer) { |
|
45 | + foreach (static::RENDERS as $renderer){ |
|
46 | 46 | $compiler->addRenderer(new $renderer()); |
47 | 47 | } |
48 | 48 | |
49 | 49 | $directiveGroup = new DirectiveGroup(); |
50 | - foreach (static::DIRECTIVES as $directive) { |
|
50 | + foreach (static::DIRECTIVES as $directive){ |
|
51 | 51 | $directiveGroup->addDirective(new $directive()); |
52 | 52 | } |
53 | 53 |
@@ -42,12 +42,14 @@ |
||
42 | 42 | protected function compile(Template $document): string |
43 | 43 | { |
44 | 44 | $compiler = new Compiler(); |
45 | - foreach (static::RENDERS as $renderer) { |
|
45 | + foreach (static::RENDERS as $renderer) |
|
46 | + { |
|
46 | 47 | $compiler->addRenderer(new $renderer()); |
47 | 48 | } |
48 | 49 | |
49 | 50 | $directiveGroup = new DirectiveGroup(); |
50 | - foreach (static::DIRECTIVES as $directive) { |
|
51 | + foreach (static::DIRECTIVES as $directive) |
|
52 | + { |
|
51 | 53 | $directiveGroup->addDirective(new $directive()); |
52 | 54 | } |
53 | 55 |
@@ -30,7 +30,7 @@ |
||
30 | 30 | { |
31 | 31 | $parser = new Parser(); |
32 | 32 | |
33 | - foreach (static::GRAMMARS as $grammar => $syntax) { |
|
33 | + foreach (static::GRAMMARS as $grammar => $syntax){ |
|
34 | 34 | $parser->addSyntax(new $grammar(), new $syntax()); |
35 | 35 | } |
36 | 36 |
@@ -30,7 +30,8 @@ |
||
30 | 30 | { |
31 | 31 | $parser = new Parser(); |
32 | 32 | |
33 | - foreach (static::GRAMMARS as $grammar => $syntax) { |
|
33 | + foreach (static::GRAMMARS as $grammar => $syntax) |
|
34 | + { |
|
34 | 35 | $parser->addSyntax(new $grammar(), new $syntax()); |
35 | 36 | } |
36 | 37 |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | AnnotationRegistry::registerLoader('class_exists'); |
68 | 68 | |
69 | 69 | $schema = $this->memory->loadData(self::MEMORY_SECTION); |
70 | - if (empty($schema) || !$cached) { |
|
70 | + if (empty($schema) || !$cached){ |
|
71 | 71 | $schema = $locator->findDeclarations(); |
72 | 72 | $this->memory->saveData(self::MEMORY_SECTION, $schema); |
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->configureRoutes($schema); |
76 | 76 | |
77 | - foreach ($this->groups as $group) { |
|
77 | + foreach ($this->groups as $group){ |
|
78 | 78 | $group->flushRoutes(); |
79 | 79 | } |
80 | 80 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | private function configureRoutes(array $routes): void |
94 | 94 | { |
95 | - foreach ($routes as $name => $schema) { |
|
95 | + foreach ($routes as $name => $schema){ |
|
96 | 96 | $this->groups |
97 | 97 | ->getGroup($schema['group']) |
98 | 98 | ->registerRoute( |
@@ -67,14 +67,16 @@ discard block |
||
67 | 67 | AnnotationRegistry::registerLoader('class_exists'); |
68 | 68 | |
69 | 69 | $schema = $this->memory->loadData(self::MEMORY_SECTION); |
70 | - if (empty($schema) || !$cached) { |
|
70 | + if (empty($schema) || !$cached) |
|
71 | + { |
|
71 | 72 | $schema = $locator->findDeclarations(); |
72 | 73 | $this->memory->saveData(self::MEMORY_SECTION, $schema); |
73 | 74 | } |
74 | 75 | |
75 | 76 | $this->configureRoutes($schema); |
76 | 77 | |
77 | - foreach ($this->groups as $group) { |
|
78 | + foreach ($this->groups as $group) |
|
79 | + { |
|
78 | 80 | $group->flushRoutes(); |
79 | 81 | } |
80 | 82 | } |
@@ -92,7 +94,8 @@ discard block |
||
92 | 94 | */ |
93 | 95 | private function configureRoutes(array $routes): void |
94 | 96 | { |
95 | - foreach ($routes as $name => $schema) { |
|
97 | + foreach ($routes as $name => $schema) |
|
98 | + { |
|
96 | 99 | $this->groups |
97 | 100 | ->getGroup($schema['group']) |
98 | 101 | ->registerRoute( |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | ContainerInterface $container, |
51 | 51 | RouterInterface $router, |
52 | 52 | Pipeline $pipeline |
53 | - ) { |
|
53 | + ){ |
|
54 | 54 | $this->container = $container; |
55 | 55 | $this->router = $router; |
56 | 56 | $this->pipeline = $pipeline; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function setCore($core): self |
80 | 80 | { |
81 | - if (!$core instanceof CoreInterface) { |
|
81 | + if (!$core instanceof CoreInterface){ |
|
82 | 82 | $core = $this->container->get($core); |
83 | 83 | } |
84 | 84 | $this->core = $core; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function addMiddleware($middleware): self |
97 | 97 | { |
98 | - if (!$middleware instanceof MiddlewareInterface) { |
|
98 | + if (!$middleware instanceof MiddlewareInterface){ |
|
99 | 99 | $middleware = $this->container->get($middleware); |
100 | 100 | } |
101 | 101 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | array $verbs, |
127 | 127 | array $defaults, |
128 | 128 | array $middleware |
129 | - ) { |
|
129 | + ){ |
|
130 | 130 | $this->routes[$name] = [ |
131 | 131 | 'pattern' => $pattern, |
132 | 132 | 'controller' => $controller, |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function flushRoutes() |
144 | 144 | { |
145 | - foreach ($this->routes as $name => $schema) { |
|
145 | + foreach ($this->routes as $name => $schema){ |
|
146 | 146 | $route = $this->createRoute($schema['pattern'], $schema['controller'], $schema['action']); |
147 | 147 | |
148 | - if ($schema['defaults'] !== []) { |
|
148 | + if ($schema['defaults'] !== []){ |
|
149 | 149 | $route = $route->withDefaults($schema['defaults']); |
150 | 150 | } |
151 | 151 | |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | public function createRoute(string $pattern, string $controller, string $action): Route |
166 | 166 | { |
167 | 167 | $action = new Action($controller, $action); |
168 | - if ($this->core !== null) { |
|
168 | + if ($this->core !== null){ |
|
169 | 169 | $action = $action->withCore($this->core); |
170 | 170 | } |
171 | 171 | |
172 | - $route = new Route($this->prefix . $pattern, $action); |
|
172 | + $route = new Route($this->prefix.$pattern, $action); |
|
173 | 173 | |
174 | 174 | // all routes within group share the same middleware pipeline |
175 | 175 | $route = $route->withMiddleware($this->pipeline); |
@@ -78,7 +78,8 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function setCore($core): self |
80 | 80 | { |
81 | - if (!$core instanceof CoreInterface) { |
|
81 | + if (!$core instanceof CoreInterface) |
|
82 | + { |
|
82 | 83 | $core = $this->container->get($core); |
83 | 84 | } |
84 | 85 | $this->core = $core; |
@@ -95,7 +96,8 @@ discard block |
||
95 | 96 | */ |
96 | 97 | public function addMiddleware($middleware): self |
97 | 98 | { |
98 | - if (!$middleware instanceof MiddlewareInterface) { |
|
99 | + if (!$middleware instanceof MiddlewareInterface) |
|
100 | + { |
|
99 | 101 | $middleware = $this->container->get($middleware); |
100 | 102 | } |
101 | 103 | |
@@ -142,10 +144,12 @@ discard block |
||
142 | 144 | */ |
143 | 145 | public function flushRoutes() |
144 | 146 | { |
145 | - foreach ($this->routes as $name => $schema) { |
|
147 | + foreach ($this->routes as $name => $schema) |
|
148 | + { |
|
146 | 149 | $route = $this->createRoute($schema['pattern'], $schema['controller'], $schema['action']); |
147 | 150 | |
148 | - if ($schema['defaults'] !== []) { |
|
151 | + if ($schema['defaults'] !== []) |
|
152 | + { |
|
149 | 153 | $route = $route->withDefaults($schema['defaults']); |
150 | 154 | } |
151 | 155 | |
@@ -165,7 +169,8 @@ discard block |
||
165 | 169 | public function createRoute(string $pattern, string $controller, string $action): Route |
166 | 170 | { |
167 | 171 | $action = new Action($controller, $action); |
168 | - if ($this->core !== null) { |
|
172 | + if ($this->core !== null) |
|
173 | + { |
|
169 | 174 | $action = $action->withCore($this->core); |
170 | 175 | } |
171 | 176 |
@@ -33,7 +33,8 @@ |
||
33 | 33 | public function findDeclarations(): array |
34 | 34 | { |
35 | 35 | $result = []; |
36 | - foreach ($this->locator->findMethods(RouteAnnotation::class) as $match) { |
|
36 | + foreach ($this->locator->findMethods(RouteAnnotation::class) as $match) |
|
37 | + { |
|
37 | 38 | /** @var RouteAnnotation $route */ |
38 | 39 | $route = $match->getAnnotation(); |
39 | 40 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function findDeclarations(): array |
34 | 34 | { |
35 | 35 | $result = []; |
36 | - foreach ($this->locator->findMethods(RouteAnnotation::class) as $match) { |
|
36 | + foreach ($this->locator->findMethods(RouteAnnotation::class) as $match){ |
|
37 | 37 | /** @var RouteAnnotation $route */ |
38 | 38 | $route = $match->getAnnotation(); |
39 | 39 | |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | 'controller' => $match->getClass()->getName(), |
43 | 43 | 'action' => $match->getMethod()->getName(), |
44 | 44 | 'group' => $route->group, |
45 | - 'verbs' => (array) $route->methods, |
|
45 | + 'verbs' => (array)$route->methods, |
|
46 | 46 | 'defaults' => $route->defaults, |
47 | - 'middleware' => (array) $route->middleware, |
|
47 | + 'middleware' => (array)$route->middleware, |
|
48 | 48 | ]; |
49 | 49 | } |
50 | 50 |
@@ -39,7 +39,7 @@ |
||
39 | 39 | */ |
40 | 40 | public function getGroup(string $name): RouteGroup |
41 | 41 | { |
42 | - if (!isset($this->groups[$name])) { |
|
42 | + if (!isset($this->groups[$name])){ |
|
43 | 43 | $this->groups[$name] = $this->factory->make(RouteGroup::class); |
44 | 44 | } |
45 | 45 |
@@ -39,7 +39,8 @@ |
||
39 | 39 | */ |
40 | 40 | public function getGroup(string $name): RouteGroup |
41 | 41 | { |
42 | - if (!isset($this->groups[$name])) { |
|
42 | + if (!isset($this->groups[$name])) |
|
43 | + { |
|
43 | 44 | $this->groups[$name] = $this->factory->make(RouteGroup::class); |
44 | 45 | } |
45 | 46 |
@@ -25,8 +25,8 @@ |
||
25 | 25 | protected function makeApp(array $env): App |
26 | 26 | { |
27 | 27 | $config = [ |
28 | - 'root' => __DIR__ . '/App', |
|
29 | - 'app' => __DIR__ . '/App', |
|
28 | + 'root' => __DIR__.'/App', |
|
29 | + 'app' => __DIR__.'/App', |
|
30 | 30 | ]; |
31 | 31 | |
32 | 32 | return App::init($config, new Environment($env), false); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | array $headers = [] |
52 | 52 | ): ResponseInterface { |
53 | 53 | $r = $this->request($uri, 'GET', [], $headers, []); |
54 | - foreach ($attributes as $k => $v) { |
|
54 | + foreach ($attributes as $k => $v){ |
|
55 | 55 | $r = $r->withAttribute($k, $v); |
56 | 56 | } |
57 | 57 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | public function fetchCookies(array $header) |
96 | 96 | { |
97 | 97 | $result = []; |
98 | - foreach ($header as $line) { |
|
98 | + foreach ($header as $line){ |
|
99 | 99 | $cookie = explode('=', $line); |
100 | 100 | $result[$cookie[0]] = rawurldecode(substr($cookie[1], 0, strpos($cookie[1], ';'))); |
101 | 101 | } |
@@ -51,7 +51,8 @@ discard block |
||
51 | 51 | array $headers = [] |
52 | 52 | ): ResponseInterface { |
53 | 53 | $r = $this->request($uri, 'GET', [], $headers, []); |
54 | - foreach ($attributes as $k => $v) { |
|
54 | + foreach ($attributes as $k => $v) |
|
55 | + { |
|
55 | 56 | $r = $r->withAttribute($k, $v); |
56 | 57 | } |
57 | 58 | |
@@ -95,7 +96,8 @@ discard block |
||
95 | 96 | public function fetchCookies(array $header) |
96 | 97 | { |
97 | 98 | $result = []; |
98 | - foreach ($header as $line) { |
|
99 | + foreach ($header as $line) |
|
100 | + { |
|
99 | 101 | $cookie = explode('=', $line); |
100 | 102 | $result[$cookie[0]] = rawurldecode(substr($cookie[1], 0, strpos($cookie[1], ';'))); |
101 | 103 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php return array ( |
2 | - 'index' => |
|
3 | - array ( |
|
2 | + 'index' => |
|
3 | + array ( |
|
4 | 4 | 'pattern' => '/', |
5 | 5 | 'controller' => 'Spiral\\Tests\\Router\\App\\Controller\\HomeController', |
6 | 6 | 'action' => 'index', |
7 | 7 | 'group' => 'default', |
8 | 8 | 'verbs' => |
9 | 9 | array ( |
10 | - 0 => 'GET', |
|
10 | + 0 => 'GET', |
|
11 | 11 | ), |
12 | 12 | 'defaults' => |
13 | 13 | array ( |
@@ -15,16 +15,16 @@ discard block |
||
15 | 15 | 'middleware' => |
16 | 16 | array ( |
17 | 17 | ), |
18 | - ), |
|
19 | - 'method' => |
|
20 | - array ( |
|
18 | + ), |
|
19 | + 'method' => |
|
20 | + array ( |
|
21 | 21 | 'pattern' => '/', |
22 | 22 | 'controller' => 'Spiral\\Tests\\Router\\App\\Controller\\HomeController', |
23 | 23 | 'action' => 'method', |
24 | 24 | 'group' => 'default', |
25 | 25 | 'verbs' => |
26 | 26 | array ( |
27 | - 0 => 'POST', |
|
27 | + 0 => 'POST', |
|
28 | 28 | ), |
29 | 29 | 'defaults' => |
30 | 30 | array ( |
@@ -32,5 +32,5 @@ discard block |
||
32 | 32 | 'middleware' => |
33 | 33 | array ( |
34 | 34 | ), |
35 | - ), |
|
35 | + ), |
|
36 | 36 | ); |
37 | 37 | \ No newline at end of file |
@@ -1,36 +1,36 @@ |
||
1 | -<?php return array ( |
|
1 | +<?php return array( |
|
2 | 2 | 'index' => |
3 | - array ( |
|
3 | + array( |
|
4 | 4 | 'pattern' => '/', |
5 | 5 | 'controller' => 'Spiral\\Tests\\Router\\App\\Controller\\HomeController', |
6 | 6 | 'action' => 'index', |
7 | 7 | 'group' => 'default', |
8 | 8 | 'verbs' => |
9 | - array ( |
|
9 | + array( |
|
10 | 10 | 0 => 'GET', |
11 | 11 | ), |
12 | 12 | 'defaults' => |
13 | - array ( |
|
13 | + array( |
|
14 | 14 | ), |
15 | 15 | 'middleware' => |
16 | - array ( |
|
16 | + array( |
|
17 | 17 | ), |
18 | 18 | ), |
19 | 19 | 'method' => |
20 | - array ( |
|
20 | + array( |
|
21 | 21 | 'pattern' => '/', |
22 | 22 | 'controller' => 'Spiral\\Tests\\Router\\App\\Controller\\HomeController', |
23 | 23 | 'action' => 'method', |
24 | 24 | 'group' => 'default', |
25 | 25 | 'verbs' => |
26 | - array ( |
|
26 | + array( |
|
27 | 27 | 0 => 'POST', |
28 | 28 | ), |
29 | 29 | 'defaults' => |
30 | - array ( |
|
30 | + array( |
|
31 | 31 | ), |
32 | 32 | 'middleware' => |
33 | - array ( |
|
33 | + array( |
|
34 | 34 | ), |
35 | 35 | ), |
36 | 36 | ); |
37 | 37 | \ No newline at end of file |