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
5325acac
Commit
5325acac
authored
Feb 28, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding support for attaching filters based on URI routing.
Signed-off-by:
Taylor Otwell
<
taylorotwell@gmail.com
>
parent
01ddff5c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
10 deletions
+43
-10
laravel.php
laravel/laravel.php
+1
-2
filter.php
laravel/routing/filter.php
+7
-5
route.php
laravel/routing/route.php
+33
-3
router.php
laravel/routing/router.php
+2
-0
No files found.
laravel/laravel.php
View file @
5325acac
...
@@ -98,8 +98,7 @@ switch (Request::method())
...
@@ -98,8 +98,7 @@ switch (Request::method())
$input
=
$_POST
;
$input
=
$_POST
;
break
;
break
;
case
'PUT'
:
default
:
case
'DELETE'
:
if
(
Request
::
spoofed
())
if
(
Request
::
spoofed
())
{
{
$input
=
$_POST
;
$input
=
$_POST
;
...
...
laravel/routing/filter.php
View file @
5325acac
...
@@ -38,14 +38,17 @@ class Filter {
...
@@ -38,14 +38,17 @@ class Filter {
* Filter::register('before', array('Class', 'method'));
* Filter::register('before', array('Class', 'method'));
* </code>
* </code>
*
*
* @param string
$name
* @param string $name
* @param
Closure
$callback
* @param
mixed
$callback
* @return void
* @return void
*/
*/
public
static
function
register
(
$name
,
Closure
$callback
)
public
static
function
register
(
$name
,
$callback
)
{
{
if
(
isset
(
static
::
$aliases
[
$name
]))
$name
=
static
::
$aliases
[
$name
];
if
(
isset
(
static
::
$aliases
[
$name
]))
$name
=
static
::
$aliases
[
$name
];
// If the filter starts with "pattern: ", the filter is being setup to match on
// all requests that match a given pattern. This is nice for defining filters
// that handle all URIs beginning with "admin" for example.
if
(
starts_with
(
$name
,
'pattern: '
))
if
(
starts_with
(
$name
,
'pattern: '
))
{
{
foreach
(
explode
(
', '
,
substr
(
$name
,
9
))
as
$pattern
)
foreach
(
explode
(
', '
,
substr
(
$name
,
9
))
as
$pattern
)
...
@@ -102,8 +105,7 @@ class Filter {
...
@@ -102,8 +105,7 @@ class Filter {
// We will also go ahead and start the bundle for the developer. This allows
// We will also go ahead and start the bundle for the developer. This allows
// the developer to specify bundle filters on routes without starting the
// the developer to specify bundle filters on routes without starting the
// bundle manually, and performance is improved since the bundle is only
// bundle manually, and performance is improved by lazy-loading.
// started when needed.
Bundle
::
start
(
Bundle
::
name
(
$filter
));
Bundle
::
start
(
Bundle
::
name
(
$filter
));
if
(
!
isset
(
static
::
$filters
[
$filter
]))
continue
;
if
(
!
isset
(
static
::
$filters
[
$filter
]))
continue
;
...
...
laravel/routing/route.php
View file @
5325acac
<?php
namespace
Laravel\Routing
;
<?php
namespace
Laravel\Routing
;
use
Closure
;
use
Closure
;
use
Laravel\URI
;
use
Laravel\Bundle
;
use
Laravel\Bundle
;
use
Laravel\Request
;
use
Laravel\Request
;
use
Laravel\Response
;
use
Laravel\Response
;
...
@@ -172,9 +173,38 @@ class Route {
...
@@ -172,9 +173,38 @@ class Route {
$filters
=
array_merge
(
$filters
,
$assigned
);
$filters
=
array_merge
(
$filters
,
$assigned
);
}
}
// Next we will attach any pattern type filters to the array of
// filters as these are matched to the route by the route's
// URI and not explicitly attached to routes.
if
(
$event
==
'before'
)
{
$filters
=
array_merge
(
$filters
,
$this
->
patterns
());
}
return
array
(
new
Filter_Collection
(
$filters
));
return
array
(
new
Filter_Collection
(
$filters
));
}
}
/**
* Get the pattern filters for the route.
*
* @return array
*/
protected
function
patterns
()
{
// We will simply iterate through the registered patterns and
// check the URI pattern against the URI for the route and
// if they match we'll attach the filter.
foreach
(
Filter
::
$patterns
as
$pattern
=>
$filter
)
{
if
(
URI
::
is
(
$pattern
,
$this
->
uri
))
{
$filters
[]
=
$filter
;
}
}
return
(
array
)
$filters
;
}
/**
/**
* Get the controller action delegate assigned to the route.
* Get the controller action delegate assigned to the route.
*
*
...
@@ -340,11 +370,11 @@ class Route {
...
@@ -340,11 +370,11 @@ class Route {
/**
/**
* Register a route filter.
* Register a route filter.
*
*
* @param string
$name
* @param string $name
* @param
Closure
$callback
* @param
mixed
$callback
* @return void
* @return void
*/
*/
public
static
function
filter
(
$name
,
Closure
$callback
)
public
static
function
filter
(
$name
,
$callback
)
{
{
Filter
::
register
(
$name
,
$callback
);
Filter
::
register
(
$name
,
$callback
);
}
}
...
...
laravel/routing/router.php
View file @
5325acac
...
@@ -31,6 +31,7 @@ class Router {
...
@@ -31,6 +31,7 @@ class Router {
'POST'
=>
array
(),
'POST'
=>
array
(),
'PUT'
=>
array
(),
'PUT'
=>
array
(),
'DELETE'
=>
array
(),
'DELETE'
=>
array
(),
'PATCH'
=>
array
(),
'HEAD'
=>
array
(),
'HEAD'
=>
array
(),
);
);
...
@@ -44,6 +45,7 @@ class Router {
...
@@ -44,6 +45,7 @@ class Router {
'POST'
=>
array
(),
'POST'
=>
array
(),
'PUT'
=>
array
(),
'PUT'
=>
array
(),
'DELETE'
=>
array
(),
'DELETE'
=>
array
(),
'PATCH'
=>
array
(),
'HEAD'
=>
array
(),
'HEAD'
=>
array
(),
);
);
...
...
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