1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-08-08 01:16:47 +02:00

added composer.json and newlines in end of files

This commit is contained in:
niahoo
2013-03-06 11:09:46 +01:00
parent ad87a4ae3a
commit fe4d390f0c
4 changed files with 29 additions and 10 deletions

View File

@@ -1,3 +1,3 @@
RewriteEngine On RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 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) { 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$`";
} }
} }

19
composer.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "altorouter/altorouter",
"description": "A lightning fast router for PHP",
"keywords": ["router", "routing", "lightweight"],
"homepage": "https://github.com/dannyvankooten/AltoRouter",
"authors": [
{
"name": "Danny van Kooten",
"email": "dannyvankooten@gmail.com",
"homepage": "http://dannyvankooten.com/"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"files": ["AltoRouter.php"]
}
}

View File

@@ -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>