1
0
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:
Danny van Kooten
2013-03-18 06:57:52 -07:00
4 changed files with 33 additions and 10 deletions

View File

@@ -1,3 +1,3 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
RewriteRule . index.php [L]

View File

@@ -23,18 +23,18 @@ class AltoRouter {
*
*/
public function map($method, $route, $target, $name = null) {
$route = $this->basePath . $route;
$this->routes[] = array($method, $route, $target, $name);
if($name) {
if(isset($this->namedRoutes[$name])) {
throw new \Exception("Can not redeclare route '{$name}'");
if(isset($this->namedRoutes[$name])) {
throw new \Exception("Can not redeclare route '{$name}'");
} else {
$this->namedRoutes[$name] = $route;
}
}
return;
@@ -61,7 +61,7 @@ class AltoRouter {
$url = $route;
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
list($block, $pre, $type, $param, $optional) = $match;
@@ -75,7 +75,7 @@ class AltoRouter {
$url = str_replace($block, '', $url);
}
}
}
@@ -222,4 +222,4 @@ class AltoRouter {
}
return "`^$route$`";
}
}
}

23
composer.json Normal file
View 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"]
}
}

View File

@@ -24,4 +24,4 @@ $match = $router->match();
<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('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>