Fixing naming. Fixing deprecated Functionts. Adding :s for slugs as Route parameter
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Routes;
|
||||
|
||||
enum HTTPCodes: string
|
||||
{
|
||||
// Informational 1xx
|
||||
case 100 = 'Continue';
|
||||
case 101 = 'Switching Protocols';
|
||||
|
||||
// Successful 2xx
|
||||
case 200 = 'OK';
|
||||
case 201 = 'Created';
|
||||
case 202 = 'Accepted';
|
||||
case 203 = 'Non-Authoritative Information';
|
||||
case 204 = 'No Content';
|
||||
case 205 = 'Reset Content';
|
||||
case 206 = 'Partial Content';
|
||||
|
||||
// Redirection 3xx
|
||||
case 300 = 'Multiple Choices';
|
||||
case 301 = 'Moved Permanently';
|
||||
case 302 = 'Found';
|
||||
case 303 = 'See Other';
|
||||
case 304 = 'Not Modified';
|
||||
case 305 = 'Use Proxy';
|
||||
case 306 = '(Unused)';
|
||||
case 307 = 'Temporary Redirect';
|
||||
|
||||
// Client Error 4xx
|
||||
case 400 = 'Bad Request';
|
||||
case 401 = 'Unauthorized';
|
||||
case 402 = 'Payment Required';
|
||||
case 403 = 'Forbidden';
|
||||
case 404 = 'Not Found';
|
||||
case 405 = 'Method Not Allowed';
|
||||
case 406 = 'Not Acceptable';
|
||||
case 407 = 'Proxy Authentication Required';
|
||||
case 408 = 'Request Timeout';
|
||||
case 409 = 'Conflict';
|
||||
case 410 = 'Gone';
|
||||
case 411 = 'Length Required';
|
||||
case 412 = 'Precondition Failed';
|
||||
case 413 = 'Request Entity Too Large';
|
||||
case 414 = 'Request-URI Too Long';
|
||||
case 415 = 'Unsupported Media Type';
|
||||
case 416 = 'Requested Range Not Satisfiable';
|
||||
case 417 = 'Expectation Failed';
|
||||
|
||||
// Server Error 5xx
|
||||
case 500 = 'Internal Server Error';
|
||||
case 501 = 'Not Implemented';
|
||||
case 502 = 'Bad Gateway';
|
||||
case 503 = 'Service Unavailable';
|
||||
case 504 = 'Gateway Timeout';
|
||||
case 505 = 'HTTP Version Not Supported';
|
||||
}
|
||||
+19
-66
@@ -15,7 +15,7 @@ class Route
|
||||
* HTTP VERB
|
||||
*/
|
||||
|
||||
public $_verb = array();
|
||||
public $_verb = Array();
|
||||
/*
|
||||
* Execution Source
|
||||
* HTTP | Cli | SOAP |
|
||||
@@ -41,32 +41,32 @@ class Route
|
||||
/*
|
||||
* URI Segments
|
||||
*/
|
||||
public $_uriSegments = array();
|
||||
public $_uriSegments = Array();
|
||||
|
||||
/*
|
||||
* Extracted params
|
||||
*/
|
||||
public $_segments = array();
|
||||
public $_segments = Array();
|
||||
|
||||
/*
|
||||
* Prepared params
|
||||
*/
|
||||
public $_params = array();
|
||||
public $_params = Array();
|
||||
|
||||
/*
|
||||
* Execute before dispatch route
|
||||
*/
|
||||
public $_before = array();
|
||||
public $_before = Array();
|
||||
|
||||
/*
|
||||
* Route callback
|
||||
*/
|
||||
public $_callback = array();
|
||||
public $_callback = Array();
|
||||
|
||||
/*
|
||||
* Execute after route dispatched
|
||||
*/
|
||||
public $_after = array();
|
||||
public $_after = Array();
|
||||
|
||||
/*
|
||||
* Prepared RegEx
|
||||
@@ -91,63 +91,12 @@ class Route
|
||||
/*
|
||||
* Middlewares to remove from the list
|
||||
*/
|
||||
public $_middlewaresToIgnore = array();
|
||||
public $_middlewaresToIgnore = Array();
|
||||
|
||||
/*
|
||||
* From Klein
|
||||
* HTTP status List
|
||||
* Arbitrary tag on a route
|
||||
*/
|
||||
|
||||
public $_tags = [];
|
||||
|
||||
|
||||
protected static $httpMessages = array(
|
||||
// Informational 1xx
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
// Successful 2xx
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
// Redirection 3xx
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found',
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
306 => '(Unused)',
|
||||
307 => 'Temporary Redirect',
|
||||
// Client Error 4xx
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
// Server Error 5xx
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
);
|
||||
public $_tags = Array();
|
||||
|
||||
//=======================================================
|
||||
function execute()
|
||||
@@ -174,8 +123,9 @@ class Route
|
||||
|
||||
$r = new \ReflectionMethod($segments[0], $segments[1]);
|
||||
|
||||
if (sizeof($r->getParameters()) > 0 && $r->getParameters()[0]->getClass() != NULL) {
|
||||
$element = $r->getParameters()[0]->getClass()->name;
|
||||
$firstType = count($r->getParameters()) > 0 ? $r->getParameters()[0]->getType() : null;
|
||||
if ($firstType instanceof \ReflectionNamedType && !$firstType->isBuiltin()) {
|
||||
$element = $firstType->getName();
|
||||
$element = new $element;
|
||||
if (isset($this->_params['id'])) {
|
||||
$element->load($this->_params['id']);
|
||||
@@ -185,8 +135,9 @@ class Route
|
||||
$class->{$segments[1]}(...array_values($this->_params));
|
||||
} else {
|
||||
$r = new \ReflectionFunction($callback);
|
||||
if (sizeof($r->getParameters()) > 0 && $r->getParameters()[0]->getClass() != NULL) {
|
||||
$element = $r->getParameters()[0]->getClass()->name;
|
||||
$firstType = count($r->getParameters()) > 0 ? $r->getParameters()[0]->getType() : null;
|
||||
if ($firstType instanceof \ReflectionNamedType && !$firstType->isBuiltin()) {
|
||||
$element = $firstType->getName();
|
||||
$element = new $element;
|
||||
if (isset($this->_params['id'])) {
|
||||
$element->load($this->_params['id']);
|
||||
@@ -213,6 +164,8 @@ class Route
|
||||
$this->_regex .= "\/[A-z]+";
|
||||
} else if (strpos($segment, 'd:') > -1) {
|
||||
$this->_regex .= "\/[A-z0-9]+";
|
||||
} else if (strpos($segment, 's:') > -1) {
|
||||
$this->_regex .= "\/[A-z0-9\-_]+";
|
||||
} else if (strpos($segment, 'r:') > -1) {
|
||||
$this->_regex .= "\/[ -~]+";
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user