-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added Profiler to Debugger - Routes now are defined by a config file stored in the directory /routes - Added the Service class
- Loading branch information
Fariz Luqman
committed
Jan 20, 2017
1 parent
35d2aeb
commit cb5ed16
Showing
19 changed files
with
143 additions
and
32 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,24 +26,19 @@ | |
* @author Studio Nexus <[email protected]> | ||
* @copyright 2016 Studio Nexus | ||
* @license MIT | ||
* @version Release: 0.2.0 | ||
* @version Release: 0.3.0 | ||
* @link https://www.studionexus.co/php/damnstupidsimple | ||
*/ | ||
namespace Core; | ||
|
||
/** | ||
* Routing System | ||
* ----------------------------------------------------------------------- | ||
* | ||
* @method static Macaw get(string $route, Callable $callback) | ||
* @method static Macaw post(string $route, Callable $callback) | ||
* @method static Macaw put(string $route, Callable $callback) | ||
* @method static Macaw delete(string $route, Callable $callback) | ||
* @method static Macaw options(string $route, Callable $callback) | ||
* @method static Macaw head(string $route, Callable $callback) | ||
* | ||
*/ | ||
class Router { | ||
/** | ||
* The configurations | ||
* @var array | ||
* @access private | ||
* @static | ||
*/ | ||
static private $config = null; | ||
public static $halts = false; | ||
public static $routes = array(); | ||
public static $methods = array(); | ||
|
@@ -64,6 +59,20 @@ public static function __callstatic($method, $params) { | |
array_push(self::$methods, strtoupper($method)); | ||
array_push(self::$callbacks, $callback); | ||
} | ||
|
||
/** | ||
* Load the configuration file | ||
*/ | ||
public static function start(){ | ||
if(self::$config === null){ | ||
self::$config = Config::get('routes'); | ||
} | ||
|
||
foreach(self::$config['routes'] as $route){ | ||
include(self::$config['path'] . $route . '.php'); | ||
} | ||
} | ||
|
||
/** | ||
* Defines callback if route is not found | ||
*/ | ||
|
@@ -83,7 +92,7 @@ public static function dispatch(){ | |
$searches = array_keys(static::$patterns); | ||
$replaces = array_values(static::$patterns); | ||
$found_route = false; | ||
|
||
self::$routes = str_replace('//', '/', self::$routes); | ||
// Check if route is defined without regex | ||
if (in_array($uri, self::$routes)) { | ||
|
@@ -136,7 +145,7 @@ public static function dispatch(){ | |
// Fix multi parameters | ||
if(!method_exists($controller, $segments[1])) { | ||
//"controller and action not found" | ||
Debugger::report(500); | ||
Debugger::report(500); | ||
} else { | ||
call_user_func_array(array($controller, $segments[1]), $matched); | ||
} | ||
|
@@ -145,7 +154,9 @@ public static function dispatch(){ | |
call_user_func_array(self::$callbacks[$pos], $matched); | ||
if (self::$halts) return; | ||
} | ||
} | ||
}else{ | ||
|
||
} | ||
} | ||
$pos++; | ||
} | ||
|
@@ -167,11 +178,11 @@ public static function dispatch(){ | |
call_user_func(self::$error_callback); | ||
} | ||
} | ||
|
||
static function redirect($url, $permanent = false){ | ||
if (headers_sent() === false){ | ||
header('Location: ' . $url, true, ($permanent === true) ? 301 : 302); | ||
} | ||
exit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
namespace Core; | ||
|
||
/** | ||
* Class Service | ||
* Service is where all the applications written by user resides, for both | ||
* input and output processing | ||
* @package Core | ||
*/ | ||
class Service { | ||
/** | ||
* Contains the object of instantiation of the Service class | ||
* @static | ||
* @var object | ||
*/ | ||
private static $serviceObject; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $config = ''; | ||
|
||
/** | ||
* @static | ||
* @return Service|object | ||
*/ | ||
public static function loadServices() | ||
{ | ||
if(isset(self::$serviceObject) === false){ | ||
self::$serviceObject = new self; | ||
} | ||
|
||
self::$serviceObject->prepare(); | ||
|
||
return self::$serviceObject; | ||
} | ||
|
||
/** | ||
* Object preparer | ||
*/ | ||
private function prepare(){ | ||
if(isset($config) === false){ | ||
$this->config = Config::get('services'); | ||
} | ||
|
||
foreach($this->config as $className => $varName){ | ||
$this->$varName = new $className; | ||
} | ||
} | ||
|
||
/** | ||
* Dump function | ||
*/ | ||
public function dump(){ | ||
return($this); | ||
} | ||
|
||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.