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
82f3784d
Commit
82f3784d
authored
Sep 20, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored and comment route loader.
parent
a8dbe777
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
10 deletions
+29
-10
loader.php
laravel/routing/loader.php
+29
-10
No files found.
laravel/routing/loader.php
View file @
82f3784d
<?php
namespace
Laravel\Routing
;
use
Laravel\Arr
;
use
RecursiveIteratorIterator
as
Iterator
;
use
RecursiveDirectoryIterator
as
DirectoryIterator
;
class
Loader
{
...
...
@@ -41,6 +43,9 @@ class Loader {
/**
* Load the applicable routes for a given URI.
*
* The application route directory will be checked for nested route files and an
* array of all applicable routes will be returned based on the URI segments.
*
* @param string $uri
* @return array
*/
...
...
@@ -59,26 +64,39 @@ class Loader {
*/
protected
function
nested
(
$segments
)
{
$routes
=
array
();
// Work backwards through the URI segments until we find the deepest possible
// matching route directory. Once we find it, we will return those routes.
foreach
(
array_reverse
(
$segments
,
true
)
as
$key
=>
$value
)
{
// First we check to determine if there is a route file matching the segment
// of the URI. If there is, its routes will be merged into the route array.
if
(
file_exists
(
$path
=
$this
->
nest
.
implode
(
'/'
,
array_slice
(
$segments
,
0
,
$key
+
1
))
.
EXT
))
{
return
require
$path
;
$routes
=
array_merge
(
$routes
,
require
$path
)
;
}
elseif
(
file_exists
(
$path
=
str_replace
(
'.php'
,
'/routes.php'
,
$path
)))
// Even if we have already loaded routes for the URI, we still want to check
// for a "routes.php" file which could handle the root route and any routes
// that are impossible to handle in an explicitly named file.
if
(
file_exists
(
$path
=
str_replace
(
'.php'
,
'/routes.php'
,
$path
)))
{
return
require
$path
;
$routes
=
array_merge
(
$routes
,
require
$path
)
;
}
if
(
count
(
$routes
)
>
0
)
return
$routes
;
}
return
array
()
;
return
$routes
;
}
/**
* Get every route defined for the application.
*
* For fast performance, if the routes have already been loaded once, they will not
* be loaded again, and the same routes will be returned on subsequent calls.
*
* @return array
*/
public
function
everything
()
...
...
@@ -88,14 +106,15 @@ class Loader {
$routes
=
array
();
// Since route files can be nested deep within the route directory, we need to
// recursively spin through the directory to find every file.
$directoryIterator
=
new
\RecursiveDirectoryIterator
(
$this
->
nest
);
$recursiveIterator
=
new
\RecursiveIteratorIterator
(
$directoryIterator
,
\RecursiveIteratorIterator
::
SELF_FIRST
);
// recursively spin through each directory to find every file.
$recursiveIterator
=
new
Iterator
(
new
DirectoryIterator
(
$this
->
nest
),
Iterator
::
SELF_FIRST
);
foreach
(
$
recursiveI
terator
as
$file
)
foreach
(
$
i
terator
as
$file
)
{
if
(
filetype
(
$file
)
===
'file'
)
// Since some Laravel developers may place HTML files in the route directories, we will
// check for the PHP extension before merging the file. Typically, the HTML files are
// present in installations that are not using mod_rewrite and the public directory.
if
(
filetype
(
$file
)
===
'file'
and
strpos
(
$file
,
EXT
)
!==
false
)
{
$routes
=
array_merge
(
require
$file
,
$routes
);
}
...
...
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