diff --git a/source/Groundhog/Router/Route.php b/source/Groundhog/Router/Route.php index 662d026..7192689 100644 --- a/source/Groundhog/Router/Route.php +++ b/source/Groundhog/Router/Route.php @@ -185,7 +185,7 @@ public function extractParametersFromRequest(RequestInterface $request) array_shift($result); // If the result has content - if ( !empty($result) ) { + if (!empty($result)) { // Create a new array using the route parameter order as the keys and the request values as the values $result = array_combine(unserialize($this->parameter_order), array_values($result)); diff --git a/source/Groundhog/Router/RouteParserAnnotation.php b/source/Groundhog/Router/RouteParserAnnotation.php index 8f711e4..3255342 100644 --- a/source/Groundhog/Router/RouteParserAnnotation.php +++ b/source/Groundhog/Router/RouteParserAnnotation.php @@ -84,13 +84,13 @@ private function includeAllPhpFiles($root_path) // Loop through the target path and include any class files discovered foreach (new \DirectoryIterator($root_path) as $file_in_dir) { - if ( $file_in_dir->isDot() ) { + if ($file_in_dir->isDot()) { continue; - } else if ( $file_in_dir->isDir() ) { + } else if ($file_in_dir->isDir()) { $this->includeAllPhpFiles($file_in_dir->getPathName()); - } else if ( $file_in_dir->getExtension() == 'php' ) { + } else if ($file_in_dir->getExtension() == 'php') { include_once $file_in_dir->getPathName(); } } @@ -109,7 +109,7 @@ private function fetchAllDefinedConcreteClassesOfType($interface) $result = array(); foreach ($declared_classes as $class_name) { - if ( !($reflect = new \ReflectionClass($class_name)) ) { + if (!($reflect = new \ReflectionClass($class_name))) { continue; } @@ -117,7 +117,7 @@ private function fetchAllDefinedConcreteClassesOfType($interface) continue; } - if ( !in_array($interface, $reflect->getInterfaceNames()) ) { + if (!in_array($interface, $reflect->getInterfaceNames())) { continue; } @@ -143,14 +143,14 @@ private function fetchAllDefinedConcreteClassesOfType($interface) private function extractRoutesFromMethodHeader($method_comment) { // If the method has a !NoRoute annotation then its marked for being skipped. Return an empty array. - if ( preg_match('/\!NoRoute/i', $method_comment) ) { + if (preg_match('/\!NoRoute/i', $method_comment)) { return array(); } preg_match_all('/ \!HttpRoute [ \t]+ (?P[A-Za-z]+) [ \t]* (?P[^ ]*) [ \t]* $/imx', $method_comment, $regex_routes, PREG_SET_ORDER); $arr_method_routes = array(); - if ( !empty($regex_routes) ) { + if (!empty($regex_routes)) { foreach ($regex_routes as $match) { $arr_method_routes[] = array( 'request_method' => $match['request_method'], @@ -180,15 +180,15 @@ private function getRouteType($route_string) // Does the route have wildcards? $has_wildcards = (boolean) preg_match('/[#$]{1}([0-9])+/', $route_string); - if ( substr($route_string, 0, 2) == '//' ) { + if (substr($route_string, 0, 2) == '//') { // Specific domain, unspecified protocol, absolute path info $match_path = $has_wildcards ? Route::ROUTE_TYPE_ABSOLUTE_DOMAIN_WITH_WILDCARDS : Route::ROUTE_TYPE_ABSOLUTE_DOMAIN; - } else if ( substr($route_string, 0, 1) == '/' ) { + } else if (substr($route_string, 0, 1) == '/') { // Absolute path, relative to the domain root $match_path = $has_wildcards ? Route::ROUTE_TYPE_ABSOLUTE_PATH_WITH_WILDCARDS : Route::ROUTE_TYPE_ABSOLUTE_PATH; - } else if ( strpos($route_string, '://') !== false ) { + } else if (strpos($route_string, '://') !== false) { // Specific domain, specific protocol, absolute paths $match_path = $has_wildcards ? Route::ROUTE_TYPE_ABSOLUTE_PROTOCOL_WITH_WILDCARDS : Route::ROUTE_TYPE_ABSOLUTE_PROTOCOL; diff --git a/source/Groundhog/Router/RoutingTableStoreApc.php b/source/Groundhog/Router/RoutingTableStoreApc.php index d0e1c7d..30332e2 100644 --- a/source/Groundhog/Router/RoutingTableStoreApc.php +++ b/source/Groundhog/Router/RoutingTableStoreApc.php @@ -67,7 +67,7 @@ public function getRoutingTable($query_string = '') foreach ($stored_routing_table as $route) { $keeper = null; foreach (explode(' ', $query_string) as $query_fragment) { - if ( preg_match('/.*'.$query_fragment.'.*/i', $route->getRawRouteString()) || + if (preg_match('/.*'.$query_fragment.'.*/i', $route->getRawRouteString()) || preg_match('/.*'.$query_fragment.'.*/i', $route->getClassName()) || preg_match('/.*'.$query_fragment.'.*/i', $route->getRouteHttpMethod()) ) { @@ -99,17 +99,17 @@ public function findMatchingRoute(RequestInterface $request) foreach ($stored_routing_table as $route) { foreach ($arr_match_types as $route_type => $route_match) { - if ( $route->getRouteHttpMethod() == $request->getMethod() && $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) { + if ($route->getRouteHttpMethod() == $request->getMethod() && $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) { return $route; - } else if ( $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) { + } else if ($route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) { $arr_allowed_methods[] = $route->getRouteHttpMethod(); } } } // No match found - if ( !empty($arr_allowed_methods) ) { + if (!empty($arr_allowed_methods)) { // If there's a match on this URL, just not for the given HTTP method, return a 405 throw new ExceptionMethodNotAllowed($arr_allowed_methods); diff --git a/source/Groundhog/Router/RoutingTableStoreNoCache.php b/source/Groundhog/Router/RoutingTableStoreNoCache.php index 18836c0..c15975e 100644 --- a/source/Groundhog/Router/RoutingTableStoreNoCache.php +++ b/source/Groundhog/Router/RoutingTableStoreNoCache.php @@ -35,9 +35,9 @@ public function getRoutingTable($query_string = '') foreach ($this->stored_routing_table as $route) { $is_search_match = null; foreach (explode(' ', $query_string) as $query_fragment) { - if ( preg_match('/.*'.$query_fragment.'.*/i', $route->getRawRouteString()) || - preg_match('/.*'.$query_fragment.'.*/i', $route->getClassName()) || - preg_match('/.*'.$query_fragment.'.*/i', $route->getRouteHttpMethod()) + if (preg_match('/.*'.$query_fragment.'.*/i', $route->getRawRouteString()) || + preg_match('/.*'.$query_fragment.'.*/i', $route->getClassName()) || + preg_match('/.*'.$query_fragment.'.*/i', $route->getRouteHttpMethod()) ) { $is_search_match = true; } else { @@ -63,17 +63,17 @@ public function findMatchingRoute(RequestInterface $request) foreach ($this->stored_routing_table as $route) { foreach ($arr_match_types as $route_type => $route_match) { - if ( $route->getRouteHttpMethod() == $request->getMethod() && $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) { + if ($route->getRouteHttpMethod() == $request->getMethod() && $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) { return $route; - } else if ( $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) { + } else if ($route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) { $arr_allowed_methods[] = $route->getRouteHttpMethod(); } } } // No match found - if ( !empty($arr_allowed_methods) ) { + if (!empty($arr_allowed_methods)) { // If there's a match on this URL, just not for the given HTTP method, return a 405 throw new ExceptionMethodNotAllowed($arr_allowed_methods); diff --git a/source/Groundhog/Router/RoutingTableStoreSqlite.php b/source/Groundhog/Router/RoutingTableStoreSqlite.php index 5d4ab4c..bbb6d8b 100644 --- a/source/Groundhog/Router/RoutingTableStoreSqlite.php +++ b/source/Groundhog/Router/RoutingTableStoreSqlite.php @@ -65,7 +65,7 @@ class_name text, ); // Remove all the auto-generated routes - if ( ! $db->exec("DELETE FROM routing_table;") ) { + if (!$db->exec("DELETE FROM routing_table;")) { throw new Exception("Trouble truncating routing table: ".$db->lastErrorMsg()); } @@ -78,7 +78,7 @@ class_name text, "' AND route_regex='".$db->escapeString($route->getRouteRegex()). "' AND route_type='".$db->escapeString($route->getRouteType())."';" ); - if ( ($arr_result = $result->fetchArray(SQLITE3_ASSOC))!==false ) { + if (($arr_result = $result->fetchArray(SQLITE3_ASSOC))!==false) { throw new Exception( "This handler ({$route->getClassName()}) cannot handle this route ". "({$route->getRouteHttpMethod()} {$route->getRawRouteString()}) because that route's regex ". @@ -117,7 +117,7 @@ public function getRoutingTable($query_string = '') // Determine the query $where_clause = ''; - if ( !empty($query_string) ) { + if (!empty($query_string)) { $where_clause = " WHERE "; foreach (explode(' ', $query_string) as $query_fragment) { $where_clause .= "( "; @@ -134,7 +134,7 @@ public function getRoutingTable($query_string = '') // Load all the routing table records $result = $db->query($query); $routing_table = array(); - while ( $arr_result = $result->fetchArray(SQLITE3_ASSOC) ) { + while ($arr_result = $result->fetchArray(SQLITE3_ASSOC)) { $routing_table[] = new Route( $arr_result['route_type'], strtoupper($arr_result['route_http_method']), @@ -179,18 +179,18 @@ function ($str, $regex) { $arr_match = $result->fetchArray(SQLITE3_ASSOC); // if there was no perfect match, we need to find out if the URL itself was legit, in order to know whether to assemble a 405 response, or a 404 response - if ( empty($arr_match) ) { + if (empty($arr_match)) { // Determine if there were any matches at all for this URL, with any HTTP method $error_result = $db->query("SELECT route_http_method FROM routing_table WHERE (".implode(' OR ', $arr_route_path_where_clause).");"); // Fetch the set of allowed methods (if any) on this route $arr_allowed_methods = array(); - while ($arr_result = $error_result->fetchArray(SQLITE3_ASSOC) ) { + while ($arr_result = $error_result->fetchArray(SQLITE3_ASSOC)) { $arr_allowed_methods[] = $arr_result['route_http_method']; } - if ( !empty($arr_allowed_methods) ) { + if (!empty($arr_allowed_methods)) { // If there's a match on this URL, just not for the given HTTP method, return a 405 throw new ExceptionMethodNotAllowed($arr_allowed_methods);