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
f9f168ea
Commit
f9f168ea
authored
Aug 01, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more dependency injection to route loader and finder.
parent
0af326b6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
53 deletions
+48
-53
finder.php
system/routing/finder.php
+6
-52
loader.php
system/routing/loader.php
+41
-0
url.php
system/url.php
+1
-1
No files found.
system/routing/finder.php
View file @
f9f168ea
...
...
@@ -2,13 +2,6 @@
class
Finder
{
/**
* All of the loaded routes.
*
* @var array
*/
public
static
$routes
;
/**
* The named routes that have been found so far.
*
...
...
@@ -17,35 +10,25 @@ class Finder {
public
static
$names
=
array
();
/**
* Find a
route by name
.
* Find a
named route in a given array of routes
.
*
* @param string $name
* @param array $routes
* @return array
*/
public
static
function
find
(
$name
)
public
static
function
find
(
$name
,
$routes
)
{
// This class maintains its own list of routes because the router only loads routes that
// are applicable to the current request URI. But, this class obviously needs access
// to all of the routes, not just the ones applicable to the request URI.
if
(
is_null
(
static
::
$routes
))
{
static
::
$routes
=
require
APP_PATH
.
'routes'
.
EXT
;
if
(
is_dir
(
APP_PATH
.
'routes'
))
{
static
::
$routes
=
array_merge
(
static
::
load
(),
static
::
$routes
);
}
}
if
(
array_key_exists
(
$name
,
static
::
$names
))
{
return
static
::
$names
[
$name
];
}
$arrayIterator
=
new
\RecursiveArrayIterator
(
static
::
$routes
);
$arrayIterator
=
new
\RecursiveArrayIterator
(
$routes
);
$recursiveIterator
=
new
\RecursiveIteratorIterator
(
$arrayIterator
);
// Since routes can be nested deep within sub-directories, we need to recursively
// iterate through each directory and gather all of the routes.
foreach
(
$recursiveIterator
as
$iterator
)
{
$route
=
$recursiveIterator
->
getSubIterator
();
...
...
@@ -57,33 +40,4 @@ class Finder {
}
}
/**
* Load all of the routes from the routes directory.
*
* All of the various route files will be merged together
* into a single array that can be searched.
*
* @return array
*/
private
static
function
load
()
{
$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
(
APP_PATH
.
'routes'
);
$recursiveIterator
=
new
\RecursiveIteratorIterator
(
$directoryIterator
,
\RecursiveIteratorIterator
::
SELF_FIRST
);
foreach
(
$recursiveIterator
as
$file
)
{
if
(
filetype
(
$file
)
===
'file'
and
strpos
(
$file
,
EXT
)
!==
false
)
{
$routes
=
array_merge
(
require
$file
,
$routes
);
}
}
return
$routes
;
}
}
\ No newline at end of file
system/routing/loader.php
View file @
f9f168ea
...
...
@@ -2,6 +2,13 @@
class
Loader
{
/**
* All of the routes for the application.
*
* @var array
*/
private
static
$routes
;
/**
* Load the appropriate routes for the request URI.
*
...
...
@@ -39,4 +46,38 @@ class Loader {
return
array
();
}
/**
* Get all of the routes for the application.
*
* To improve performance, this operation will only be performed once. The routes
* will be cached and returned on every subsequent call.
*
* @return array
*/
public
static
function
everything
()
{
if
(
!
is_null
(
static
::
$routes
))
return
static
::
$routes
;
$routes
=
require
APP_PATH
.
'routes'
.
EXT
;
if
(
is_dir
(
APP_PATH
.
'routes'
))
{
// 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
(
APP_PATH
.
'routes'
);
$recursiveIterator
=
new
\RecursiveIteratorIterator
(
$directoryIterator
,
\RecursiveIteratorIterator
::
SELF_FIRST
);
foreach
(
$recursiveIterator
as
$file
)
{
if
(
filetype
(
$file
)
===
'file'
and
strpos
(
$file
,
EXT
)
!==
false
)
{
$routes
=
array_merge
(
require
$file
,
$routes
);
}
}
}
return
static
::
$routes
=
$routes
;
}
}
\ No newline at end of file
system/url.php
View file @
f9f168ea
...
...
@@ -71,7 +71,7 @@ class URL {
*/
public
static
function
to_route
(
$name
,
$parameters
=
array
(),
$https
=
false
)
{
if
(
!
is_null
(
$route
=
Routing\Finder
::
find
(
$name
)))
if
(
!
is_null
(
$route
=
Routing\Finder
::
find
(
$name
,
Routing\Loader
::
everything
()
)))
{
$uris
=
explode
(
', '
,
key
(
$route
));
...
...
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