Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
c2e1ef68
Commit
c2e1ef68
authored
Jul 07, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Router class, deprecate Route\Loader and Route\Parser.
parent
c1e2f3cf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
2 deletions
+62
-2
system/router.php
+62
-2
No files found.
system/router.php
View file @
c2e1ef68
...
...
@@ -23,7 +23,7 @@ class Router {
if
(
is_null
(
static
::
$routes
))
{
static
::
$routes
=
Route\Loader
::
load
(
$uri
);
static
::
$routes
=
static
::
load
(
$uri
);
}
// Is there an exact match for the request?
...
...
@@ -44,11 +44,70 @@ class Router {
if
(
preg_match
(
'#^'
.
$key
.
'$#'
,
$method
.
' '
.
$uri
))
{
return
Request
::
$route
=
new
Route
(
$keys
,
$callback
,
Route\Parser
::
parameters
(
$uri
,
$key
));
return
Request
::
$route
=
new
Route
(
$keys
,
$callback
,
static
::
parameters
(
explode
(
'/'
,
$uri
),
explode
(
'/'
,
$key
)
));
}
}
}
}
}
/**
* Load the appropriate route file for the request URI.
*
* @param string $uri
* @return array
*/
private
static
function
load
(
$uri
)
{
if
(
!
is_dir
(
APP_PATH
.
'routes'
))
{
return
require
APP_PATH
.
'routes'
.
EXT
;
}
if
(
!
file_exists
(
APP_PATH
.
'routes/home'
.
EXT
))
{
throw
new
\Exception
(
"A [home] route file is required when using a route directory."
);
}
if
(
$uri
==
'/'
)
{
return
require
APP_PATH
.
'routes/home'
.
EXT
;
}
else
{
$segments
=
explode
(
'/'
,
trim
(
$uri
,
'/'
));
if
(
!
file_exists
(
APP_PATH
.
'routes/'
.
$segments
[
0
]
.
EXT
))
{
return
require
APP_PATH
.
'routes/home'
.
EXT
;
}
return
array_merge
(
require
APP_PATH
.
'routes/'
.
$segments
[
0
]
.
EXT
,
require
APP_PATH
.
'routes/home'
.
EXT
);
}
}
/**
* Extract the parameters from a URI based on a route URI.
*
* Any route segment wrapped in parentheses is considered a parameter.
*
* @param array $uri
* @param array $route
* @return array
*/
private
static
function
parameters
(
$uri
,
$route
)
{
$parameters
=
array
();
for
(
$i
=
0
;
$i
<
count
(
$route
);
$i
++
)
{
if
(
strpos
(
$route
[
$i
],
'('
)
===
0
)
{
$parameters
[]
=
$uri
[
$i
];
}
}
return
$parameters
;
}
}
\ 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