내가 좋아하는 MVC의 ActionController가 무엇인가요?
- /*
- * MST_Library v3.1
- * @autohr Janpoem
- */
- if (!define('IN_MST_CORE'))
- exit('MST_ActionController는 단일을 포함할 수 없습니다!');
- if (!definated(MST_Core::LITE_MODE)) {
- MST_Core: :import(array(
- 'MST/ActionController/Request',
- 'MST/ActionController/Router',
- ), MST_Core::P_LIB);
- }
- 추상 클래스 MST_ActionController {
- const
- NO_RENDER = false,
- IS_RENDER = 'ControlLER_IS_RENDER',
- PF_CONTROLLER = '컨트롤러',
- PF_ACTION = '액션',
- FILE = '파일 ',
- VIEW = '보기',
- TEXT = '텍스트',
- ACTION = '액션',
- WIDGET = '위젯',
- CUSTOM_VIEW = 'custom_view';
-
- private static
- $_request = null,
- $_instance = null,
- $_currentView = null;
-
- # @todo 此处的处理应该放到controller被实例化以后, dispatch应该有一个具体含义
- final static public function dispatch(array $config = null, $beforeDispatch = null) {
- if (self::$_instance == null) {
- $request = new MST_ActionController_Request($config['request']);
- $router = new MST_ActionController_Router($config['routes']);
- $router->routing($request);
- $controller = $ request['controller'];
- $controller = MST_String::camelize2($controller) . static::PF_ControlLER;
- if ($request['module'] != null) {
- $module = $request['module'];
- if (strpos($module, '/') !== false)
- $module = str_replace('/', '_', $module);
- $controller = $module . '_' . $controller;
- }
- if (is_callable($beforeDispatch)) {
- call_user_func_array($beforeDispatch, array($request, & $controller));
- }
- $GLOBALS['DATA_CACHE ']['request'] = & $request;
- if (!class_exists($controller))
- MST_Core::error(202, $controller);
- else
- self::$_instance = new $controller();
- }
- }
-
- 공개
- $layout = false,
- $format = 'html',
- $params = null,
- $autoLoadHelper = false;
-
- protected
- $comet = 0,
- $viewPath = null,
- $defaultRender = self::VIEW;
-
- 추상 공용 함수 애플리케이션 ();
-
- 개인 함수 __construct()
- {
- if ($this->comet <= 0)
- ob_start();
- $this->params = & $GLOBALS['DATA_CACHE']['request'];
- $this->viewPath = Trim(
- $this->params['module'] . '/' . $this-> ;params['controller'], '/');
- if ($this->application() !== self::NO_RENDER)
- $this->action($this->params ['action']);
- }
-
- 공개 함수 __destruct() {
- if (!definated(self::IS_RENDER) && self::$_currentView != null) {
- 스위치 ($this->defaultRender) {
- 케이스 self::VIEW :
- 케이스 self::TEXT :
- 케이스 self::ACTION :
- 케이스 self::WIDGET :
- # $this->defaultRender = $mode;
- break;
- default :
- $this->defaultRender = self::VIEW;
- }
- $this->render(
- $this->defaultRender,
- self::$_currentView
- );
- }
- if (self::$_instance != null)
- self::$_instance = null ;
- if (self::$_request != null)
- self::$_request = null;
- }
-
- 보호 함수 작업($action) {
- $name = MST_String::camelize($action);
- $actName = $name . self::PF_ACTION;
- if (!method_exists($this, $actName))
- MST_Core::error(203, $actName);
- $actRef = new ReflectionMethod($this, $actName);
- if ($actRef->isPrivate() || $actRef->isProtected()
- && !constant(MST_ActionController_Router::IS_MAP))
- MST_Core::error(203, $actName);
- if ($this->$actName() !== self::NO_RENDER && self::$_currentView == null)
- self::$_currentView = $action;
- return $this;
- }
-
- /**
- * 출력, URL 점프
- */
- 보호 함수 리디렉션($url) {
- if (defed(self::IS_RENDER)) return self::NO_RENDER;
- 정의(self::IS_RENDER, true);
- header('Location:'.linkUri($url));
- return $this;
- }
-
- // XML 렌더링
- // JAVASCRIPT
- 보호 함수 렌더링(
- $mode = null,
- $content = null,
- array $options = null)
- {
- if (definition(self) ::IS_RENDER)) return self::NO_RENDER;
- 정의(self::IS_RENDER, true);
- if ($mode == null) $mode = $this->defaultRender;
- if ( $mode == self::VIEW)
- $content = $this->viewPath . '/' . $content;
- MST_ActionView::instance()
- ->할당($this)
- ->setOptions($options)
- ->render($mode, $content);
- $this를 반환하세요.
- }
-
- 보호 함수 customRender($file, $path, array $options = null) {
- return $this->render(self::CUSTOM_VIEW, array($file, $path), $options );
- }
-
- 보호 함수 setView($val) {
- self::$_currentView = $val;
- }
-
- 보호 함수 setViewOption($key, $ val) {
- MST_ActionView::instance()->setOption($key, $val);
- return $this;
- }
-
- 보호 함수 getViewOption($key) {
- return MST_ActionView::instance()->getOption($key);
- }
-
- 보호 함수 setViewOptions(array $options) {
- MST_ActionView::instance()->setOptions ($options);
- return $this;
- }
-
- 보호 함수 getViewOptions() {
- return MST_ActionView::instance()->getOptions();
- }
-
- 보호 함수 doComet(Closure $fn) {
- $times = 0;
- set_time_limit(0);
- while(true) {
- ob_flush();
- 플러시( );
- $times ;
- $result = call_user_func($fn, $times, $this);
- if ($result === false) {
- break;
- }
- usleep(10000);
- sleep($this->comet);
- }
- }
- }
复system代码
|