Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
31cf44c3
Commit
31cf44c3
authored
Feb 10, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on routing.
parent
4330124d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
42 deletions
+72
-42
route.php
laravel/routing/route.php
+71
-15
url.php
laravel/url.php
+1
-27
No files found.
laravel/routing/route.php
View file @
31cf44c3
...
@@ -56,32 +56,53 @@ class Route {
...
@@ -56,32 +56,53 @@ class Route {
// Extract each URI from the route key. Since the route key has the request
// Extract each URI from the route key. Since the route key has the request
// method, we will extract that from the string. If the URI points to the
// method, we will extract that from the string. If the URI points to the
// root of the application, a single forward slash
will be
returned.
// root of the application, a single forward slash
is
returned.
$uris
=
array_get
(
$action
,
'handles'
,
array
(
$key
));
$uris
=
array_get
(
$action
,
'handles'
,
array
(
$key
));
$this
->
uris
=
array_map
(
array
(
$this
,
'
extract
'
),
$uris
);
$this
->
uris
=
array_map
(
array
(
$this
,
'
destination
'
),
$uris
);
// Determine the bundle in which the route was registered. We will know
// Determine the bundle in which the route was registered. We will know
// the bundle by
feeding the URI into the bundle::handles method, which
// the bundle by
using the bundle::handles method, which will return
//
will return
the bundle assigned to that URI.
// the bundle assigned to that URI.
$this
->
bundle
=
Bundle
::
handles
(
$this
->
uris
[
0
]);
$this
->
bundle
=
Bundle
::
handles
(
$this
->
uris
[
0
]);
$this
->
parameters
=
array_map
(
'urldecode'
,
$parameters
);
$defaults
=
array_get
(
$action
,
'defaults'
,
array
());
$this
->
parameters
=
array_merge
(
$parameters
,
$defaults
);
// Once we have set the parameters and URIs, we'll transpose the route
// parameters onto the URIs so that the routes response naturally to
// the handles without the wildcards messing them up.
foreach
(
$this
->
uris
as
&
$uri
)
{
$uri
=
$this
->
transpose
(
$uri
,
$this
->
parameters
);
}
}
}
/**
/**
*
Retrieve the URI from a given route destination
.
*
Substitute the parameters in a given URI
.
*
*
* If the request is to the application root, a slash is returned.
* @param string $uri
*
* @param array $parameters
* @param string $segment
* @return string
* @return string
*/
*/
protected
static
function
extract
(
$segment
)
public
static
function
transpose
(
$uri
,
$parameters
)
{
// Spin through each route parameter and replace the route wildcard segment
// with the corresponding parameter passed to the method. Afterwards, we'll
// replace all of the remaining optional URI segments.
foreach
((
array
)
$parameters
as
$parameter
)
{
{
$uri
=
substr
(
$segment
,
strpos
(
$segment
,
' '
)
+
1
);
if
(
!
is_null
(
$parameter
))
{
$uri
=
preg_replace
(
'/\(.+?\)/'
,
$parameter
,
$uri
,
1
);
}
}
return
(
$uri
!==
'/'
)
?
trim
(
$uri
,
'/'
)
:
$uri
;
// If there are any remaining optional place-holders, we'll just replace
// them with empty strings since not every optional parameter has to be
// in the array of parameters that were passed.
return
str_replace
(
array_keys
(
Router
::
$optional
),
''
,
$uri
);
}
}
/**
/**
...
@@ -92,9 +113,8 @@ class Route {
...
@@ -92,9 +113,8 @@ class Route {
public
function
call
()
public
function
call
()
{
{
// The route is responsible for running the global filters, and any
// The route is responsible for running the global filters, and any
// filters defined on the route itself. Since all incoming requests
// filters defined on the route itself, since all incoming requests
// come through a route (either defined or ad-hoc), it makes sense
// come through a route (either defined or ad-hoc).
// to let the route handle the global filters.
$response
=
Filter
::
run
(
$this
->
filters
(
'before'
),
array
(),
true
);
$response
=
Filter
::
run
(
$this
->
filters
(
'before'
),
array
(),
true
);
if
(
is_null
(
$response
))
if
(
is_null
(
$response
))
...
@@ -102,6 +122,9 @@ class Route {
...
@@ -102,6 +122,9 @@ class Route {
$response
=
$this
->
response
();
$response
=
$this
->
response
();
}
}
// We always return a Response instance from the route calls, so
// we'll use the prepare method on the Response class to make
// sure we have a valid Response isntance.
$response
=
Response
::
prepare
(
$response
);
$response
=
Response
::
prepare
(
$response
);
Filter
::
run
(
$this
->
filters
(
'after'
),
array
(
$response
));
Filter
::
run
(
$this
->
filters
(
'after'
),
array
(
$response
));
...
@@ -218,6 +241,39 @@ class Route {
...
@@ -218,6 +241,39 @@ class Route {
}));
}));
}
}
/**
* Register a route with the router.
*
* <code>
* // Register a route with the router
* Router::register('GET /', function() {return 'Home!';});
*
* // Register a route that handles multiple URIs with the router
* Router::register(array('GET /', 'GET /home'), function() {return 'Home!';});
* </code>
*
* @param string|array $route
* @param mixed $action
* @param bool $https
* @return void
*/
public
static
function
to
(
$route
,
$action
)
{
Router
::
register
(
$route
,
$action
);
}
/**
* Register a HTTPS route with the router.
*
* @param string|array $route
* @param mixed $action
* @return void
*/
public
static
function
secure
(
$route
,
$action
)
{
Router
::
secure
(
$route
,
$action
);
}
/**
/**
* Extract the URI string from a route destination.
* Extract the URI string from a route destination.
*
*
...
...
laravel/url.php
View file @
31cf44c3
...
@@ -204,7 +204,7 @@ class URL {
...
@@ -204,7 +204,7 @@ class URL {
// Since assets are not served by Laravel, we do not need to come through
// Since assets are not served by Laravel, we do not need to come through
// the front controller. So, we'll remove the application index specified
// the front controller. So, we'll remove the application index specified
// in the application configuration from the
generated
URL.
// in the application configuration from the URL.
if
((
$index
=
Config
::
get
(
'application.index'
))
!==
''
)
if
((
$index
=
Config
::
get
(
'application.index'
))
!==
''
)
{
{
$url
=
str_replace
(
$index
.
'/'
,
''
,
$url
);
$url
=
str_replace
(
$index
.
'/'
,
''
,
$url
);
...
@@ -246,30 +246,4 @@ class URL {
...
@@ -246,30 +246,4 @@ class URL {
return
static
::
to
(
Route
::
transpose
(
$uri
,
$parameters
),
$https
);
return
static
::
to
(
Route
::
transpose
(
$uri
,
$parameters
),
$https
);
}
}
/**
* Substitute the parameters in a given URI.
*
* @param string $uri
* @param array $parameters
* @return string
*/
public
static
function
transpose
(
$uri
,
$parameters
)
{
// Spin through each route parameter and replace the route wildcard segment
// with the corresponding parameter passed to the method. Afterwards, we'll
// replace all of the remaining optional URI segments.
foreach
((
array
)
$parameters
as
$parameter
)
{
if
(
!
is_null
(
$parameter
))
{
$uri
=
preg_replace
(
'/\(.+?\)/'
,
$parameter
,
$uri
,
1
);
}
}
// If there are any remaining optional place-holders, we'll just replace
// them with empty strings since not every optional parameter has to be
// in the array of parameters that were passed.
return
str_replace
(
array_keys
(
Router
::
$optional
),
''
,
$uri
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment