示例#1
0
 static function factory($cn, \cherry\Mvc\Request $req)
 {
     \Cherry\Log(\Cherry\LOG_DEBUG, "Invoking controller: %s", $cn);
     // Check the namespace
     $app = \cherry\Application::getInstance();
     $cfg = $app->getConfiguration('application', 'application');
     $ns = $cfg['namespace'];
     if (substr($cn, 0, strlen($ns)) == $ns) {
         $cpath = explode('\\', strToLower($cn));
         $fpath = CHERRY_APP . _DS_ . 'application' . _DS_ . join(_DS_, array_slice($cpath, 2));
     } else {
         $fpath = strToLower($cn);
     }
     $fpath = str_replace('\\', DIRECTORY_SEPARATOR, $fpath);
     if (substr($fpath, -10, 10) == 'controller') {
         $fpath = substr($fpath, 0, strlen($fpath) - 10);
     }
     $fpath .= '.php';
     if (file_exists($fpath)) {
         require_once $fpath;
         $cobj = new $cn($req);
         return $cobj;
     } else {
         throw new \Exception("Could not include file; " . $fpath);
     }
 }
示例#2
0
 function onTag($tag, array $props)
 {
     if ($tag == '@uuid') {
         \Cherry\Log(\Cherry\LOG_DEBUG, "Generating UUID for @uuid metatag.");
         return \Cherry\Crypto\Uuid::getInstance()->generate();
     }
 }
示例#3
0
 protected function checkStaticRoutes(\Cherry\Mvc\Request $request)
 {
     $rt = StaticRoutes::getInstance();
     $dest = $rt->checkRoute($request);
     if (is_object($dest)) {
         \Cherry\Log(\Cherry\LOG_DEBUG, "Static route found for request: %s", $request);
         return $dest;
     }
     return null;
 }
示例#4
0
 function route(\cherry\Mvc\Request $request)
 {
     \Cherry\Log(\Cherry\LOG_DEBUG, "Routing request: %s", $request);
     $cobj = $this->checkStaticRoutes($request);
     if (!$cobj) {
         $cobj = \cherry\Mvc\Controller\Base::factory('\\MyApp\\Controllers\\IndexController', $request);
         $cobj->method = 'index';
     }
     if (is_object($cobj)) {
         $cobj->invoke();
     }
 }