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
54e0bef6
Commit
54e0bef6
authored
Jan 27, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified the controller_key method in the router.
parent
82f56f95
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
11 deletions
+15
-11
router.php
laravel/routing/router.php
+15
-11
No files found.
laravel/routing/router.php
View file @
54e0bef6
...
@@ -187,6 +187,9 @@ class Router {
...
@@ -187,6 +187,9 @@ class Router {
{
{
$pattern
=
'#^'
.
static
::
wildcards
(
$route
)
.
'$#'
;
$pattern
=
'#^'
.
static
::
wildcards
(
$route
)
.
'$#'
;
// If we get a match, we'll return the route and slice off
// the first parameter match, as preg_match sets the first
// array item to the full-text match.
if
(
preg_match
(
$pattern
,
$destination
,
$parameters
))
if
(
preg_match
(
$pattern
,
$destination
,
$parameters
))
{
{
return
new
Route
(
$route
,
$action
,
array_slice
(
$parameters
,
1
));
return
new
Route
(
$route
,
$action
,
array_slice
(
$parameters
,
1
));
...
@@ -263,20 +266,21 @@ class Router {
...
@@ -263,20 +266,21 @@ class Router {
*/
*/
protected
static
function
controller_key
(
$segments
,
$directory
)
protected
static
function
controller_key
(
$segments
,
$directory
)
{
{
$reverse
=
array_reverse
(
$segments
,
true
);
for
(
$i
=
count
(
$segments
)
-
1
;
$i
>=
0
;
$i
--
)
{
// To find the proper controller, we need to iterate backwards through
// To find the proper controller, we need to iterate backwards through
// the URI segments and take the first file that matches. That file
// the URI segments and take the first file that matches. That file
// should be the deepest possible controller matched by the URI.
// should be the deepest possible controller matched by the URI.
// Once we find it, we'll return its index key.
if
(
file_exists
(
$directory
.
implode
(
'/'
,
$segments
)
.
EXT
))
foreach
(
$reverse
as
$key
=>
$value
)
{
{
$controller
=
implode
(
'/'
,
array_slice
(
$segments
,
0
,
$key
+
1
))
.
EXT
;
return
$i
+
1
;
if
(
file_exists
(
$directory
.
$controller
))
{
return
$key
+
1
;
}
}
// If a controller did not exist for the segments, we will pop
// the last segment off of the array so that on the next run
// through the loop we'll check one folder up from the one
// we checked on this iteration.
array_pop
(
$segments
);
}
}
}
}
...
...
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