/** * * @return \ORC\MVC\ViewModel */ public static function getInstance() { if (!isset(self::$_instance)) { self::$_instance = new self(Application::getApp()->getController()); } return self::$_instance; }
protected function parseURI() { $uri = $this->_request->getURI(); list($url_path, ) = explode('?', $uri, 2); $config = Config::getInstance(); if ($config->get('app.seo.ext')) { $url_path = preg_replace('/\\.(' . $config->get('app.seo.ext') . ')$/i', '', $url_path); } $routes = $this->get('routes'); //pre($routes); $trim_chars = "/\n\r\t\v "; $url_args = array(); while (strlen($url_path) > 1 && !isset($routes[$url_path])) { $new_arg = substr($url_path, strrpos($url_path, '/')); $url_path = substr($url_path, 0, strrpos($url_path, $new_arg)); // put the new arg into the list array_unshift($url_args, trim($new_arg, $trim_chars)); } if ($url_path == '') { $url_path = '/'; } if ($url_path == '/') { //index, show the default action $this->set('action', strtolower(\ORC\Application::getApp()->getDefaultAction())); } elseif ($url_path) { $this->set('action', strtolower($routes[$url_path])); } else { throw new \ORC\Exception\NotExistsException('404 not found'); } $this->_request->set(\ORC\MVC\Request::args, $url_args); }
protected function getCacher() { if (!isset($this->_cacher)) { $cacher_name = 'dbal_cache'; $cacher_namespace = sprintf('table_%s_%s', Application::getApp()->getName(), str_replace('.', '_', $this->_table->getTableName())); $this->_cacher = CacheFactory::get($cacher_name, $cacher_namespace); } return $this->_cacher; }
public function __construct() { $config = Config::getInstance(); $tablename = $config->get('app.session.tablename'); if (!$tablename) { $tablename = 'sessions'; } $this->table = $tablename; $this->cookie_key = sprintf('%s_sid', Application::getApp()->getName()); parent::__construct(); }
public function render() { $controller = Application::getApp()->getController(); $action = $controller->getAction(); $view = $controller->getView(); $r = new ReflectionObject($action); $action_file = $r->getFileName(); $data = array('action_info' => array('obj' => $action, 'filename' => $action_file)); $r = new ReflectionObject($view); $data['view_info'] = array('obj' => $view, 'filename' => $r->getFileName()); return $this->renderTemplate('Source.Fragments.View', $data); }
public function render() { $class_name = sprintf('%s_%s_Block', $this->_module_name, str_replace('.', '_', $this->_extra)); if (!class_exists($class_name)) { require $this->getFilePath(); } $obj = new $class_name(Application::getApp()->getController()); if (!$obj instanceof Block) { throw new BlockNotFoundException('block object wrong!'); } return $obj->render(); }
public function run() { $this->auth(); $this->parseURI(); $actionName = $this->getActionName(); if (!$actionName) { $this->sendNotFound(); exit; } $controller = Application::getApp()->getController(); list($module_name, $action_name) = $this->_parseName($actionName); $class_name = sprintf('%s_%s_Action', $module_name, str_replace('.', '_', $action_name)); if (!class_exists($class_name)) { $filename = $controller->getFilePath('action', $actionName); include_once $filename; } if (!class_exists($class_name)) { $this->sendNotFound(); exit; } $class = new $class_name($controller); if (!$class instanceof APIAction) { $this->sendNotFound(); exit; } try { $response = $class->execute(); } catch (Exception $ex) { $message = $ex->getMessage(); $code = $ex->getCode(); $response = new Response(); $response->setCode($code); $response->setMessage($message); } catch (\Exception $ex) { $response = new Response(); $response->setCode(Response::ERROR_CODE_SYSTEM); $response->setMessage($ex->getMessage()); } if ($response == null) { $response = new Response(); $response->setCode(Exception::CODE_ACTION_NOTFOUND); $response->setMessage('未知的动作'); } $this->sendContent($response); exit; }
/** * * @param string $action_name null if use default * @param array $params * @throws NotExistsException * @return string */ public static function generateURL($action_name = null, array $params = array()) { $default_action = Application::getApp()->getDefaultAction(); if ($action_name == null) { $action_name = $default_action; } $route = Route::getInstance(); $routes = $route->get('routes'); $path = array_search(strtolower($action_name), $routes); if (!$path) { throw new NotExistsException('Can not find the path', $action_name); } $main_server = Config::getInstance()->get('main_server'); if (strcasecmp($default_action, $action_name) == 0 && empty($params)) { if (empty($params)) { return $main_server; } else { $path = ''; } } $base = $path; $p = array(); foreach ($params as $key => $value) { if (is_int($key)) { $base .= '/' . $value; } else { $p[] = urlencode($key) . '=' . urlencode($value); } } $base = rtrim($base, '/'); if ($base) { if (Config::getInstance()->get('app.seo.ext')) { $base .= '.' . Config::getInstance()->get('app.seo.ext'); } } if (count($p)) { $base .= '?' . implode('&', $p); } return $main_server . ltrim($base, '/'); }
<?php // $start = microtime(true); $base = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR; define('DIR_ORC_ROOT', $base . 'fw'); //the root path of the framework define('DIR_APP_ROOT', dirname(dirname(__FILE__))); //the root path of this site(application) define('DIR_APP_PUBLIC', dirname(__FILE__)); //the path of the public html folder //define('APP_IN_DEBUG_MODE', true); require DIR_ORC_ROOT . DIRECTORY_SEPARATOR . 'application.php'; \ORC\Application::getApp()->setName('eoffcn_course')->setDefaultAction('Index.Index')->run(); //var_dump(microtime(true) - $start);
case '--app-dir': $dir_app_root = realpath($value); break; case '-i': case '--ignore-exists': $ignore_exists = true; break; case '-y': $yes_to_all = true; break; } } if (empty($dir_app_root)) { $dir_app_root = getcwd(); } define('DIR_APP_ROOT', $dir_app_root); require dirname(dirname(__FILE__)) . '/application.php'; Application::getApp()->setName('Tools'); require dirname(__FILE__) . '/src/schema.php'; $schema = new Schema($ignore_exists, $yes_to_all); $schema->createSchema(); function display_help() { echo <<<'EOD' -h, --help 显示这个帮助信息 -i, --ignore-exists 加上这个参数会强制生成所有表而不忽略已经存在的 -b, --app-dir=APP_ROOT_DIR 网站的根目录,注意不是public_html目录。如果不指定使用当前目录 -y 自动对所有的问题使用Yes EOD; return true; }
<?php use ORC\API\Interior\Server\Server; // $start = microtime(true); $base = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR; define('DIR_ORC_ROOT', $base . 'fw'); //the root path of the framework define('DIR_APP_ROOT', dirname(dirname(__FILE__))); //the root path of this site(application) define('DIR_APP_PUBLIC', dirname(__FILE__)); //the path of the public html folder //define('APP_IN_DEBUG_MODE', true); require DIR_ORC_ROOT . DIRECTORY_SEPARATOR . 'application.php'; \ORC\Application::getApp()->setName('eoffcn_course'); $server = new Server(); $server->run(); //var_dump(microtime(true) - $start);
protected function getSessionKey() { return sprintf('%s%s', Application::getApp()->getName(), static::SESSION_KEY); }
private function getController() { return Application::getApp()->getController(); }
public function execute($action_name) { if ($action_name == '') { $action_name = Application::getApp()->getDefaultAction(); } $action = $this->_retrieveAction($action_name); if ($action == null) { throw new \ORC\Exception\ActionNotFoundException('Action ' . $action_name . ' Not Found!'); } while (method_exists($action, 'forward')) { $new_action_name = $action->forward(); if ($new_action_name) { $action = $this->_retrieveAction($new_action_name); $action_name = $new_action_name; } else { break; } } $this->_action = $action; if (method_exists($action, 'pre_execute')) { $response = $action->pre_execute(); } //if pre_execute returns something, the default execute will not be used if (!isset($response) || !$response) { $response = $action->execute(); } if (!$response) { if (method_exists($action, 'post_execute')) { $response = $action->post_execute(); } } //result is the Response object if (!$response) { throw new \ORC\Exception\ActionException('Action Have No Result', $action_name); } if (!$response instanceof Response) { throw new \ORC\Exception\ActionException('Wrong result from action', $action_name); } if ($response->getViewType() == Action::VIEW_REDIRECT) { $response->sendHeaders(); $response->redirect(); exit; } $view_name = $response->getViewName(); $view = $this->_retrieveView($view_name); if ($view == null) { throw new \ORC\Exception\ViewNotFoundException('View Not Found!', $view_name); } while (method_exists($view, 'forward')) { $new_view_name = $view->forward(); if ($new_view_name) { $view = $this->_retrieveView($new_view_name); $view_name = $new_view_name; } else { break; } } $this->_view = $view; $output = $response->render($view); $response->sendHeaders(); echo $output; }
<?php // $start = microtime(true); $base = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR; define('DIR_ORC_ROOT', $base . 'fw'); //the root path of the framework define('DIR_APP_ROOT', dirname(dirname(__FILE__))); //the root path of this site(application) define('DIR_APP_PUBLIC', dirname(__FILE__)); //the path of the public html folder //define('APP_IN_DEBUG_MODE', true); require DIR_ORC_ROOT . DIRECTORY_SEPARATOR . 'application.php'; \ORC\Application::getApp()->setName('example')->setDefaultAction('Index.Index')->run(); //var_dump(microtime(true) - $start);
protected function resloveNamespace($namespace) { return sprintf('crud_table_%s_%s_%s', Application::getApp()->getName(), str_replace('.', '_', $this->_table->getFullTableName()), $namespace); }