$collection = new RouteCollection();
$collection->attachRoute(new Route('/users/', array(
- '_controller' => 'someController::users_create',
+ '_controller' => 'someController::usersCreate',
'methods' => 'GET'
)));
"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/"
}
}
}
*/
public static function loadFromFile($yamlFile)
{
- if (! is_file($yamlFile)) {
+ if (!is_file($yamlFile)) {
throw new InvalidArgumentException(sprintf('The file %s not exists!', $yamlFile));
}
* @var bool
*/
private $parametersByName;
-
+
/**
* @var array
*/
*/
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()
public function setFilters(array $filters, $parametersByName = false)
{
$this->filters = $filters;
-
+
if ($parametersByName) {
$this->parametersByName = true;
}
{
return $this->parameters;
}
-
+
public function setParameters(array $parameters)
{
$this->parameters = $parameters;
{
$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);
}
}
// 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);
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];
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.");
}
}
require_once __DIR__ . '/../vendor/autoload.php';
+require __DIR__ . '/Fixtures/SomeController.php';
final class SomeController
{
- public function users_create()
+ public function usersCreate()
{
}
*/
namespace PHPRouterTest\Test;
-require __DIR__ . '/../../Fixtures/SomeController.php';
-
use PHPRouter\Route;
use PHPRouter\Router;
use PHPRouter\RouteCollection;
{
$collection = new RouteCollection();
$collection->attach(new Route('/users/', array(
- '_controller' => 'PHPRouter\Test\SomeController::users_create',
+ '_controller' => 'PHPRouter\Test\SomeController::usersCreate',
'methods' => 'GET'
)));
{
$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(