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
eb956cc8
Commit
eb956cc8
authored
Oct 03, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some routing enhancements - still a work in progress.
parent
7be960fb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
61 deletions
+93
-61
controller.php
laravel/controller.php
+22
-7
laravel.php
laravel/laravel.php
+1
-1
caller.php
laravel/routing/caller.php
+34
-49
route.php
laravel/routing/route.php
+2
-4
router.php
laravel/routing/router.php
+34
-0
No files found.
laravel/controller.php
View file @
eb956cc8
<?php
namespace
Laravel
;
<?php
namespace
Laravel
;
use
Laravel\Routing\Destination
;
abstract
class
Controller
{
abstract
class
Controller
implements
Destination
{
/**
*
A stub method that will be called before every request to
the controller.
*
The "before" filters defined for
the controller.
*
* If a value is returned by the method, it will be halt the request cycle
* and will be considered the response to the request.
* @var array
*/
public
$before
=
array
();
/**
* The "after" filters defined for the controller.
*
* @
return mixed
* @
var array
*/
public
function
before
()
{}
public
$after
=
array
();
/**
* Get an array of filter names defined for the destination.
*
* @param string $name
* @return array
*/
public
function
filters
(
$name
)
{
return
$this
->
$name
;
}
/**
* Magic Method to handle calls to undefined functions on the controller.
...
...
laravel/laravel.php
View file @
eb956cc8
...
...
@@ -39,8 +39,8 @@ if (Config::get('session.driver') !== '')
* be returned to the browser.
*/
require
SYS_PATH
.
'request'
.
EXT
;
require
SYS_PATH
.
'routing/route'
.
EXT
;
require
SYS_PATH
.
'routing/router'
.
EXT
;
require
SYS_PATH
.
'routing/route'
.
EXT
;
require
SYS_PATH
.
'routing/loader'
.
EXT
;
require
SYS_PATH
.
'routing/caller'
.
EXT
;
...
...
laravel/routing/caller.php
View file @
eb956cc8
...
...
@@ -4,28 +4,6 @@ use Closure;
use
Laravel\Response
;
use
Laravel\Container
;
class
Delegate
{
/**
* The destination of the route delegate.
*
* @var string
*/
public
$destination
;
/**
* Create a new route delegate instance.
*
* @param string $destination
* @return void
*/
public
function
__construct
(
$destination
)
{
$this
->
destination
=
$destination
;
}
}
class
Caller
{
/**
...
...
@@ -85,30 +63,14 @@ class Caller {
// If a route returns a Delegate, it also means the route is delegating the
// handling of the request to a controller method. So, we will pass the string
// to the route delegator, exploding on "@".
if
(
$response
instanceof
Delegate
)
$response
=
$this
->
delegate
(
$route
,
$response
->
destination
);
if
(
$response
instanceof
Delegate
)
return
$this
->
delegate
(
$route
,
$response
->
destination
);
return
$this
->
finish
(
$route
,
$response
);
}
// If we get to this point, no response was returned from the filters or the route.
// The 404 response will be returned to the browser instead of a blank screen.
return
$this
->
finish
(
$route
,
$this
->
container
->
resolve
(
'laravel.response'
)
->
error
(
'404'
));
}
/**
* Run the "before" filters for the route.
*
* If a before filter returns a value, that value will be considered the response to the
* request and the route function / controller will not be used to handle the request.
*
* @param Route $route
* @return mixed
*/
protected
function
before
(
Route
$route
)
{
$before
=
array_merge
(
array
(
'before'
),
$route
->
filters
(
'before'
));
return
$this
->
filter
(
$before
,
array
(),
true
);
return
$this
->
finish
(
$route
,
Response
::
error
(
'404'
));
}
/**
...
...
@@ -139,12 +101,17 @@ class Caller {
$controller
->
container
=
$this
->
container
;
// Again, as was the case with route closures, if the controller "before"
method returns
// Again, as was the case with route closures, if the controller "before"
filters return
// a response, it will be considered the response to the request and the controller method
// will not be used to handle the request to the application.
$response
=
$controller
->
before
();
$response
=
$this
->
before
(
$controller
);
if
(
is_null
(
$response
))
{
$response
=
call_user_func_array
(
array
(
$controller
,
$method
),
$route
->
parameters
);
}
return
(
is_null
(
$response
))
?
call_user_func_array
(
array
(
$controller
,
$method
),
$route
->
parameters
)
:
$response
;
return
$this
->
finish
(
$controller
,
$response
)
;
}
/**
...
...
@@ -197,29 +164,47 @@ class Caller {
*
* The route response will be converted to a Response instance and the "after" filters will be run.
*
* @param
Route
$route
* @param
Destination
$route
* @param mixed $response
* @return Response
*/
protected
function
finish
(
Route
$route
,
$response
)
protected
function
finish
(
Destination
$destination
,
$response
)
{
if
(
!
$response
instanceof
Response
)
$response
=
new
Response
(
$response
);
$this
->
filter
(
array_merge
(
$
route
->
filters
(
'after'
),
array
(
'after'
)),
array
(
$response
));
$this
->
filter
(
array_merge
(
$
destination
->
filters
(
'after'
),
array
(
'after'
)),
array
(
$response
));
return
$response
;
}
/**
* Run the "before" filters for the routing destination.
*
* If a before filter returns a value, that value will be considered the response to the
* request and the route function / controller will not be used to handle the request.
*
* @param Route $route
* @return mixed
*/
protected
function
before
(
Destination
$destination
)
{
$before
=
array_merge
(
array
(
'before'
),
$destination
->
filters
(
'before'
));
return
$this
->
filter
(
$before
,
array
(),
true
);
}
/**
* Call a filter or set of filters.
*
* @param array $filters
* @param array
|string
$filters
* @param array $parameters
* @param bool $override
* @return mixed
*/
protected
function
filter
(
$filters
,
$parameters
=
array
(),
$override
=
false
)
{
if
(
is_string
(
$filters
))
$filters
=
explode
(
'|'
,
$filters
);
foreach
((
array
)
$filters
as
$filter
)
{
// Parameters may be passed into routes by specifying the list of parameters after
...
...
laravel/routing/route.php
View file @
eb956cc8
...
...
@@ -3,7 +3,7 @@
use
Closure
;
use
Laravel\Arr
;
class
Route
{
class
Route
implements
Destination
{
/**
* The route key, including request method and URI.
...
...
@@ -126,9 +126,7 @@ class Route {
{
if
(
is_array
(
$this
->
callback
)
and
isset
(
$this
->
callback
[
$name
]))
{
$filters
=
$this
->
callback
[
$name
];
return
(
is_string
(
$filters
))
?
explode
(
'|'
,
$filters
)
:
$filters
;
return
$this
->
callback
[
$name
];
}
return
array
();
...
...
laravel/routing/router.php
View file @
eb956cc8
...
...
@@ -2,6 +2,40 @@
use
Laravel\Request
;
interface
Destination
{
/**
* Get an array of filter names defined for the destination.
*
* @param string $name
* @return array
*/
public
function
filters
(
$name
);
}
class
Delegate
{
/**
* The destination of the route delegate.
*
* @var string
*/
public
$destination
;
/**
* Create a new route delegate instance.
*
* @param string $destination
* @return void
*/
public
function
__construct
(
$destination
)
{
$this
->
destination
=
$destination
;
}
}
class
Router
{
/**
...
...
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