Ejemplo n.º 1
0
 public final function set_location($uri)
 {
     $uri = moojon_uri::clean_uri($uri);
     $route_match = moojon_routes::map($uri);
     $data = $route_match->get_params();
     $this->app_name = $data['app'];
     $this->controller_name = $data['controller'];
     $this->action_name = $data['action'];
     if (self::get_app_class($this->app_name) != get_class($this)) {
         $location = moojon_config::get('index_file') . $uri;
         $this->redirect($location);
     }
     $this->set_controller();
 }
Ejemplo n.º 2
0
 public static function app_from_uri($uri)
 {
     $uri = moojon_uri::clean_uri($uri);
     $route_match = moojon_routes::map($uri);
     $data = $route_match->get_params();
     foreach ($data as $key => $value) {
         moojon_request::set($key, $value);
     }
     $app = $data['app'];
     self::require_view_functions();
     require_once moojon_paths::get_app_path($app);
     $app_class = self::get_app_class($app);
     return new $app_class($uri);
 }
Ejemplo n.º 3
0
 protected function __construct()
 {
     $uri = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : $_SERVER['PATH_INFO'];
     $this->uri = self::clean_uri($uri);
     if ($match = moojon_routes::map($this->uri)) {
         $config = array_merge(moojon_config::get_data(), moojon_config::read(moojon_paths::get_project_config_environment_app_directory(ENVIRONMENT, $match->get('app'))));
         if (array_key_exists('secure', $config) && $config['secure'] === true && !moojon_security::authenticate()) {
             moojon_cache::disable();
             $pattern = ':app/:controller/:action';
             $match = new moojon_route_match($pattern, array_merge($match->get_params(), array('app' => $config['security_app'], 'controller' => $config['security_controller'], 'action' => $config['security_action'])), new moojon_route($pattern));
             $this->uri = $config['security_app'] . '/' . $config['security_controller'] . '/' . $config['security_action'];
         }
         $this->match = $match;
         $this->data = $this->match->get_params();
         $this->route = $this->match->get_route();
         self::try_define('APP', $this->data['app']);
         self::try_define('CONTROLLER', $this->data['controller']);
         self::try_define('ACTION', $this->data['action']);
     } else {
         self::_404($this->uri);
     }
 }
Ejemplo n.º 4
0
 private function map_member_routes($uris = array())
 {
     $id = array_shift($uris);
     $uri = implode('/', $uris);
     $id_property = $this->id_property;
     $params = array_merge($this->params, array($id_property => $id));
     $relationship_routes = $this->get_relationship_routes();
     $params['relationship_routes'] = $relationship_routes;
     $pattern = '';
     $routes = array_merge(array_key_exists('member_routes', $this->params) ? $this->params['member_routes'] : array(), $relationship_routes);
     if ($routes && ($route = moojon_routes::map($uri, $routes, false))) {
         $new_params = $route->get_params();
         if (array_key_exists('resource', $new_params)) {
             $id_property = moojon_primary_key::get_foreign_key($this->resource);
             $params[$id_property] = $id;
         }
         $pattern = ":{$id_property}/" . $route->get_pattern();
         $params = array_merge($params, $new_params);
     } else {
         switch ($this->method) {
             case 'get':
                 if (!$uri) {
                     $pattern = ":{$id_property}/";
                     $params['action'] = 'show';
                 } else {
                     if ($uri == 'edit' || $uri == 'delete' || $uri == 'show') {
                         $pattern = ":{$id_property}/{$uri}";
                         $params['action'] = $uri;
                     }
                 }
                 break;
             case 'post':
                 $pattern = 'create';
                 $params['action'] = $pattern;
                 break;
             case 'put':
                 $pattern = 'update';
                 $params['action'] = $pattern;
                 break;
             case 'delete':
                 $pattern = 'destroy';
                 $params['action'] = $pattern;
                 break;
         }
     }
     return $this->match_route($pattern, $params, false);
 }