Example #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);
     }
 }