Commit 40ea2ef9 by yeran

update router

1 parent 4a38fd80
Showing with 44 additions and 2 deletions
......@@ -3,7 +3,7 @@
"description": "Phalcon",
"keywords": ["phwoolcon"],
"type": "library",
"version": "1.0.5",
"version": "1.0.6",
"license": "proprietary",
"authors": [
{
......@@ -24,7 +24,8 @@
"ext-mbstring": "*",
"symfony/console": "~3.0",
"pda/pheanstalk": "~3.1",
"swiftmailer/swiftmailer": "~5.4|~6.0"
"swiftmailer/swiftmailer": "~5.4|~6.0",
"opis/closure": "3.0.1"
},
"require-dev": {
},
......
......@@ -13,6 +13,7 @@ use Phwoolcon\Exception\Http\ApiException;
use Phwoolcon\Exception\Http\CsrfException;
use Phwoolcon\Exception\Http\NotFoundException;
use Phwoolcon\Exception\HttpException;
use Opis\Closure\SerializableClosure;
/**
* Class Router
......@@ -91,6 +92,46 @@ class Router extends PhalconRouter implements ServiceAwareInterface
$this->response->setStatusCode(200);
}
public function addRoutes(array $routes)
{
foreach ($routes as $route) {
if (!$route[2] instanceof Closure) {
$pattern = $route[1];
$paths = $route[2];
$method = $route[0];
$filter = empty($route[3]) ? null : $route[3];
$this->quickAdd($pattern, $paths, $method, $filter);
} else {
$pattern = $route[1];
$function = $route[2];
$method = $route[0];
$filter = empty($route[3]) ? null : $route[3];
$this->CquickAdd($pattern, $function, $method, $filter);
}
}
}
public function quickAdd($pattern, $paths, $method, $filter = null)
{
$method == 'ANY' and $method = null;
$method == 'GET' and $method = ['GET', 'HEAD'];
$route = $this->add($pattern, $paths, $method);
is_callable($filter) or $filter = null;
$filter and $route->beforeMatch($filter);
return $route;
}
public function CquickAdd($pattern, $function, $method, $filter = null)
{
$method == 'ANY' and $method = null;
$method == 'GET' and $method = ['GET', 'HEAD'];
$handler['controller'] = new SerializableClosure($function);
$route = $this->add($pattern, $handler, $method);
is_callable($filter) or $filter = null;
$filter and $route->beforeMatch($filter);
return $route;
}
public static function checkCsrfToken()
{
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!