예제 #1
0
 public function dispatch()
 {
     $filepath = $this->modulesPath . $this->module() . '/controllers/' . $this->controller() . '.php';
     if (is_file($filepath)) {
         // we found a valid controller
         // load this module bootstrap.php file if it exists
         $bs = $this->modulesPath . $this->module() . '/bootstrap.php';
         if (is_file($bs)) {
             require_once $bs;
         }
         require_once $filepath;
         $classname = ucfirst($this->module) . '_' . ucfirst($this->controller) . 'Controller';
         $rfc = new ReflectionClass($classname);
         if ($rfc->isSubclassOf('Hayate_Controller') && $rfc->isInstantiable()) {
             Hayate_Event::run('hayate.pre_controller', array($this));
             $controller = $rfc->newInstance();
             Hayate_Event::run('hayate.post_controller', array($this, $controller));
             Hayate_Event::run('hayate.pre_action', array($this));
             $action = $rfc->hasMethod($this->action()) ? $rfc->getMethod($this->action()) : $rfc->getMethod('__call');
             if ($action->isPublic() && strpos($action->getName(), '_') !== 0) {
                 $action->invokeArgs($controller, $this->params());
             } else {
                 if ($action->getName() == '__call') {
                     $action->invoke($controller, $this->action(), $this->params());
                 }
             }
             Hayate_Event::run('hayate.post_action', array($this));
         }
     } else {
         if (true !== Hayate_Event::run('hayate.404', array($this))) {
             $this->errorReporter->setStatus(404);
             throw new Hayate_Exception(sprintf(_('Requested page: "%s" not found.'), Hayate_URI::getInstance()->current()), 404);
         }
     }
 }
예제 #2
0
파일: Router.php 프로젝트: hayate/hayate
 protected function __construct()
 {
     $config = Hayate_Config::load('routes', false);
     if ($config && isset($config->routes)) {
         $this->routes = $config->routes->getArrayCopy();
     }
     if (count($this->routes)) {
         $keys = array_keys($this->routes);
         $values = array_values($this->routes);
         array_walk($keys, array($this, 'trimSlash'));
         array_walk($values, array($this, 'trimSlash'));
         $this->routes = array_combine($keys, $values);
     }
     $base_path = array();
     if (isset($config->core->base_path)) {
         $base_path = preg_split('|/|', $config->core->base_path, -1, PREG_SPLIT_NO_EMPTY);
     }
     $segments = Hayate_URI::getInstance()->segments();
     for ($i = 0; $i < count($base_path); $i++) {
         if (isset($segments[$i]) && $segments[$i] == $base_path[$i]) {
             unset($segments[$i]);
         }
     }
     $this->path = $this->routed_path = implode('/', $segments);
 }
예제 #3
0
파일: URI.php 프로젝트: hayate/hayate
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
예제 #4
0
파일: Cookie.php 프로젝트: heromaeda/hayate
 protected function __construct()
 {
     Hayate_Crypto::getInstance();
     $this->config = Hayate_Config::load('cookie');
     $this->encrypt = isset($this->config->cookie->encrypt) ? (bool) $this->config->cookie->encrypt : false;
     $this->expire = isset($this->config->cookie->expire) ? $this->config->cookie->expire : 0;
     $this->path = isset($this->config->cookie->path) ? $this->config->cookie->path : '/';
     $this->domain = isset($this->config->cookie->domain) ? $this->config->cookie->domain : Hayate_URI::getInstance()->hostname();
     $this->secure = isset($this->config->cookie->secure) ? (bool) $this->config->cookie->secure : false;
     $this->httponly = isset($this->config->cookie->httponly) ? (bool) $this->config->cookie->httponly : false;
 }
예제 #5
0
파일: HTML.php 프로젝트: hayate/hayate
 public static function form($action = NULL, $method = 'post', $upload = FALSE, array $attribs = array())
 {
     if (NULL === $action) {
         $action = Hayate_URI::getInstance()->current();
     }
     $buf = '<form action="' . $action . '" method="' . $method . '"';
     if ($upload) {
         $buf .= ' enctype="multipart/form-data"';
     }
     foreach ($attribs as $key => $val) {
         $buf .= " {$key}=\"{$val}\"";
     }
     $buf .= '>';
     echo $buf . "\n";
 }
예제 #6
0
 /**
  * This will trigger an exception if not overwritten
  */
 public function __call($method, array $args)
 {
     Hayate_Log::info(__METHOD__ . ' ' . sprintf(_('method "%s" not found.'), $method));
     throw new Hayate_Exception(sprintf(_('"%s" not found.'), Hayate_URI::getInstance()->current()), 400);
 }
예제 #7
0
 public function refresh()
 {
     $this->redirect(Hayate_URI::getInstance()->current(), 302);
 }
예제 #8
0
 public function dispatch()
 {
     // $filepath = $this->modulesPath.$this->module().'/controllers/'.$this->controller().'.php';
     if ($this->controllerExists($filepath)) {
         // we found a valid controller
         // load this module bootstrap.php file if it exists
         $bs = $this->modulesPath . $this->module() . '/bootstrap.php';
         if (is_file($bs)) {
             require_once $bs;
         }
         require_once $filepath;
         $classname = ucfirst($this->module) . '_' . ucfirst($this->controller) . 'Controller';
         $rfc = new ReflectionClass($classname);
         if ($rfc->isSubclassOf('Hayate_Controller') && $rfc->isInstantiable()) {
             Hayate_Event::run('hayate.pre_controller', array($this));
             $controller = new $classname();
             $controller->_init();
             Hayate_Event::run('hayate.post_controller', array($this, $controller));
             $action = NULL;
             $params = $this->params();
             if ($rfc->hasMethod($this->action())) {
                 $method = $rfc->getMethod($this->action());
                 if (0 !== strpos($this->action(), '_') && $method->isPublic()) {
                     $action = $this->action();
                 }
             } else {
                 if ($rfc->hasMethod('index')) {
                     $method = $rfc->getMethod('index');
                     array_unshift($params, $this->action());
                     if ($method->getNumberOfParameters() >= count($params) && count($params) >= $method->getNumberOfRequiredParameters() && $method->isPublic()) {
                         $action = 'index';
                     }
                 }
             }
             if (!isset($action)) {
                 // if action does not exists the default __call
                 // method will be called
                 $action = $this->action();
             }
             $controller->_preDispatch();
             Hayate_Event::run('hayate.pre_action', array($this));
             switch (count($params)) {
                 case 0:
                     $controller->{$action}();
                     break;
                 case 1:
                     $controller->{$action}($params[0]);
                     break;
                 case 2:
                     $controller->{$action}($params[0], $params[1]);
                     break;
                 case 3:
                     $controller->{$action}($params[0], $params[1], $params[2]);
                     break;
                 case 4:
                     $controller->{$action}($params[0], $params[1], $params[2], $params[3]);
                     break;
                 case 5:
                     $controller->{$action}($params[0], $params[1], $params[2], $params[3], $params[4]);
                     break;
                 default:
                     call_user_func_array(array($controller, $action), $params);
             }
             Hayate_Event::run('hayate.post_action', array($this));
         }
     } else {
         if (true !== Hayate_Event::run('hayate.404', array($this))) {
             $this->errorReporter->setStatus(404);
             throw new Hayate_Exception(sprintf(_('Requested page: "%s" not found.'), Hayate_URI::getInstance()->current()), 404);
         }
     }
 }