OSDN Git Service

PSR2 compatibility
authorManuel Dalla Lana <endelwar@aregar.it>
Fri, 25 Sep 2015 07:34:42 +0000 (09:34 +0200)
committerManuel Dalla Lana <endelwar@aregar.it>
Fri, 25 Sep 2015 07:34:42 +0000 (09:34 +0200)
also fixes makefile

README.md
composer.json
src/PHPRouter/Config.php
src/PHPRouter/Route.php
src/PHPRouter/Router.php
tests/Bootstrap.php
tests/Fixtures/SomeController.php
tests/src/PHPRouterTest/RouterTest.php

index 53382a6..d6b4fb7 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ use PHPRouter\Route;
 
 $collection = new RouteCollection();
 $collection->attachRoute(new Route('/users/', array(
-    '_controller' => 'someController::users_create',
+    '_controller' => 'someController::usersCreate',
     'methods' => 'GET'
 )));
 
index 4a52eff..44442fe 100644 (file)
   "license": "MIT",
   "authors": [
     {
-        "name": "Danny van Kooten",
-        "email": "dannyvankooten@gmail.com",
-        "homepage": "http://dannyvankooten.com/"
+      "name": "Danny van Kooten",
+      "email": "dannyvankooten@gmail.com",
+      "homepage": "http://dannyvankooten.com/"
     },
     {
-        "name": "Jefersson Nathan",
-        "email": "malukenho@phpse.net"
+      "name": "Jefersson Nathan",
+      "email": "malukenho@phpse.net"
     }
   ],
   "require": {
     "php": ">=5.3.0"
   },
   "require-dev": {
-    "phpunit/phpunit": "4.8.*"
+    "phpunit/phpunit": "4.8.*",
+    "squizlabs/php_codesniffer": "2.*"
   },
   "autoload": {
     "psr-0": {
-        "PHPRouter": "src/"
+      "PHPRouter": "src/"
     }
   }
 }
index 9ac209d..f5fab65 100644 (file)
@@ -43,7 +43,7 @@ final class Config
      */
     public static function loadFromFile($yamlFile)
     {
-        if (! is_file($yamlFile)) {
+        if (!is_file($yamlFile)) {
             throw new InvalidArgumentException(sprintf('The file %s not exists!', $yamlFile));
         }
 
index f0c056e..13cfd0c 100755 (executable)
@@ -61,7 +61,7 @@ class Route
      * @var bool
      */
     private $parametersByName;
-    
+
     /**
      * @var array
      */
@@ -73,10 +73,10 @@ class Route
      */
     public function __construct($resource, array $config)
     {
-        $this->url     = $resource;
-        $this->config  = $config;
+        $this->url = $resource;
+        $this->config = $config;
         $this->methods = isset($config['methods']) ? $config['methods'] : array();
-        $this->target  = isset($config['target'])  ? $config['target']  : null;
+        $this->target = isset($config['target']) ? $config['target'] : null;
     }
 
     public function getUrl()
@@ -129,7 +129,7 @@ class Route
     public function setFilters(array $filters, $parametersByName = false)
     {
         $this->filters = $filters;
-        
+
         if ($parametersByName) {
             $this->parametersByName = true;
         }
@@ -153,7 +153,7 @@ class Route
     {
         return $this->parameters;
     }
-    
+
     public function setParameters(array $parameters)
     {
         $this->parameters = $parameters;
@@ -163,11 +163,11 @@ class Route
     {
         $action = explode('::', $this->config['_controller']);
         $instance = new $action[0];
-        
-        if($this->parametersByName) {
-          $this->parameters = array($this->parameters);
+
+        if ($this->parametersByName) {
+            $this->parameters = array($this->parameters);
         }
-        
+
         call_user_func_array(array($instance, $action[1]), $this->parameters);
     }
 }
index 595e434..7bf7788 100755 (executable)
@@ -76,7 +76,7 @@ class Router
 
         // strip GET variables from URL
         if (($pos = strpos($requestUrl, '?')) !== false) {
-            $requestUrl =  substr($requestUrl, 0, $pos);
+            $requestUrl = substr($requestUrl, 0, $pos);
         }
 
         return $this->match($requestUrl, $requestMethod);
@@ -95,26 +95,24 @@ class Router
     public function match($requestUrl, $requestMethod = 'GET')
     {
         foreach ($this->routes->all() as $routes) {
-
             // compare server request method with route's allowed http methods
-            if (! in_array($requestMethod, (array) $routes->getMethods())) {
+            if (!in_array($requestMethod, (array)$routes->getMethods())) {
                 continue;
             }
 
             $currentDir = dirname($_SERVER['SCRIPT_NAME']);
             if ($currentDir != '/') {
-                $requestUrl = str_replace($currentDir, '', $requestUrl);    
-            }           
+                $requestUrl = str_replace($currentDir, '', $requestUrl);
+            }
 
             // check if request _url matches route regex. if not, return false.
-            if (! preg_match("@^" . $this->basePath . $routes->getRegex() . "*$@i", $requestUrl, $matches)) {
+            if (!preg_match("@^" . $this->basePath . $routes->getRegex() . "*$@i", $requestUrl, $matches)) {
                 continue;
             }
 
             $params = array();
 
             if (preg_match_all("/:([\w-%]+)/", $routes->getUrl(), $argument_keys)) {
-
                 // grab array with matches
                 $argument_keys = $argument_keys[1];
 
@@ -149,7 +147,7 @@ class Router
     public function generate($routeName, array $params = array())
     {
         // Check if route exists
-        if (! isset($this->namedRoutes[$routeName])) {
+        if (!isset($this->namedRoutes[$routeName])) {
             throw new Exception("No route with the name $routeName has been found.");
         }
 
index bb66914..cf4d0b3 100644 (file)
@@ -23,3 +23,4 @@ if (function_exists('date_default_timezone_set') && function_exists('date_defaul
 }
 
 require_once __DIR__ . '/../vendor/autoload.php';
+require __DIR__ . '/Fixtures/SomeController.php';
index 06791d4..c92c817 100644 (file)
@@ -19,7 +19,7 @@ namespace PHPRouter\Test;
 
 final class SomeController
 {
-    public function users_create()
+    public function usersCreate()
     {
     }
 
index d86a37d..e537db3 100644 (file)
@@ -17,8 +17,6 @@
  */
 namespace PHPRouterTest\Test;
 
-require __DIR__ . '/../../Fixtures/SomeController.php';
-
 use PHPRouter\Route;
 use PHPRouter\Router;
 use PHPRouter\RouteCollection;
@@ -50,7 +48,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
     {
         $collection = new RouteCollection();
         $collection->attach(new Route('/users/', array(
-            '_controller' => 'PHPRouter\Test\SomeController::users_create',
+            '_controller' => 'PHPRouter\Test\SomeController::usersCreate',
             'methods' => 'GET'
         )));
 
@@ -130,7 +128,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
     {
         $collection = new RouteCollection();
         $collection->attachRoute(new Route('/users/', array(
-            '_controller' => 'PHPRouter\Test\SomeController::users_create',
+            '_controller' => 'PHPRouter\Test\SomeController::usersCreate',
             'methods' => 'GET'
         )));
         $collection->attachRoute(new Route('/user/:id', array(