Пример #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();
     }
 }
Пример #2
0
 /**
  * Destroy the test environment.
  */
 public function tearDown()
 {
     // @todo clear httpfoundation request data
     Config::set('session.driver', '');
     Router::$routes = array();
     Router::$names = array();
     URL::$base = '';
     Config::set('application.index', 'index.php');
     Session::$instance = null;
 }
Пример #3
0
 /**
  * Destroy the test enviornment.
  */
 public function tearDown()
 {
     $_SERVER = array();
     Router::$routes = array();
     Router::$names = array();
     Router::$uses = array();
     Router::$fallback = array();
     Config::set('application.ssl', true);
     Config::set('application.url', '');
     Config::set('application.index', 'index.php');
 }
Пример #4
0
 /**
  * Create a redirect response to application root.
  *
  * @param  int       $status
  * @param  bool      $secure
  * @return Redirect
  */
 public static function home($status = 302, $https = false)
 {
     $route = Router::find('home');
     // If a route named "home" exists, we'll route to that instead of using
     // the single slash root URI. THis allows the HTTPS attribute to be
     // respected instead of being hard-coded in the redirect.
     if (!is_null($route)) {
         return static::to_route('home', $status);
     }
     return static::to('/', $status, $https);
 }
Пример #5
0
 /**
  * Dump the results of the currently established route.
  *
  * @return void
  */
 protected function route()
 {
     // We'll call the router using the method and URI specified by
     // the developer on the CLI. If a route is found, we will not
     // run the filters, but simply dump the result.
     $route = Router::route(Request::method(), URI::current());
     if (!is_null($route)) {
         var_dump($route->response());
     } else {
         echo '404: Not Found';
     }
 }
Пример #6
0
 /**
  * Calls the specified route and returns its response.
  *
  * @param  string    $method
  * @param  string    $uri
  * @return Response
  */
 public static function forward($method, $uri)
 {
     return Router::route(strtoupper($method), $uri)->call();
 }
Пример #7
0
 /**
  * Test foreign characters can be used in routes.
  *
  * @group laravel
  */
 public function testForeignCharsInRoutes()
 {
     Route::get(urlencode('مدرس_رياضيات') . '/(:any)', function () {
     });
     Route::get(urlencode('مدرس_رياضيات'), function () {
     });
     Route::get(urlencode('ÇœŪ'), function () {
     });
     Route::get(urlencode('私は料理が大好き'), function () {
     });
     $this->assertEquals(array(urlencode('مدرس_رياضيات')), Router::route('GET', urlencode('مدرس_رياضيات') . '/' . urlencode('مدرس_رياضيات'))->parameters);
     $this->assertEquals(urlencode('مدرس_رياضيات'), Router::route('GET', urlencode('مدرس_رياضيات'))->uri);
     $this->assertEquals(urlencode('ÇœŪ'), Router::route('GET', urlencode('ÇœŪ'))->uri);
     $this->assertEquals(urlencode('私は料理が大好き'), Router::route('GET', urlencode('私は料理が大好き'))->uri);
 }
Пример #8
0
 /**
  * Register a HTTPS route with the router.
  *
  * @param  string        $method
  * @param  string|array  $route
  * @param  mixed         $action
  * @return void
  */
 public static function secure($method, $route, $action)
 {
     Router::secure($method, $route, $action);
 }
Пример #9
0
 /**
  * Load the "routes" file for a given bundle.
  *
  * @param  string  $bundle
  * @return void
  */
 public static function routes($bundle)
 {
     if (static::routed($bundle)) {
         return;
     }
     $path = static::path($bundle) . 'routes' . EXT;
     // By setting the bundle property on the router the router knows what
     // value to replace the (:bundle) place-holder with when the bundle
     // routes are added, keeping the routes flexible.
     Router::$bundle = static::option($bundle, 'handles');
     if (!static::routed($bundle) and file_exists($path)) {
         static::$routed[] = $bundle;
         require $path;
     }
 }
Пример #10
0
 /**
  * Generate a URL from a route name.
  *
  * <code>
  *		// Create a URL to the "profile" named route
  *		$url = URL::to_route('profile');
  *
  *		// Create a URL to the "profile" named route with wildcard parameters
  *		$url = URL::to_route('profile', array($username));
  * </code>
  *
  * @param  string  $name
  * @param  array   $parameters
  * @return string
  */
 public static function to_route($name, $parameters = array())
 {
     if (is_null($route = Routing\Router::find($name))) {
         throw new \Exception("Error creating URL for undefined route [{$name}].");
     }
     // To determine whether the URL should be HTTPS or not, we look for the "https"
     // value on the route action array. The route has control over whether the URL
     // should be generated with an HTTPS protocol string or just HTTP.
     $https = array_get(current($route), 'https', null);
     $uri = trim(static::transpose(key($route), $parameters), '/');
     return static::to($uri, $https);
 }
Пример #11
0
 /**
  * Generate a URL to a controller action.
  *
  * <code>
  *		// Generate a URL to the "index" method of the "user" controller
  *		$url = URL::to_action('user@index');
  *
  *		// Generate a URL to http://example.com/user/profile/taylor
  *		$url = URL::to_action('user@profile', array('taylor'));
  * </code>
  *
  * @param  string  $action
  * @param  array   $parameters
  * @return string
  */
 public static function to_action($action, $parameters = array())
 {
     // This allows us to use true reverse routing to controllers, since
     // URIs may be setup to handle the action that do not follow the
     // typical Laravel controller URI conventions.
     $route = Router::uses($action);
     if (!is_null($route)) {
         return static::explicit($route, $action, $parameters);
     } else {
         return static::convention($action, $parameters);
     }
 }
Пример #12
0
 public static function to_route($name, $parameters = array())
 {
     if (is_null($route = Routing\Router::find($name))) {
         throw new \Exception("Error creating URL for undefined route [{$name}].");
     }
     $https = array_get(current($route), 'https', null);
     $uri = trim(static::transpose(key($route), $parameters), '/');
     return static::to($uri, $https);
 }
Пример #13
0
 public static function to_action($action, $parameters = array())
 {
     $route = Router::uses($action);
     if (!is_null($route)) {
         return static::explicit($route, $action, $parameters);
     } else {
         return static::convention($action, $parameters);
     }
 }
Пример #14
0
<?php

Route::get('(:bundle)/rejigger.js', array('as' => 'rejigger_js', function () {
    return View::make('rejigger::js');
}));
Route::get('(:bundle)/version', array('as' => 'rejigger_version', function () {
    // Don't let the controller mistake this for a regular AJAX call
    unset($_SERVER['HTTP_X_REQUESTED_WITH']);
    $uri = \Rejigger\URI::resolve(Input::get('uri'));
    $route = \Laravel\Routing\Router::route('GET', $uri);
    $response = $route->call();
    $version = md5($response->content);
    // Parse out resources (css & script)
    preg_match_all('/\\<script[^\\>]+src=\\"(?P<src>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $scripts);
    preg_match_all('/\\<link[^\\>]+href=\\"(?P<href>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $styles);
    preg_match_all('/\\<img[^\\>]+src=\\"(?P<src>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $images);
    $resources = array_merge($scripts['src'], $styles['href'], $images['src']);
    $public = path('public');
    foreach ($resources as $resource) {
        $resource = $public . str_replace(\Laravel\URL::base(), '', $resource);
        if (\Laravel\File::exists($resource)) {
            $version .= File::modified($resource);
        }
    }
    return '{ "version": "' . md5($version) . '" }';
}));