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
82776946
Commit
82776946
authored
Jul 10, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring router.
parent
141bed39
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
router.php
system/router.php
+21
-21
No files found.
system/router.php
View file @
82776946
...
...
@@ -23,7 +23,8 @@ class Router {
static
::
$routes
=
static
::
load
(
$uri
);
}
// Put the request method and URI in route form. Routes begin with the request method and a forward slash.
// Put the request method and URI in route form.
// Routes begin with the request method and a forward slash.
$uri
=
$method
.
' /'
.
trim
(
$uri
,
'/'
);
// Is there an exact match for the request?
...
...
@@ -34,7 +35,8 @@ class Router {
foreach
(
static
::
$routes
as
$keys
=>
$callback
)
{
// Only check routes that have multiple URIs or wildcards. Other routes would be caught by a literal match.
// Only check routes that have multiple URIs or wildcards.
// Other routes would have been caught by the check for literal matches.
if
(
strpos
(
$keys
,
'('
)
!==
false
or
strpos
(
$keys
,
','
)
!==
false
)
{
foreach
(
explode
(
', '
,
$keys
)
as
$key
)
...
...
@@ -58,31 +60,29 @@ class Router {
*/
public
static
function
load
(
$uri
)
{
if
(
!
is_dir
(
APP_PATH
.
'routes'
))
{
return
require
APP_PATH
.
'routes'
.
EXT
;
return
(
is_dir
(
APP_PATH
.
'routes'
))
?
static
::
load_from_directory
(
$uri
)
:
require
APP_PATH
.
'routes'
.
EXT
;
}
if
(
!
file_exists
(
APP_PATH
.
'routes/home'
.
EXT
))
/**
* Load the appropriate route file from the routes directory.
*
* @param string $uri
* @return array
*/
private
static
function
load_from_directory
(
$uri
)
{
throw
new
\Exception
(
"A [home] route file is required when using a route directory."
);
}
// If it exists, The "home" routes file is loaded for every request. This allows
// for "catch-all" routes such as http://example.com/username...
$home
=
(
file_exists
(
$path
=
APP_PATH
.
'routes/home'
.
EXT
))
?
require
$path
:
array
();
if
(
$uri
==
'
/
'
)
if
(
$uri
==
''
)
{
return
require
APP_PATH
.
'routes/home'
.
EXT
;
return
$home
;
}
else
{
$segments
=
explode
(
'/'
,
$uri
);
if
(
!
file_exists
(
APP_PATH
.
'routes/'
.
$segments
[
0
]
.
EXT
))
{
return
require
APP_PATH
.
'routes/home'
.
EXT
;
}
$segments
=
explode
(
'/'
,
$uri
);
return
array_merge
(
require
APP_PATH
.
'routes/'
.
$segments
[
0
]
.
EXT
,
require
APP_PATH
.
'routes/home'
.
EXT
);
}
return
(
file_exists
(
$path
=
APP_PATH
.
'routes/'
.
$segments
[
0
]
.
EXT
))
?
array_merge
(
require
$path
,
$home
)
:
$home
;
}
/**
...
...
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