Example #1
0
 /**
  * Register the 404 not found callback
  *
  * @param closure
  */
 public static function not_found($callbacks)
 {
     if ($callbacks instanceof Closure) {
         $callbacks = array('main' => $callbacks);
     }
     Router::$not_found = $callbacks;
 }
Example #2
0
 public function test_reversing()
 {
     $cfg = \System\Settings::get('domains');
     $list = array_keys($cfg);
     $host = $list[0];
     $this->assertEquals(\System\Router::get_url($host, 'system_resource', array('static', 'a', 'b')), '/static/a/b');
 }
Example #3
0
 /** Get domain init data
  * @return mixed
  */
 public function load_config()
 {
     $cfg = cfg('domains', \System\Router::get_domain($this->host));
     $this->rules = def($cfg['rules'], null);
     $this->layout = (array) def($cfg['layout'], array());
     $this->policies = (array) def($cfg['policies'], array());
     $this->context = (array) def($cfg['context'], array());
     $this->init = (array) def($cfg['init'], array());
     return $this;
 }
Example #4
0
 /**
  * 实例化help层
  * @param string $class
  * @return 
  */
 public function H($class)
 {
     $class = str_replace(array('.', '#'), array('\\', '.'), $class);
     $class = '\\AppMain\\helper\\' . $class . 'Helper';
     return \System\Router::getClass($class);
 }
Example #5
0
<?php

\System\Database::init();
if (Godmode\Router::entered($request)) {
    Godmode\Router::init();
    if ($request->logged_in()) {
        if (!\Godmode\Gatekeeper::canAccessGodmode($request->user)) {
            throw new \System\Error\AccessDenied();
        }
    } else {
        $url_login = \System\Router::get_url($request->host, 'god_login');
        if ($request->path != $url_login) {
            redirect_now($url_login);
        }
    }
}
Example #6
0
 /**
  * URL alias for reponse::url
  *
  * @param string $name Named route name
  * @param array  $args Arguments for route
  * @param int    $var  Variation number of URL
  * @return string
  */
 public function url($name, array $args = array(), $var = 0)
 {
     return \System\Router::get_url($this->request->host, $name, $args, $var);
 }
Example #7
0
 public static function entered(\System\Http\Request $request)
 {
     return \System\Router::json_preg_match('^' . cfg('godmode', 'path_prefix'), $request->path);
 }
Example #8
0
 public static function get_url($src, $type, $name)
 {
     try {
         $domain = \System\Settings::get('resources', 'domain');
     } catch (\System\Error\Config $e) {
         $domain = null;
     }
     $map = self::get_map();
     $post = null;
     if (isset($map[$type])) {
         $cname = $map[$type];
         if ($cname::POSTFIX_OUTPUT) {
             $post = $cname::POSTFIX_OUTPUT;
         }
     }
     if (!$post && strpos($name, '.')) {
         $name = explode('.', $name);
         $post = '.' . array_pop($name);
         $name = implode('.', $name);
     }
     $name = $name . '.' . self::get_serial() . ($post ? $post : '');
     $path = \System\Router::get_first_url('system_resource', array($src, $type, $name));
     if ($domain) {
         $path = '//' . $domain . $path;
     }
     return $path;
 }
Example #9
0
<?php

use System\Router;
Router::get("", "Index@index");
Router::get("airforces", "Index@airforces");
Router::get("ankieta", "Index@ankieta");
Router::get("ksiegagosci", "Index@ksiegagosci");
Router::get("user", "User@index");
Router::get("user/login", "User@login");
Router::post("user/login", "User@postLogin");
Router::get("user/login/{abc}", "User@login");
Router::get("user/register", "User@register");
Router::post("user/register", "User@postRegister");
Router::get("user/logout", "User@logout");
Router::get("photos", "Photos@index");
Router::get("photos/remembered", "Photos@rememberedPhotos");
Router::get("photos/search", "Photos@searchPhotos");
Router::get("photos/add", "Photos@addPhoto");
Router::post("photos/add", "Photos@postAddPhoto");
Router::post("photos/remember", "Photos@postRememberPhotos");
Router::post("photos/forget", "Photos@postForgetPhotos");
Router::get('ajax/searchPhotos/{text}', "Ajax@searchPhotos");
Example #10
0
<?php

use System\Router;
require dirname(__FILE__) . '/core/setting/setting.php';
$router = new Router();
$router->run();
Example #11
0
 /**
  * Gets you full URL
  *
  * @param String $name
  * @param array  $args
  * @param int    $variation
  * @return String
  */
 public function url_full($name, array $args = array(), $variation = 0)
 {
     return $this->request->protocol . '://' . $this->request->host . \System\Router::get_url($this->request->host, $name, $args, $variation);
 }
Example #12
0
<?php

$policy = function ($rq, $res) {
    $past_route = function ($rq, $name) {
        return \System\Router::get_route_str($rq->host, $name);
    };
    $url_pack = $past_route($rq, 'system_resource');
    $url_pack = str_replace(array('{res_src}', '{res_type}', '{res_path}'), array('media', 'schema', '{name}.' . \System\Resource::get_serial()), $url_pack);
    $urls = array('pack' => $url_pack, 'schema' => $past_route($rq, 'api_model_schema'), 'browse' => $past_route($rq, 'api_model_browse'), 'create' => $past_route($rq, 'api_model_create'), 'edit' => $past_route($rq, 'api_model_object_edit'), 'drop' => $past_route($rq, 'api_model_object_drop'));
    $rq->fconfig = array_merge_recursive($rq->fconfig, array('models' => array('url' => $urls)));
    return true;
};