| ... | ... |
@@ -3,51 +3,51 @@ |
| 3 | 3 |
namespace elanpl\L3; |
| 4 | 4 |
|
| 5 | 5 |
class Application{
|
| 6 |
- public $Config; // L3 Config object |
|
| 7 |
- public $Request; // build from received HTTP request or created in L3 Config object |
|
| 8 |
- public $Response; // response to be send |
|
| 9 |
- public $Router; // routing engine |
|
| 10 |
- public $Serialization; // serialization engine |
|
| 11 |
- public $BaseDirectory; // directory root of the application |
|
| 12 |
- public $ControllersDirectory; // subdirectory/namespace part added to controller class |
|
| 13 |
- public $ViewsDirectory; // subdirectory to search for the view files |
|
| 14 |
- public $ApplicationDirectory; // subdirectory/namespace part of the application |
|
| 6 |
+ public $config; // L3 Config object |
|
| 7 |
+ public $request; // build from received HTTP request or created in L3 Config object |
|
| 8 |
+ public $response; // response to be send |
|
| 9 |
+ public $router; // routing engine |
|
| 10 |
+ public $serialization; // serialization engine |
|
| 11 |
+ public $baseDirecotry; // directory root of the application |
|
| 12 |
+ public $controllersDirecotry; // subdirectory/namespace part added to controller class |
|
| 13 |
+ public $viewsDirecotry; // subdirectory to search for the view files |
|
| 14 |
+ public $applicationDirectory; // subdirectory/namespace part of the application |
|
| 15 | 15 |
//public $Controller; //Active controller |
| 16 | 16 |
//public $Module; //Active module |
| 17 | 17 |
//public $Action; //Active action |
| 18 | 18 |
|
| 19 | 19 |
public function __construct($config){
|
| 20 | 20 |
//set L3 application config |
| 21 |
- $this->Config = $config; |
|
| 21 |
+ $this->config = $config; |
|
| 22 | 22 |
// directory root of the application |
| 23 |
- $this->BaseDirectory = $config->getBaseDirectory(); |
|
| 23 |
+ $this->baseDirecotry = $config->getBaseDirectory(); |
|
| 24 | 24 |
// subdirectory/namespace part added to controller class |
| 25 |
- $this->ControllersDirectory = $config->getControllersDirectory(); |
|
| 25 |
+ $this->controllersDirecotry = $config->getControllersDirectory(); |
|
| 26 | 26 |
// subdirectory to search for the view files |
| 27 |
- $this->ViewsDirectory = $config->getViewsDirectory(); |
|
| 27 |
+ $this->viewsDirecotry = $config->getViewsDirectory(); |
|
| 28 | 28 |
// subdirectory/namespace part of the application |
| 29 |
- $this->ApplicationDirectory = $config->getApplicationDirectory(); |
|
| 29 |
+ $this->applicationDirectory = $config->getApplicationDirectory(); |
|
| 30 | 30 |
//create request object |
| 31 |
- $this->Request = $this->Config->getRequest(); |
|
| 31 |
+ $this->request = $this->config->getRequest(); |
|
| 32 | 32 |
//create router object |
| 33 |
- $this->Router = new Router($this->Config->getRouting()); |
|
| 33 |
+ $this->router = new Router($this->config->getRouting()); |
|
| 34 | 34 |
//create response objcet |
| 35 |
- $this->Response = new Response(); |
|
| 35 |
+ $this->response = new Response(); |
|
| 36 | 36 |
|
| 37 | 37 |
//create serialization object |
| 38 |
- $this->Serialization = new Serialization(); |
|
| 38 |
+ $this->serialization = new Serialization(); |
|
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
public function basePath(){
|
| 42 |
- return strstr($_SERVER['REQUEST_URI'], $this->Request->Path, true); |
|
| 42 |
+ return strstr($_SERVER['REQUEST_URI'], $this->request->path, true); |
|
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 | 45 |
public function relPath($file){
|
| 46 |
- return ($this->Router->depth>0 ? str_repeat("../", substr($this->Request->Path,-1)=='/'?$this->Router->depth:$this->Router->depth-1) : "" ).$file;
|
|
| 46 |
+ return ($this->router->depth>0 ? str_repeat("../", substr($this->request->path,-1)=='/'?$this->router->depth:$this->router->depth-1) : "" ).$file;
|
|
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 | 49 |
public function link($name, $parameters){
|
| 50 |
- return $this->Router->link($name, $parameters); |
|
| 50 |
+ return $this->router->link($name, $parameters); |
|
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 | 53 |
/* |
| ... | ... |
@@ -56,7 +56,7 @@ class Application{
|
| 56 | 56 |
include_once(_L3_CONTROLLER_PATH.$Controller.'.php'); |
| 57 | 57 |
}*/ |
| 58 | 58 |
|
| 59 |
- public function FindControllerInCallStack($search_level=5){
|
|
| 59 |
+ public function findControllerInCallStack($search_level=5){
|
|
| 60 | 60 |
//search for controller, action and module if present |
| 61 | 61 |
$controller = ""; |
| 62 | 62 |
$module = ""; |
| ... | ... |
@@ -68,7 +68,7 @@ class Application{
|
| 68 | 68 |
|
| 69 | 69 |
for($i=0; $i<$search_level; $i++){
|
| 70 | 70 |
if(preg_match( |
| 71 |
- $pattern = '#('.$this->ApplicationDirectory.')(\\\\(?P<module>.+))?\\\\'.$this->ControllersDirectory.'\\\\(?P<controller>.+)#',
|
|
| 71 |
+ $pattern = '#('.$this->applicationDirectory.')(\\\\(?P<module>.+))?\\\\'.$this->controllersDirecotry.'\\\\(?P<controller>.+)#',
|
|
| 72 | 72 |
$call_stack[$i]['class'], |
| 73 | 73 |
$match |
| 74 | 74 |
) |
| ... | ... |
@@ -87,7 +87,7 @@ class Application{
|
| 87 | 87 |
); |
| 88 | 88 |
} |
| 89 | 89 |
|
| 90 |
- function RunControllerAction($ControllerAction, $Parameters){
|
|
| 90 |
+ function runControllerAction($controllerAction, $parameters){
|
|
| 91 | 91 |
|
| 92 | 92 |
//prepare object and action name |
| 93 | 93 |
/* |
| ... | ... |
@@ -106,21 +106,21 @@ class Application{
|
| 106 | 106 |
} |
| 107 | 107 |
}*/ |
| 108 | 108 |
|
| 109 |
- if(is_array($ControllerAction)){
|
|
| 109 |
+ if(is_array($controllerAction)){
|
|
| 110 | 110 |
//$this->IncludeControler($ControllerAction['controller']); |
| 111 |
- $controller_class = "\\".$this->ApplicationDirectory."\\" |
|
| 112 |
- .(isset($ControllerAction['module'])?$ControllerAction['module']."\\":"") |
|
| 113 |
- .$this->ControllersDirectory."\\" |
|
| 114 |
- .$ControllerAction['controller']; |
|
| 111 |
+ $controller_class = "\\".$this->applicationDirectory."\\" |
|
| 112 |
+ .(isset($controllerAction['module'])?$controllerAction['module']."\\":"") |
|
| 113 |
+ .$this->controllersDirecotry."\\" |
|
| 114 |
+ .$controllerAction['controller']; |
|
| 115 | 115 |
$controller_object = new $controller_class; |
| 116 |
- $controller_action = $ControllerAction['action']; |
|
| 116 |
+ $controller_action = $controllerAction['action']; |
|
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 | 119 |
//fire the action |
| 120 | 120 |
if(isset($controller_object) && isset($controller_action)){
|
| 121 |
- $this->Module = (isset($ControllerAction['module'])?$ControllerAction['module']:""); |
|
| 122 |
- $this->Controller = $ControllerAction['controller']; |
|
| 123 |
- $this->Action = $controller_action; |
|
| 121 |
+ $this->module = (isset($controllerAction['module'])?$controllerAction['module']:""); |
|
| 122 |
+ $this->controller = $controllerAction['controller']; |
|
| 123 |
+ $this->action = $controller_action; |
|
| 124 | 124 |
// prepare args and start the action |
| 125 | 125 |
if(!isset($reflection)){
|
| 126 | 126 |
$reflection = new \ReflectionMethod($controller_object, $controller_action); |
| ... | ... |
@@ -130,11 +130,11 @@ class Application{
|
| 130 | 130 |
|
| 131 | 131 |
foreach($reflection->getParameters() AS $arg) |
| 132 | 132 |
{
|
| 133 |
- if(isset($Parameters[$arg->name]) || (is_array($ControllerAction) && isset($ControllerAction['defaults'][$arg->name]))) |
|
| 134 |
- if(isset($Parameters[$arg->name])) |
|
| 135 |
- $fire_args[$arg->name]=$Parameters[$arg->name]; |
|
| 133 |
+ if(isset($parameters[$arg->name]) || (is_array($controllerAction) && isset($controllerAction['defaults'][$arg->name]))) |
|
| 134 |
+ if(isset($parameters[$arg->name])) |
|
| 135 |
+ $fire_args[$arg->name]=$parameters[$arg->name]; |
|
| 136 | 136 |
else |
| 137 |
- $fire_args[$arg->name]=$ControllerAction['defaults'][$arg->name]; |
|
| 137 |
+ $fire_args[$arg->name]=$controllerAction['defaults'][$arg->name]; |
|
| 138 | 138 |
else |
| 139 | 139 |
{
|
| 140 | 140 |
if($arg->isDefaultValueAvailable()){
|
| ... | ... |
@@ -153,23 +153,23 @@ class Application{
|
| 153 | 153 |
} |
| 154 | 154 |
} |
| 155 | 155 |
|
| 156 |
- public function HandleActionResult($result){
|
|
| 156 |
+ public function handleActionResult($result){
|
|
| 157 | 157 |
if(is_string($result)){
|
| 158 | 158 |
$content = $result; |
| 159 | 159 |
} |
| 160 | 160 |
else if(is_object($result)){
|
| 161 | 161 |
if($result instanceof ViewModel){
|
| 162 |
- if($SerializationContentType = $this->Serialization->Match($this->Request->AcceptTypes, $result)){
|
|
| 163 |
- $content = $this->Serialization->Serialize($SerializationContentType, $result); |
|
| 162 |
+ if($serializationContentType = $this->serialization->match($this->request->acceptTypes, $result)){
|
|
| 163 |
+ $content = $this->serialization->serialize($serializationContentType, $result); |
|
| 164 | 164 |
if(is_object($content)){
|
| 165 |
- if($content instanceof Response){
|
|
| 166 |
- $this->Response = $content; |
|
| 165 |
+ if($content instanceof response){
|
|
| 166 |
+ $this->response = $content; |
|
| 167 | 167 |
unset($content); |
| 168 | 168 |
} |
| 169 | 169 |
} |
| 170 | 170 |
} |
| 171 | 171 |
else{
|
| 172 |
- echo "Serializer not defined for Content-Type: ".$this->Request->Accept."<br>".PHP_EOL; |
|
| 172 |
+ echo "Serializer not defined for Content-Type: ".$this->request->accept."<br>".PHP_EOL; |
|
| 173 | 173 |
throw new \Exception("Not implemented!");
|
| 174 | 174 |
} |
| 175 | 175 |
} |
| ... | ... |
@@ -177,26 +177,26 @@ class Application{
|
| 177 | 177 |
$content = $result->render(); |
| 178 | 178 |
} |
| 179 | 179 |
else if($result instanceof Response){
|
| 180 |
- $this->Response = $result; |
|
| 180 |
+ $this->response = $result; |
|
| 181 | 181 |
} |
| 182 | 182 |
} |
| 183 | 183 |
if(isset($content)) |
| 184 |
- $this->Response->withBody($content); |
|
| 185 |
- $this->Response->send(); |
|
| 184 |
+ $this->response->withBody($content); |
|
| 185 |
+ $this->response->send(); |
|
| 186 | 186 |
} |
| 187 | 187 |
|
| 188 |
- public function BeforeAction(){
|
|
| 189 |
- if(!empty($this->Router->RouteInfo->BeforeAction)){
|
|
| 190 |
- foreach($this->Router->RouteInfo->BeforeAction as $event_handler){
|
|
| 191 |
- $this->Router->RouteInfo::EventHandlerFormatCheck($event_handler, $eh); |
|
| 188 |
+ public function beforeAction(){
|
|
| 189 |
+ if(!empty($this->router->routeInfo->beforeAction)){
|
|
| 190 |
+ foreach($this->router->routeInfo->beforeAction as $event_handler){
|
|
| 191 |
+ $this->router->routeInfo::eventHandlerFormatCheck($event_handler, $eh); |
|
| 192 | 192 |
if(isset($eh['class'])){
|
| 193 | 193 |
$object = new $eh['class']; |
| 194 | 194 |
$reflection = new \ReflectionMethod($object, $eh['function']); |
| 195 | 195 |
$fire_args = array(); |
| 196 |
- $fire_args[] = $this->Request; |
|
| 197 |
- $fire_args[] = $this->Router->RouteInfo; |
|
| 196 |
+ $fire_args[] = $this->request; |
|
| 197 |
+ $fire_args[] = $this->router->routeInfo; |
|
| 198 | 198 |
if(isset($eh['arguments'])){
|
| 199 |
- $this->Router->RouteInfo::EventHandlerArgumentsFormatCheck($eh['arguments'], $args); |
|
| 199 |
+ $this->router->routeInfo::eventHandlerArgumentsFormatCheck($eh['arguments'], $args); |
|
| 200 | 200 |
$fire_args = array_merge($fire_args, $args); |
| 201 | 201 |
} |
| 202 | 202 |
$result = $reflection->invokeArgs ($object , $fire_args ); |
| ... | ... |
@@ -207,7 +207,7 @@ class Application{
|
| 207 | 207 |
if(isset($result)){
|
| 208 | 208 |
if(is_object($result)){
|
| 209 | 209 |
if($result instanceof Response){
|
| 210 |
- $this->HandleActionResult($result); |
|
| 210 |
+ $this->handleActionResult($result); |
|
| 211 | 211 |
exit(); |
| 212 | 212 |
} |
| 213 | 213 |
} |
| ... | ... |
@@ -216,9 +216,9 @@ class Application{
|
| 216 | 216 |
} |
| 217 | 217 |
} |
| 218 | 218 |
|
| 219 |
- public function Run(){
|
|
| 219 |
+ public function run(){
|
|
| 220 | 220 |
// Check if routing path is found |
| 221 |
- if($action = $this->Router->match($this->Request)){
|
|
| 221 |
+ if($action = $this->router->match($this->request)){
|
|
| 222 | 222 |
// routing match found decide what to do next... |
| 223 | 223 |
// BeforeAction event |
| 224 | 224 |
$this->BeforeAction(); |
| ... | ... |
@@ -231,8 +231,8 @@ class Application{
|
| 231 | 231 |
|
| 232 | 232 |
foreach($reflection->getParameters() AS $arg) |
| 233 | 233 |
{
|
| 234 |
- if(isset($this->Router->parsedParameters[$arg->name])) |
|
| 235 |
- $fire_args[$arg->name]=$this->Router->parsedParameters[$arg->name]; |
|
| 234 |
+ if(isset($this->router->parsedParameters[$arg->name])) |
|
| 235 |
+ $fire_args[$arg->name]=$this->router->parsedParameters[$arg->name]; |
|
| 236 | 236 |
else |
| 237 | 237 |
$fire_args[$arg->name]=null; |
| 238 | 238 |
} |
| ... | ... |
@@ -250,7 +250,7 @@ class Application{
|
| 250 | 250 |
} |
| 251 | 251 |
// array with controller, and action -> run the controller action |
| 252 | 252 |
else if(is_array($action) && array_key_exists('controller',$action) && array_key_exists('action', $action)){
|
| 253 |
- $result = $this->RunControllerAction($action, $this->Router->parsedParameters); |
|
| 253 |
+ $result = $this->runControllerAction($action, $this->router->parsedParameters); |
|
| 254 | 254 |
|
| 255 | 255 |
} |
| 256 | 256 |
// string |
| ... | ... |
@@ -260,7 +260,7 @@ class Application{
|
| 260 | 260 |
|
| 261 | 261 |
// Handle the action result |
| 262 | 262 |
if(isset($result)){
|
| 263 |
- $this->HandleActionResult($result); |
|
| 263 |
+ $this->handleActionResult($result); |
|
| 264 | 264 |
} |
| 265 | 265 |
} |
| 266 | 266 |
// routing path not found -> generate 404 response |
| ... | ... |
@@ -3,41 +3,41 @@ |
| 3 | 3 |
namespace elanpl\L3; |
| 4 | 4 |
|
| 5 | 5 |
class Request{
|
| 6 |
- public $Path; |
|
| 7 |
- public $Method; |
|
| 8 |
- public $Accept; |
|
| 9 |
- public $AcceptTypes; |
|
| 10 |
- public $AcceptLanguage; |
|
| 11 |
- public $UserAgent; |
|
| 12 |
- public $Headers; |
|
| 13 |
- public $Body; |
|
| 6 |
+ public $path; |
|
| 7 |
+ public $method; |
|
| 8 |
+ public $accept; |
|
| 9 |
+ public $acceptTypes; |
|
| 10 |
+ public $acceptLanguage; |
|
| 11 |
+ public $userAgent; |
|
| 12 |
+ public $headers; |
|
| 13 |
+ public $body; |
|
| 14 | 14 |
public function __construct(){
|
| 15 | 15 |
if(isset($_GET['path'])) |
| 16 |
- $this->Path = $_GET['path']; |
|
| 17 |
- $this->Method = $_SERVER['REQUEST_METHOD']; |
|
| 18 |
- $this->Accept = $_SERVER['HTTP_ACCEPT']; |
|
| 19 |
- $this->AcceptTypes = $this->ParseAccept($this->Accept); |
|
| 20 |
- $this->AcceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?$_SERVER['HTTP_ACCEPT_LANGUAGE']:""; |
|
| 21 |
- $this->UserAgent = $_SERVER['HTTP_USER_AGENT']; |
|
| 16 |
+ $this->path = $_GET['path']; |
|
| 17 |
+ $this->method = $_SERVER['REQUEST_METHOD']; |
|
| 18 |
+ $this->accept = $_SERVER['HTTP_ACCEPT']; |
|
| 19 |
+ $this->acceptTypes = $this->parseAccept($this->accept); |
|
| 20 |
+ $this->acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?$_SERVER['HTTP_ACCEPT_LANGUAGE']:""; |
|
| 21 |
+ $this->userAgent = $_SERVER['HTTP_USER_AGENT']; |
|
| 22 | 22 |
if(function_exists('apache_request_headers')){
|
| 23 |
- $this->Headers = apache_request_headers(); |
|
| 23 |
+ $this->headers = apache_request_headers(); |
|
| 24 | 24 |
} |
| 25 | 25 |
else{
|
| 26 |
- $this->Headers = array(); |
|
| 26 |
+ $this->headers = array(); |
|
| 27 | 27 |
foreach($_SERVER as $key => $value) {
|
| 28 | 28 |
if (substr($key, 0, 5) <> 'HTTP_') {
|
| 29 | 29 |
continue; |
| 30 | 30 |
} |
| 31 | 31 |
$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
|
| 32 |
- $this->Headers[$header] = $value; |
|
| 32 |
+ $this->headers[$header] = $value; |
|
| 33 | 33 |
} |
| 34 | 34 |
} |
| 35 | 35 |
if (php_sapi_name() != "cli") {
|
| 36 |
- $this->Body = file_get_contents('php://input');
|
|
| 36 |
+ $this->body = file_get_contents('php://input');
|
|
| 37 | 37 |
} |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 |
- public function ParseAccept($accept){
|
|
| 40 |
+ public function parseAccept($accept){
|
|
| 41 | 41 |
//cut out the spaces |
| 42 | 42 |
$accept = str_replace(" ", "", $accept);
|
| 43 | 43 |
|
| ... | ... |
@@ -45,8 +45,8 @@ class Request{
|
| 45 | 45 |
$quality_factors = array(); |
| 46 | 46 |
|
| 47 | 47 |
// find content type and corresponding quality factor value |
| 48 |
- foreach(explode(",", $accept) as $AcceptParts){
|
|
| 49 |
- $type = explode(";", $AcceptParts);
|
|
| 48 |
+ foreach(explode(",", $accept) as $acceptParts){
|
|
| 49 |
+ $type = explode(";", $acceptParts);
|
|
| 50 | 50 |
$result[] = $type[0]; |
| 51 | 51 |
if(count($type)>1){
|
| 52 | 52 |
if($type[1][0].$type[1][1] == "q="){
|
| ... | ... |
@@ -4,34 +4,34 @@ namespace elanpl\L3; |
| 4 | 4 |
|
| 5 | 5 |
class RouteInfo{
|
| 6 | 6 |
// URL pattern path |
| 7 |
- public $Path; |
|
| 7 |
+ public $path; |
|
| 8 | 8 |
// Http method (ex. GET, POST, ANY) |
| 9 |
- public $Method; |
|
| 9 |
+ public $method; |
|
| 10 | 10 |
// The assigned structure (string, array, function...) |
| 11 |
- public $Result; |
|
| 11 |
+ public $result; |
|
| 12 | 12 |
// The route name |
| 13 |
- public $Name; |
|
| 13 |
+ public $name; |
|
| 14 | 14 |
// BeforeAction event handlers; |
| 15 |
- public $BeforeAction; |
|
| 15 |
+ public $beforeAction; |
|
| 16 | 16 |
// AfterAction event handlers; |
| 17 |
- public $AfterAction; |
|
| 17 |
+ public $afterAction; |
|
| 18 | 18 |
// AfterResult event handlers; |
| 19 |
- public $AfterResult; |
|
| 19 |
+ public $afterResult; |
|
| 20 | 20 |
|
| 21 |
- public function __construct($Method, $Path, $Result, $Name = '') |
|
| 21 |
+ public function __construct($method, $path, $result, $name = '') |
|
| 22 | 22 |
{
|
| 23 |
- $this->Path = $Path; |
|
| 24 |
- $this->Method = $Method; |
|
| 25 |
- $this->Result = $Result; |
|
| 26 |
- $this->Name = $Name; |
|
| 27 |
- $this->BeforeAction = array(); |
|
| 28 |
- $this->AfterAction = array(); |
|
| 29 |
- $this->AfterResult = array(); |
|
| 23 |
+ $this->path = $path; |
|
| 24 |
+ $this->method = $method; |
|
| 25 |
+ $this->result = $result; |
|
| 26 |
+ $this->name = $name; |
|
| 27 |
+ $this->beforeAction = array(); |
|
| 28 |
+ $this->afterAction = array(); |
|
| 29 |
+ $this->afterResult = array(); |
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 |
- public function AddBeforeAction($event_handler){
|
|
| 33 |
- if($this->EventHandlerFormatCheck($event_handler, $match)){
|
|
| 34 |
- $this->BeforeAction[] = $event_handler; |
|
| 32 |
+ public function addBeforeAction($event_handler){
|
|
| 33 |
+ if($this->eventHandlerFormatCheck($event_handler, $match)){
|
|
| 34 |
+ $this->beforeAction[] = $event_handler; |
|
| 35 | 35 |
return $this; |
| 36 | 36 |
} |
| 37 | 37 |
else{
|
| ... | ... |
@@ -39,9 +39,9 @@ class RouteInfo{
|
| 39 | 39 |
} |
| 40 | 40 |
} |
| 41 | 41 |
|
| 42 |
- public function AddAfterAction($event_handler){
|
|
| 43 |
- if($this->EventHandlerFormatCheck($event_handler, $match)){
|
|
| 44 |
- $this->AfterAction[] = $event_handler; |
|
| 42 |
+ public function addAfterAction($event_handler){
|
|
| 43 |
+ if($this->eventHandlerFormatCheck($event_handler, $match)){
|
|
| 44 |
+ $this->afterAction[] = $event_handler; |
|
| 45 | 45 |
return $this; |
| 46 | 46 |
} |
| 47 | 47 |
else{
|
| ... | ... |
@@ -49,9 +49,9 @@ class RouteInfo{
|
| 49 | 49 |
} |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 |
- public function AddAfterResult($event_handler){
|
|
| 53 |
- if($this->EventHandlerFormatCheck($event_handler, $match)){
|
|
| 54 |
- $this->AfterResult[] = $event_handler; |
|
| 52 |
+ public function addAfterResult($event_handler){
|
|
| 53 |
+ if($this->eventHandlerFormatCheck($event_handler, $match)){
|
|
| 54 |
+ $this->afterResult[] = $event_handler; |
|
| 55 | 55 |
return $this; |
| 56 | 56 |
} |
| 57 | 57 |
else{
|
| ... | ... |
@@ -59,11 +59,11 @@ class RouteInfo{
|
| 59 | 59 |
} |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 |
- public static function EventHandlerFormatCheck($event_handler, &$match){
|
|
| 62 |
+ public static function eventHandlerFormatCheck($event_handler, &$match){
|
|
| 63 | 63 |
$pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;, ]+)?\\))?$#i'; |
| 64 | 64 |
if(preg_match($pattern, $event_handler, $match)){
|
| 65 | 65 |
if(isset($match['arguments'])){
|
| 66 |
- $result = self::EventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match); |
|
| 66 |
+ $result = self::eventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match); |
|
| 67 | 67 |
return $result; |
| 68 | 68 |
} |
| 69 | 69 |
else{
|
| ... | ... |
@@ -75,7 +75,7 @@ class RouteInfo{
|
| 75 | 75 |
} |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 |
- public static function EventHandlerArgumentsFormatCheck($arguments, &$match){
|
|
| 78 |
+ public static function eventHandlerArgumentsFormatCheck($arguments, &$match){
|
|
| 79 | 79 |
$match = explode(',', $arguments);
|
| 80 | 80 |
return $match; |
| 81 | 81 |
} |
| ... | ... |
@@ -8,7 +8,7 @@ class Router{
|
| 8 | 8 |
protected $routeNameIndex; // An array with elements that reference to the routes ordered by a route names |
| 9 | 9 |
public $parsedParameters; // Parameters parsed from Request Path |
| 10 | 10 |
public $depth; // Number of nested nodes in Request Path |
| 11 |
- public $RouteInfo; // The RouteInfo object if the route was matched |
|
| 11 |
+ public $routeInfo; // The RouteInfo object if the route was matched |
|
| 12 | 12 |
|
| 13 | 13 |
public function __construct($routing) |
| 14 | 14 |
{
|
| ... | ... |
@@ -18,61 +18,61 @@ class Router{
|
| 18 | 18 |
$routing->set($this); |
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 |
- public function add($Method, $Path, $Result, $Name = ''){
|
|
| 22 |
- $this->routes[] = new RouteInfo($Method, $Path, $Result, $Name); |
|
| 23 |
- if(isset($Name)&&$Name!='') $this->routeNameIndex[$Name] = &$this->routes[count($this->routes)-1]; |
|
| 21 |
+ public function add($method, $path, $result, $name = ''){
|
|
| 22 |
+ $this->routes[] = new RouteInfo($method, $path, $result, $name); |
|
| 23 |
+ if(isset($name)&&$name!='') $this->routeNameIndex[$name] = &$this->routes[count($this->routes)-1]; |
|
| 24 | 24 |
return $this; |
| 25 | 25 |
} |
| 26 | 26 |
|
| 27 |
- public function get($Path, $Result, $Name = ''){
|
|
| 28 |
- return $this->add('GET', $Path, $Result, $Name);
|
|
| 27 |
+ public function get($path, $result, $name = ''){
|
|
| 28 |
+ return $this->add('GET', $path, $result, $name);
|
|
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 |
- public function post($Path, $Result, $Name = ''){
|
|
| 32 |
- return $this->add('POST', $Path, $Result, $Name);
|
|
| 31 |
+ public function post($path, $result, $name = ''){
|
|
| 32 |
+ return $this->add('POST', $path, $result, $name);
|
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
- public function put($Path, $Result, $Name = ''){
|
|
| 36 |
- return $this->add('PUT', $Path, $Result, $Name);
|
|
| 35 |
+ public function put($path, $result, $name = ''){
|
|
| 36 |
+ return $this->add('PUT', $path, $result, $name);
|
|
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 |
- public function patch($Path, $Result, $Name = ''){
|
|
| 40 |
- return $this->add('PATCH', $Path, $Result, $Name);
|
|
| 39 |
+ public function patch($path, $result, $name = ''){
|
|
| 40 |
+ return $this->add('PATCH', $path, $result, $name);
|
|
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 |
- public function delete($Path, $Result, $Name = ''){
|
|
| 44 |
- return $this->add('DELETE', $Path, $Result, $Name);
|
|
| 43 |
+ public function delete($path, $result, $name = ''){
|
|
| 44 |
+ return $this->add('DELETE', $path, $result, $name);
|
|
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 |
- public function any($Path, $Result, $Name = ''){
|
|
| 48 |
- return $this->add('ANY', $Path, $Result, $Name);
|
|
| 47 |
+ public function any($path, $result, $name = ''){
|
|
| 48 |
+ return $this->add('ANY', $path, $result, $name);
|
|
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 |
- public function AddBeforeAction($event_handler){
|
|
| 52 |
- $this->routes[count($this->routes)-1]->AddBeforeAction($event_handler); |
|
| 51 |
+ public function addBeforeAction($event_handler){
|
|
| 52 |
+ $this->routes[count($this->routes)-1]->addBeforeAction($event_handler); |
|
| 53 | 53 |
return $this; |
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 |
- public function AddAfterAction($event_handler){
|
|
| 57 |
- $this->routes[count($this->routes)-1]->AddAfterAction($event_handler); |
|
| 56 |
+ public function addAfterAction($event_handler){
|
|
| 57 |
+ $this->routes[count($this->routes)-1]->addAfterAction($event_handler); |
|
| 58 | 58 |
return $this; |
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 |
- public function AddAfterResult($event_handler){
|
|
| 62 |
- $this->routes[count($this->routes)-1]->AddAfterAction($event_handler); |
|
| 61 |
+ public function addAfterResult($event_handler){
|
|
| 62 |
+ $this->routes[count($this->routes)-1]->addAfterAction($event_handler); |
|
| 63 | 63 |
return $this; |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 |
- public function match($Request){
|
|
| 66 |
+ public function match($request){
|
|
| 67 | 67 |
|
| 68 |
- $auri = explode('/', trim($Request->Path, "/ \t\n\r\0\x0B"));
|
|
| 68 |
+ $auri = explode('/', trim($request->Path, "/ \t\n\r\0\x0B"));
|
|
| 69 | 69 |
$curi = count($auri); |
| 70 | 70 |
|
| 71 | 71 |
foreach ($this->routes as $routeInfo) {
|
| 72 | 72 |
|
| 73 |
- $route = $routeInfo->Path; |
|
| 74 |
- $method = $routeInfo->Method; |
|
| 75 |
- if($method=='ANY' || strpos($Request->Method,$method)!==false){
|
|
| 73 |
+ $route = $routeInfo->path; |
|
| 74 |
+ $method = $routeInfo->method; |
|
| 75 |
+ if($method=='ANY' || strpos($request->method,$method)!==false){
|
|
| 76 | 76 |
$aroute = explode('/', trim($route, "/ \t\n\r\0\x0B"));
|
| 77 | 77 |
//print_r($aroute); |
| 78 | 78 |
if($curi==count($aroute)){ //compare path element count
|
| ... | ... |
@@ -100,7 +100,7 @@ class Router{
|
| 100 | 100 |
} |
| 101 | 101 |
if($matchResult){ // match found
|
| 102 | 102 |
$this->depth = $curi; |
| 103 |
- $this->RouteInfo = $routeInfo; |
|
| 103 |
+ $this->routeInfo = $routeInfo; |
|
| 104 | 104 |
return $routeInfo->Result; |
| 105 | 105 |
} |
| 106 | 106 |
} |
| ... | ... |
@@ -119,7 +119,7 @@ class Router{
|
| 119 | 119 |
return preg_replace($fields, $values, $route->Path); |
| 120 | 120 |
} |
| 121 | 121 |
|
| 122 |
- public function GetParameter($name){
|
|
| 122 |
+ public function getParameter($name){
|
|
| 123 | 123 |
return $this->parsedParameters[$name]; |
| 124 | 124 |
} |
| 125 | 125 |
|
| ... | ... |
@@ -10,41 +10,41 @@ class Serialization{
|
| 10 | 10 |
if(!isset(self::$serializers)) self::$serializers = array(); |
| 11 | 11 |
} |
| 12 | 12 |
|
| 13 |
- public static function Register($ContentType, $Serializer, $ViewModelClass = null){
|
|
| 14 |
- if(isset($ViewModelClass) && $ViewModelClass!=''){
|
|
| 15 |
- $class_key = $ViewModelClass.'|'; |
|
| 13 |
+ public static function register($contentType, $serializer, $viewModelClass = null){
|
|
| 14 |
+ if(isset($viewModelClass) && $viewModelClass!=''){
|
|
| 15 |
+ $class_key = $viewModelClass.'|'; |
|
| 16 | 16 |
} |
| 17 | 17 |
else{
|
| 18 | 18 |
$class_key = ''; |
| 19 | 19 |
} |
| 20 |
- self::$serializers[$class_key.$ContentType] = $Serializer; |
|
| 20 |
+ self::$serializers[$class_key.$contentType] = $serializer; |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 |
- public function Match($AcceptTypes, $ViewModel=null){
|
|
| 24 |
- if(isset($ViewModel)){
|
|
| 25 |
- if(is_object($ViewModel)){
|
|
| 26 |
- $ViewModelClass = get_class($ViewModel); |
|
| 23 |
+ public function match($acceptTypes, $viewModel=null){
|
|
| 24 |
+ if(isset($viewModel)){
|
|
| 25 |
+ if(is_object($viewModel)){
|
|
| 26 |
+ $viewModelClass = get_class($viewModel); |
|
| 27 | 27 |
} |
| 28 |
- if(is_string($ViewModel)){
|
|
| 29 |
- $ViewModelClass = $ViewModel; |
|
| 28 |
+ if(is_string($viewModel)){
|
|
| 29 |
+ $viewModelClass = $viewModel; |
|
| 30 | 30 |
} |
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 |
- if(is_array($AcceptTypes)){
|
|
| 34 |
- $RegisteredTypes = array_keys(self::$serializers); |
|
| 33 |
+ if(is_array($acceptTypes)){
|
|
| 34 |
+ $registeredTypes = array_keys(self::$serializers); |
|
| 35 | 35 |
|
| 36 |
- foreach ($AcceptTypes as $type){
|
|
| 36 |
+ foreach ($acceptTypes as $type){
|
|
| 37 | 37 |
//Dedicated config for ViewModel class first... |
| 38 |
- if(array_key_exists($ViewModelClass."|".$type, self::$serializers)){
|
|
| 38 |
+ if(array_key_exists($viewModelClass."|".$type, self::$serializers)){
|
|
| 39 | 39 |
return $type; |
| 40 | 40 |
} |
| 41 |
- foreach($RegisteredTypes as $rtype_with_class){
|
|
| 41 |
+ foreach($registeredTypes as $rtype_with_class){
|
|
| 42 | 42 |
$rtype_parts = explode("|", $rtype_with_class);
|
| 43 | 43 |
if(count($rtype_parts)==2){
|
| 44 | 44 |
$rclass = $rtype_parts[0]; |
| 45 | 45 |
$t = explode("/", $type);
|
| 46 | 46 |
$rt = explode("/", $rtype_parts[1]);
|
| 47 |
- if($rclass==$ViewModelClass && ($t[0]=="*" || $rt[0]=="*" || $t[0]==$rt[0]) && ($t[1]=="*" || $rt[1]=="*" || $t[1]==$rt[1])){
|
|
| 47 |
+ if($rclass==$viewModelClass && ($t[0]=="*" || $rt[0]=="*" || $t[0]==$rt[0]) && ($t[1]=="*" || $rt[1]=="*" || $t[1]==$rt[1])){
|
|
| 48 | 48 |
return $rtype_with_class; |
| 49 | 49 |
} |
| 50 | 50 |
} |
| ... | ... |
@@ -54,7 +54,7 @@ class Serialization{
|
| 54 | 54 |
if(array_key_exists($type, self::$serializers)){
|
| 55 | 55 |
return $type; |
| 56 | 56 |
} |
| 57 |
- foreach($RegisteredTypes as $rtype){
|
|
| 57 |
+ foreach($registeredTypes as $rtype){
|
|
| 58 | 58 |
$t = explode("/", $type);
|
| 59 | 59 |
$rt = explode("/", $rtype);
|
| 60 | 60 |
if(($t[0]=="*" || $rt[0]=="*" || $t[0]==$t[0]) && ($t[1]=="*" || $rt[1]=="*" || $t[1]==$t[1])){
|
| ... | ... |
@@ -66,17 +66,17 @@ class Serialization{
|
| 66 | 66 |
return false; |
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 |
- public function Serialize($ContentType, $ViewModel){
|
|
| 70 |
- if(isset(Serialization::$serializers[get_class($ViewModel).'|'.$ContentType])){
|
|
| 71 |
- $serializerClass = Serialization::$serializers[get_class($ViewModel).'|'.$ContentType]; |
|
| 69 |
+ public function serialize($contentType, $viewModel){
|
|
| 70 |
+ if(isset(Serialization::$serializers[get_class($viewModel).'|'.$contentType])){
|
|
| 71 |
+ $serializerClass = Serialization::$serializers[get_class($viewModel).'|'.$contentType]; |
|
| 72 | 72 |
} |
| 73 |
- else if(isset(Serialization::$serializers[$ContentType])){
|
|
| 74 |
- $serializerClass = Serialization::$serializers[$ContentType]; |
|
| 73 |
+ else if(isset(Serialization::$serializers[$contentType])){
|
|
| 74 |
+ $serializerClass = Serialization::$serializers[$contentType]; |
|
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 | 77 |
if(isset($serializerClass)){
|
| 78 | 78 |
$serializer = new $serializerClass(); |
| 79 |
- return $serializer->Serialize($ViewModel); |
|
| 79 |
+ return $serializer->Serialize($viewModel); |
|
| 80 | 80 |
} |
| 81 | 81 |
else{
|
| 82 | 82 |
return null; |