@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | foreach ($this->table as $regex => $value) { |
151 | 151 | |
152 | - if (preg_match("/" . $regex . "/", $path, $matches)) { |
|
152 | + if (preg_match("/".$regex."/", $path, $matches)) { |
|
153 | 153 | |
154 | 154 | $this->evalUri($value['query'], $matches); |
155 | 155 | |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | |
176 | 176 | private function evalUri($parameters, $bits) { |
177 | 177 | |
178 | - $count = 0; |
|
178 | + $count = 0; |
|
179 | 179 | |
180 | 180 | foreach ($parameters as $key => $value) { |
181 | 181 | |
182 | 182 | if (isset($bits[$key])) { |
183 | 183 | |
184 | - if (preg_match('/' . $value['regex'] . '/', $bits[$key], $matches)) { |
|
184 | + if (preg_match('/'.$value['regex'].'/', $bits[$key], $matches)) { |
|
185 | 185 | |
186 | 186 | if (count($matches) == 1) $matches = $matches[0]; |
187 | 187 |
@@ -96,8 +96,9 @@ discard block |
||
96 | 96 | $this->response |
97 | 97 | ); |
98 | 98 | |
99 | + } else { |
|
100 | + return null; |
|
99 | 101 | } |
100 | - else return null; |
|
101 | 102 | |
102 | 103 | } |
103 | 104 | |
@@ -183,7 +184,9 @@ discard block |
||
183 | 184 | |
184 | 185 | if (preg_match('/' . $value['regex'] . '/', $bits[$key], $matches)) { |
185 | 186 | |
186 | - if (count($matches) == 1) $matches = $matches[0]; |
|
187 | + if (count($matches) == 1) { |
|
188 | + $matches = $matches[0]; |
|
189 | + } |
|
187 | 190 | |
188 | 191 | $this->request->query()->set($key, $matches); |
189 | 192 |
@@ -47,6 +47,11 @@ discard block |
||
47 | 47 | |
48 | 48 | private $table = array(); |
49 | 49 | |
50 | + /** |
|
51 | + * @param \Comodojo\Dispatcher\Components\Configuration $routing_table |
|
52 | + * @param \Monolog\Logger $configuration |
|
53 | + * @param \Comodojo\Cache\CacheManager $logger |
|
54 | + */ |
|
50 | 55 | public function __construct($routing_table, $configuration = null, $logger = null, $cache = null) { |
51 | 56 | |
52 | 57 | parent::__construct($configuration, $logger); |
@@ -173,6 +178,9 @@ discard block |
||
173 | 178 | |
174 | 179 | } |
175 | 180 | |
181 | + /** |
|
182 | + * @param string[] $bits |
|
183 | + */ |
|
176 | 184 | private function evalUri($parameters, $bits) { |
177 | 185 | |
178 | 186 | $count = 0; |
@@ -167,6 +167,9 @@ |
||
167 | 167 | |
168 | 168 | } |
169 | 169 | |
170 | + /** |
|
171 | + * @param string $name |
|
172 | + */ |
|
170 | 173 | private function emitServiceSpecializedEvents($name) { |
171 | 174 | |
172 | 175 | return new ServiceEvent( |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | $this->extra = new Extra($this->logger); |
87 | 87 | |
88 | - $this->router->load( $routing_table ); |
|
88 | + $this->router->load($routing_table); |
|
89 | 89 | |
90 | 90 | } |
91 | 91 | |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | |
134 | 134 | public function dispatch() { |
135 | 135 | |
136 | - $this->events->emit( new DispatcherEvent($this) ); |
|
136 | + $this->events->emit(new DispatcherEvent($this)); |
|
137 | 137 | |
138 | - if ( $this->configuration()->get('dispatcher-enabled') === false ) { |
|
138 | + if ($this->configuration()->get('dispatcher-enabled') === false) { |
|
139 | 139 | |
140 | 140 | $status = $this->configuration()->get('dispatcher-disabled-status'); |
141 | 141 | |
@@ -147,31 +147,31 @@ discard block |
||
147 | 147 | |
148 | 148 | } else { |
149 | 149 | |
150 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') ); |
|
150 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request')); |
|
151 | 151 | |
152 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get()) ); |
|
152 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method()->get())); |
|
153 | 153 | |
154 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') ); |
|
154 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#')); |
|
155 | 155 | |
156 | 156 | $this->router->route($this->request); |
157 | 157 | |
158 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') ); |
|
158 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route')); |
|
159 | 159 | |
160 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType()) ); |
|
160 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getType())); |
|
161 | 161 | |
162 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService()) ); |
|
162 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$this->router->getService())); |
|
163 | 163 | |
164 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') ); |
|
164 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#')); |
|
165 | 165 | |
166 | 166 | // translate route to service |
167 | 167 | |
168 | 168 | $this->router->compose($this->response); |
169 | 169 | |
170 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') ); |
|
170 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response')); |
|
171 | 171 | |
172 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get()) ); |
|
172 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status()->get())); |
|
173 | 173 | |
174 | - $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') ); |
|
174 | + $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#')); |
|
175 | 175 | |
176 | 176 | } |
177 | 177 |
@@ -66,8 +66,6 @@ |
||
66 | 66 | /** |
67 | 67 | * Map provided log level to level code |
68 | 68 | * |
69 | - * @param string $level |
|
70 | - * |
|
71 | 69 | * @return integer |
72 | 70 | */ |
73 | 71 | protected static function getAlgorithm($algorithm) { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | $ttl = $configuration->get('dispatcher-cache-ttl'); |
43 | 43 | |
44 | - if ( $ttl !== null && !defined('COMODOJO_CACHE_DEFAULT_TTL') ) { |
|
44 | + if ($ttl !== null && !defined('COMODOJO_CACHE_DEFAULT_TTL')) { |
|
45 | 45 | |
46 | 46 | define('COMODOJO_CACHE_DEFAULT_TTL', $ttl); |
47 | 47 | |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | |
50 | 50 | $folder = $configuration->get('dispatcher-cache-folder'); |
51 | 51 | |
52 | - $algorithm = self::getAlgorithm( $configuration->get('dispatcher-cache-algorithm') ); |
|
52 | + $algorithm = self::getAlgorithm($configuration->get('dispatcher-cache-algorithm')); |
|
53 | 53 | |
54 | - $manager = new CacheManager( $algorithm ); |
|
54 | + $manager = new CacheManager($algorithm); |
|
55 | 55 | |
56 | - if ( $enabled === true ) { |
|
56 | + if ($enabled === true) { |
|
57 | 57 | |
58 | - $manager->addProvider( new FileCache($folder) ); |
|
58 | + $manager->addProvider(new FileCache($folder)); |
|
59 | 59 | |
60 | 60 | } |
61 | 61 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | protected static function getAlgorithm($algorithm) { |
74 | 74 | |
75 | - switch ( strtoupper($algorithm) ) { |
|
75 | + switch (strtoupper($algorithm)) { |
|
76 | 76 | |
77 | 77 | case 'PICK_LAST': |
78 | 78 | $selected = CacheManager::PICK_LAST; |
@@ -33,8 +33,6 @@ |
||
33 | 33 | /** |
34 | 34 | * Create the logger |
35 | 35 | * |
36 | - * @param bool $verbose |
|
37 | - * |
|
38 | 36 | * @return \Monolog\Logger |
39 | 37 | */ |
40 | 38 | public static function create(Configuration $configuration) { |
@@ -43,19 +43,19 @@ discard block |
||
43 | 43 | |
44 | 44 | $enabled = $configuration->get('dispatcher-log-enabled'); |
45 | 45 | |
46 | - $level = self::getLevel( $configuration->get('dispatcher-log-level') ); |
|
46 | + $level = self::getLevel($configuration->get('dispatcher-log-level')); |
|
47 | 47 | |
48 | 48 | $target = $configuration->get('dispatcher-log-target'); |
49 | 49 | |
50 | 50 | $logger = new Logger($name); |
51 | 51 | |
52 | - if ( $enabled === true ) { |
|
52 | + if ($enabled === true) { |
|
53 | 53 | |
54 | - $logger->pushHandler( new StreamHandler( $target, $level) ); |
|
54 | + $logger->pushHandler(new StreamHandler($target, $level)); |
|
55 | 55 | |
56 | 56 | } else { |
57 | 57 | |
58 | - $logger->pushHandler( new NullHandler($level) ); |
|
58 | + $logger->pushHandler(new NullHandler($level)); |
|
59 | 59 | |
60 | 60 | } |
61 | 61 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | protected static function getLevel($level) { |
74 | 74 | |
75 | - switch ( strtoupper($level) ) { |
|
75 | + switch (strtoupper($level)) { |
|
76 | 76 | |
77 | 77 | case 'INFO': |
78 | 78 | $logger_level = Logger::INFO; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | //'dispatcher-autoroute' => false |
44 | 44 | ); |
45 | 45 | |
46 | - public function __construct( $configuration = array() ) { |
|
46 | + public function __construct($configuration = array()) { |
|
47 | 47 | |
48 | 48 | $this->attributes['dispatcher-base-url'] = self::urlGetAbsolute(); |
49 | 49 | |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | |
60 | 60 | $value = $this->attributes[$property]; |
61 | 61 | |
62 | - if ( preg_match_all('/%(.+?)%/', $value, $matches) ) { |
|
62 | + if (preg_match_all('/%(.+?)%/', $value, $matches)) { |
|
63 | 63 | |
64 | 64 | $substitutions = array(); |
65 | 65 | |
66 | - foreach ( $matches as $match ) { |
|
66 | + foreach ($matches as $match) { |
|
67 | 67 | |
68 | 68 | $backreference = $match[1]; |
69 | 69 | |
70 | - if ( $backreference != $property && !isset($substitutions['/%'.$backreference.'%/']) ) { |
|
70 | + if ($backreference != $property && !isset($substitutions['/%'.$backreference.'%/'])) { |
|
71 | 71 | |
72 | 72 | $substitutions['/%'.$backreference.'%/'] = $this->$backreference; |
73 | 73 | |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | |
112 | 112 | private static function urlGetAbsolute() { |
113 | 113 | |
114 | - $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://'; |
|
114 | + $http = 'http'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'; |
|
115 | 115 | |
116 | 116 | $uri = preg_replace("/\/index.php(.*?)$/i", "", $_SERVER['PHP_SELF']); |
117 | 117 | |
118 | - return ( $http . $_SERVER['HTTP_HOST'] . $uri . "/" ); |
|
118 | + return ($http.$_SERVER['HTTP_HOST'].$uri."/"); |
|
119 | 119 | |
120 | 120 | } |
121 | 121 |