Atualizar 'src/BBRouter/RouteCollection.php'
This commit is contained in:
@@ -5,27 +5,21 @@ namespace BBRouter;
|
||||
class RouteCollection {
|
||||
|
||||
private static $_route_collection;
|
||||
|
||||
public $_uri = '/';
|
||||
|
||||
public $_routes = Array();
|
||||
|
||||
private $_verb = '';
|
||||
|
||||
private $_loaded_files = Array();
|
||||
|
||||
private $_errors = Array();
|
||||
|
||||
private $_default_middlewares = Array();
|
||||
|
||||
private $_middleware_set = Array();
|
||||
private static $_verbs_whitelist = Array('*', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'CLI');
|
||||
|
||||
private static $_verbs_web = Array('GET', 'POST', 'PUT', 'PATCH', 'DELETE');
|
||||
|
||||
|
||||
//SINGLETON==============================================
|
||||
|
||||
private function __construct(){ }
|
||||
private function __construct() {
|
||||
|
||||
}
|
||||
|
||||
private static function newObj() {
|
||||
if (!isset(self::$_route_collection)) {
|
||||
@@ -40,6 +34,9 @@ class RouteCollection{
|
||||
return self::$_route_collection;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (!isset(self::$_route_collection)) {
|
||||
return self::newObj();
|
||||
@@ -47,7 +44,6 @@ class RouteCollection{
|
||||
return self::$_route_collection;
|
||||
}
|
||||
|
||||
|
||||
//HELPERS================================================
|
||||
|
||||
/*
|
||||
@@ -68,7 +64,8 @@ class RouteCollection{
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
* Load the files with the routes
|
||||
*/
|
||||
function load_routes() {
|
||||
@@ -80,7 +77,8 @@ class RouteCollection{
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
* GET | POST | PUT | PATCH | DELETE | CLI
|
||||
*
|
||||
*/
|
||||
@@ -103,7 +101,7 @@ class RouteCollection{
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function sort_routes() {
|
||||
@@ -115,8 +113,8 @@ class RouteCollection{
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Dispatch routes
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function submit() {
|
||||
global $ROUTE;
|
||||
@@ -170,6 +168,9 @@ class RouteCollection{
|
||||
|
||||
//DEFINITORS=============================================
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function get($uri, $callback, $weight = 0) {
|
||||
$route = new Route();
|
||||
$route->_verb[] = 'GET';
|
||||
@@ -184,6 +185,9 @@ class RouteCollection{
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function post($uri, $callback, $weight = 0) {
|
||||
$route = new Route();
|
||||
$route->_verb[] = 'POST';
|
||||
@@ -198,6 +202,9 @@ class RouteCollection{
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function put($uri, $callback, $weight = 0) {
|
||||
$route = new Route();
|
||||
$route->_verb[] = 'PUT';
|
||||
@@ -212,6 +219,9 @@ class RouteCollection{
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function patch($uri, $callback, $weight = 0) {
|
||||
$route = new Route();
|
||||
$route->_verb[] = 'PATCH';
|
||||
@@ -226,6 +236,9 @@ class RouteCollection{
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function delete($uri, $callback, $weight = 0) {
|
||||
$route = new Route();
|
||||
$route->_verb[] = 'DELETE';
|
||||
@@ -244,7 +257,7 @@ class RouteCollection{
|
||||
throw new Exception('Not implemented');
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function add($verb, $uri, $callback, $weight = 0) {
|
||||
@@ -268,21 +281,28 @@ class RouteCollection{
|
||||
return $route;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function addRoute(Route $route) {
|
||||
$this->_routes[] = $route;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function addMiddleware($name = '', $function){
|
||||
static function addDefaultMiddleware($name = '', $function) {
|
||||
self::getInstance()->_default_middlewares[$name] = $function;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function registerMiddleware($name = '', $function) {
|
||||
self::getInstance()->_middleware_set[$name] = $function;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static function on_http_error($function) {
|
||||
@@ -290,7 +310,7 @@ class RouteCollection{
|
||||
$instance->_errors[] = $function;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function http_error(\stdClass $info) {
|
||||
@@ -298,7 +318,6 @@ class RouteCollection{
|
||||
foreach ($this->_errors as $error) {
|
||||
call_user_func_array($error, $info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user