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
395236d6
Commit
395236d6
authored
Feb 06, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support universal routes.
parent
df3a277b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
1 deletion
+39
-1
router.php
laravel/routing/router.php
+39
-1
No files found.
laravel/routing/router.php
View file @
395236d6
...
@@ -36,6 +36,13 @@ class Router {
...
@@ -36,6 +36,13 @@ class Router {
'/(:any?)'
=>
'(?:/([a-zA-Z0-9\.\-_%]+)'
,
'/(:any?)'
=>
'(?:/([a-zA-Z0-9\.\-_%]+)'
,
);
);
/**
* An array of HTTP request methods.
*
* @var array
*/
public
static
$methods
=
array
(
'GET'
,
'POST'
,
'PUT'
,
'DELETE'
);
/**
/**
* Register a route with the router.
* Register a route with the router.
*
*
...
@@ -48,13 +55,20 @@ class Router {
...
@@ -48,13 +55,20 @@ class Router {
* </code>
* </code>
*
*
* @param string|array $route
* @param string|array $route
* @param
string
$action
* @param
mixed
$action
* @return void
* @return void
*/
*/
public
static
function
register
(
$route
,
$action
)
public
static
function
register
(
$route
,
$action
)
{
{
foreach
((
array
)
$route
as
$uri
)
foreach
((
array
)
$route
as
$uri
)
{
{
if
(
starts_with
(
$uri
,
'*'
))
{
static
::
universal
(
substr
(
$uri
,
2
),
$action
);
continue
;
}
// If the action is a string, it is a pointer to a controller, so we
// If the action is a string, it is a pointer to a controller, so we
// need to add it to the action array as a "uses" clause, which will
// need to add it to the action array as a "uses" clause, which will
// indicate to the route to call the controller when the route is
// indicate to the route to call the controller when the route is
...
@@ -78,6 +92,30 @@ class Router {
...
@@ -78,6 +92,30 @@ class Router {
}
}
}
}
/**
* Register a route for all HTTP verbs.
*
* @param string $route
* @param mixed $action
* @return void
*/
protected
static
function
universal
(
$route
,
$action
)
{
$count
=
count
(
static
::
$methods
);
$routes
=
array_fill
(
0
,
$count
,
$route
);
// When registering a universal route, we'll iterate through all of the
// verbs supported by the router and prepend each one of the URIs with
// one of the request verbs, then we'll register the routes.
for
(
$i
=
0
;
$i
<
$count
;
$i
++
)
{
$routes
[
$i
]
=
static
::
$methods
[
$i
]
.
' '
.
$routes
[
$i
];
}
static
::
register
(
$routes
,
$action
);
}
/**
/**
* Find a route by the route's assigned name.
* Find a route by the route's assigned name.
*
*
...
...
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