* // Get the first URI segment for the request * $first = URI::segment(1); * * // Return a default value if the URI segment doesn't exist * $segment = URI::segment(3, 'Default'); * * * @param int $segment * @param mixed $default * @return string */ public static function segment($segment = null, $default = null) { $segments = Arr::without(explode('/', static::get()), array('')); if ( ! is_null($segment)) $segment = $segment - 1; return Arr::get($segments, $segment, $default); } /** * Get the request URI from the $_SERVER array. * * @return string */ protected static function from_server() { // If the PATH_INFO $_SERVER element is set, we will use since it contains // the request URI formatted perfectly for Laravel's routing engine. if (isset($_SERVER['PATH_INFO'])) { return $_SERVER['PATH_INFO']; } // If the REQUEST_URI is set, we need to extract the URL path since this // should return the URI formatted in a manner similar to PATH_INFO. elseif (isset($_SERVER['REQUEST_URI'])) { return parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); } throw new \Exception('Unable to determine the request URI.'); } /** * Remove extraneous segments from the URI such as the URL and index page. * * These segments need to be removed since they will cause problems in the * routing engine if they are present in the URI. * * @param string $uri * @return string */ protected static function clean($uri) { foreach (array(parse_url(Config::get('application.url'), PHP_URL_PATH), '/index.php') as $value) { $uri = (strpos($uri, $value) === 0) ? substr($uri, strlen($value)) : $uri; } return $uri; } /** * Format the URI. * * If the request URI is empty, a single forward slash will be returned. * * @param string $uri * @return string */ protected static function format($uri) { return (($uri = trim($uri, '/')) == '') ? '/' : $uri; } }