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
096280c9
Commit
096280c9
authored
Sep 20, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring route loader and router.
parent
82f3784d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
30 deletions
+22
-30
loader.php
laravel/routing/loader.php
+13
-13
router.php
laravel/routing/router.php
+8
-9
index.php
public/index.php
+1
-8
No files found.
laravel/routing/loader.php
View file @
096280c9
...
@@ -64,31 +64,25 @@ class Loader {
...
@@ -64,31 +64,25 @@ class Loader {
*/
*/
protected
function
nested
(
$segments
)
protected
function
nested
(
$segments
)
{
{
$routes
=
array
();
// Work backwards through the URI segments until we find the deepest possible
// Work backwards through the URI segments until we find the deepest possible
// matching route directory. Once we find it, we will return those routes.
// matching route directory. Once we find it, we will return those routes.
foreach
(
array_reverse
(
$segments
,
true
)
as
$key
=>
$value
)
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
))
if
(
file_exists
(
$path
=
$this
->
nest
.
implode
(
'/'
,
array_slice
(
$segments
,
0
,
$key
+
1
))
.
EXT
))
{
{
$routes
=
array_merge
(
$routes
,
require
$path
)
;
return
require
$path
;
}
}
// Even if we
have already loaded routes for the URI, we still want to check
// Even if we
didn't find a matching file for the segment, we still want to
//
for a "routes.php" file which could handle the root route and any routes
//
check for a "routes.php" file which could handle the root route and any
// that are impossible to handle in an explicitly named file.
//
routes
that are impossible to handle in an explicitly named file.
if
(
file_exists
(
$path
=
str_replace
(
'.php'
,
'/routes.php'
,
$path
)))
if
(
file_exists
(
$path
=
str_replace
(
'.php'
,
'/routes.php'
,
$path
)))
{
{
$routes
=
array_merge
(
$routes
,
require
$path
)
;
return
require
$path
;
}
}
if
(
count
(
$routes
)
>
0
)
return
$routes
;
}
}
return
$routes
;
return
array
()
;
}
}
/**
/**
...
@@ -105,9 +99,15 @@ class Loader {
...
@@ -105,9 +99,15 @@ class Loader {
$routes
=
array
();
$routes
=
array
();
// First we will check for the base routes file in the application directory.
if
(
file_exists
(
$path
=
$this
->
base
.
'routes'
.
EXT
))
{
$routes
=
array_merge
(
$routes
,
require
$path
);
}
// Since route files can be nested deep within the route directory, we need to
// Since route files can be nested deep within the route directory, we need to
// recursively spin through each directory to find every file.
// recursively spin through each directory to find every file.
$
recursiveI
terator
=
new
Iterator
(
new
DirectoryIterator
(
$this
->
nest
),
Iterator
::
SELF_FIRST
);
$
i
terator
=
new
Iterator
(
new
DirectoryIterator
(
$this
->
nest
),
Iterator
::
SELF_FIRST
);
foreach
(
$iterator
as
$file
)
foreach
(
$iterator
as
$file
)
{
{
...
...
laravel/routing/router.php
View file @
096280c9
...
@@ -48,19 +48,18 @@ class Router {
...
@@ -48,19 +48,18 @@ class Router {
*/
*/
public
function
find
(
$name
)
public
function
find
(
$name
)
{
{
// First we will check the cache of route names. If we have already found the given route,
// we will simply return that route from the cache to improve performance.
if
(
array_key_exists
(
$name
,
$this
->
names
))
return
$this
->
names
[
$name
];
if
(
array_key_exists
(
$name
,
$this
->
names
))
return
$this
->
names
[
$name
];
$arrayIterator
=
new
\RecursiveArrayIterator
(
$this
->
loader
->
everything
());
// Spin through every route defined for the application searching for a route that has
// a name matching the name passed to the method. If the route is found, it will be
$recursiveIterator
=
new
\RecursiveIteratorIterator
(
$arrayIterator
);
// cached in the array of named routes and returned.
foreach
(
$this
->
loader
->
everything
()
as
$key
=>
$value
)
foreach
(
$recursiveIterator
as
$iterator
)
{
{
$route
=
$recursiveIterator
->
getSubIterator
();
if
(
is_array
(
$value
)
and
isset
(
$value
[
'name'
])
and
$value
[
'name'
]
===
$name
)
if
(
isset
(
$route
[
'name'
])
and
$route
[
'name'
]
===
$name
)
{
{
return
$this
->
names
[
$name
]
=
array
(
$
arrayIterator
->
key
()
=>
iterator_to_array
(
$route
)
);
return
$this
->
names
[
$name
]
=
array
(
$
key
=>
$value
);
}
}
}
}
}
}
...
...
public/index.php
View file @
096280c9
...
@@ -15,11 +15,6 @@
...
@@ -15,11 +15,6 @@
*/
*/
define
(
'START_TIME'
,
microtime
(
true
));
define
(
'START_TIME'
,
microtime
(
true
));
function
elapsed
()
{
return
number_format
((
microtime
(
true
)
-
START_TIME
)
*
1000
,
2
);
}
/*
/*
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
| Laravel Installation Paths
| Laravel Installation Paths
...
@@ -48,6 +43,4 @@ $public = __DIR__;
...
@@ -48,6 +43,4 @@ $public = __DIR__;
| 3... 2... 1... Lift-off!
| 3... 2... 1... Lift-off!
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
*/
*/
require
$laravel
.
'/laravel.php'
;
require
$laravel
.
'/laravel.php'
;
\ No newline at end of file
echo
elapsed
();
\ 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