mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-08-05 07:57:38 +02:00
Merge pull request #6 from niahoo/master
Composer compatibility - thanks niahoo.
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule . index.php [L]
|
RewriteRule . index.php [L]
|
||||||
|
@@ -23,18 +23,18 @@ class AltoRouter {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function map($method, $route, $target, $name = null) {
|
public function map($method, $route, $target, $name = null) {
|
||||||
|
|
||||||
$route = $this->basePath . $route;
|
$route = $this->basePath . $route;
|
||||||
|
|
||||||
$this->routes[] = array($method, $route, $target, $name);
|
$this->routes[] = array($method, $route, $target, $name);
|
||||||
|
|
||||||
if($name) {
|
if($name) {
|
||||||
if(isset($this->namedRoutes[$name])) {
|
if(isset($this->namedRoutes[$name])) {
|
||||||
throw new \Exception("Can not redeclare route '{$name}'");
|
throw new \Exception("Can not redeclare route '{$name}'");
|
||||||
} else {
|
} else {
|
||||||
$this->namedRoutes[$name] = $route;
|
$this->namedRoutes[$name] = $route;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -61,7 +61,7 @@ class AltoRouter {
|
|||||||
$url = $route;
|
$url = $route;
|
||||||
|
|
||||||
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
|
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
|
||||||
|
|
||||||
foreach($matches as $match) {
|
foreach($matches as $match) {
|
||||||
list($block, $pre, $type, $param, $optional) = $match;
|
list($block, $pre, $type, $param, $optional) = $match;
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ class AltoRouter {
|
|||||||
$url = str_replace($block, '', $url);
|
$url = str_replace($block, '', $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,4 +222,4 @@ class AltoRouter {
|
|||||||
}
|
}
|
||||||
return "`^$route$`";
|
return "`^$route$`";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
composer.json
Normal file
23
composer.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "niahoo/altorouter",
|
||||||
|
"description": "A lightning fast router for PHP",
|
||||||
|
"keywords": ["router", "routing", "lightweight"],
|
||||||
|
"homepage": "https://github.com/niahoo/AltoRouter",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Danny van Kooten",
|
||||||
|
"email": "dannyvankooten@gmail.com",
|
||||||
|
"homepage": "http://dannyvankooten.com/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "niahoo",
|
||||||
|
"email": "dev@ooha.in"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": ["AltoRouter.php"]
|
||||||
|
}
|
||||||
|
}
|
@@ -24,4 +24,4 @@ $match = $router->match();
|
|||||||
<h3>Try these requests: </h3>
|
<h3>Try these requests: </h3>
|
||||||
<p><a href="<?php echo $router->generate('home'); ?>">GET <?php echo $router->generate('home'); ?></a></p>
|
<p><a href="<?php echo $router->generate('home'); ?>">GET <?php echo $router->generate('home'); ?></a></p>
|
||||||
<p><a href="<?php echo $router->generate('users_show', array('id' => 5)); ?>">GET <?php echo $router->generate('users_show', array('id' => 5)); ?></a></p>
|
<p><a href="<?php echo $router->generate('users_show', array('id' => 5)); ?>">GET <?php echo $router->generate('users_show', array('id' => 5)); ?></a></p>
|
||||||
<p><form action="<?php echo $router->generate('users_do', array('id' => 10, 'action' => 'update')); ?>" method="post"><button type="submit"><?php echo $router->generate('users_do', array('id' => 10, 'action' => 'update')); ?></button></form></p>
|
<p><form action="<?php echo $router->generate('users_do', array('id' => 10, 'action' => 'update')); ?>" method="post"><button type="submit"><?php echo $router->generate('users_do', array('id' => 10, 'action' => 'update')); ?></button></form></p>
|
||||||
|
Reference in New Issue
Block a user