Exemplo n.º 1
0
 /**
  * Register opinionated controllers
  * 
  * @param array		$controllers	the controllers and config
  * @param string	$bundle			the bundle where the controller can be found
  * @param string	$url_prefix		a global url prefix
  * @param string	$route_type		the type of the route (pages or api)
  * @param array		$parents
  */
 public static function opinionated($controllers, $bundle, $url_prefix, $route_type, $parents = array())
 {
     if (!ends_with($url_prefix, '/')) {
         $url_prefix .= '/';
     }
     foreach ($controllers as $controller => $options) {
         list($types, $children) = $options;
         foreach ($types as $type) {
             list($method, $plural, $has_identity, $postfix) = static::$types[$type];
             $segment = $controller;
             $action = ($bundle ? $bundle . '::' : '') . implode('.', $parents) . (count($parents) > 0 ? '.' : '') . $segment . '@' . $type;
             if ($plural) {
                 $segment = Str::plural($segment);
             }
             $prefixes = array_map(function ($parent) {
                 return $parent ? $parent . '/(:any)/' : '(:any)/';
             }, $parents);
             $prefix = implode('', $prefixes);
             $route = $url_prefix . $prefix . $segment . ($has_identity ? '/(:any)' : '') . ($route_type == 'pages' && $postfix ? '/' . $postfix : '');
             if ($route_type == 'pages') {
                 $method = '*';
             }
             Router::register($method, $route, $action);
         }
         $parents[] = $controller;
         if (is_array($children)) {
             static::opinionated($children, $bundle, $url_prefix, $route_type, $parents);
         }
         $parents = array();
     }
 }
Exemplo n.º 2
0
 /**
  * Register a route that handles any request method.
  *
  * @param  string|array  $route
  * @param  mixed         $action
  * @return void
  */
 public static function any($route, $action)
 {
     Router::register('*', $route, $action);
 }
Exemplo n.º 3
0
    #require_once path('sys') . 'error' . EXT;
    Error::native($code, $error, $file, $line);
});
register_shutdown_function(function () {
    #require_once path('sys') . 'error' . EXT;
    Error::shutdown();
});
error_reporting(-1);
Bundle::start(DEFAULT_BUNDLE);
foreach (Bundle::$bundles as $bundle => $config) {
    if ($config['auto']) {
        Bundle::start($bundle);
    }
}
Router::register('*', '(:all)', function () {
    return Event::first('404');
});
$uri = URI::current();
$languages = Config::get('application.languages', array());
$languages[] = Config::get('application.language');
foreach ($languages as $language) {
    if (preg_match("#^{$language}(?:\$|/)#i", $uri)) {
        Config::set('application.language', $language);
        $uri = trim(substr($uri, strlen($language)), '/');
        break;
    }
}
if ($uri == '') {
    $uri = '/';
}
URI::$uri = $uri;