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
5e40e296
Commit
5e40e296
authored
Sep 01, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring routing and adding comments.
parent
30514d90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
19 deletions
+43
-19
route.php
laravel/routing/route.php
+31
-19
view.php
laravel/view.php
+12
-0
No files found.
laravel/routing/route.php
View file @
5e40e296
...
...
@@ -14,6 +14,13 @@ class Route {
*/
public
$key
;
/**
* The URIs the route responds to.
*
* @var array
*/
public
$uris
;
/**
* The route callback or array.
*
...
...
@@ -56,6 +63,15 @@ class Route {
$this
->
callback
=
$callback
;
$this
->
parameters
=
$parameters
;
$this
->
controller_path
=
$controller_path
;
// Extract each URI handled by the URI. These will be used to find the route by
// URI when requested. The leading slash will be removed for convenience.
foreach
(
explode
(
', '
,
$key
)
as
$segment
)
{
$segment
=
substr
(
$segment
,
strpos
(
$segment
,
' '
)
+
1
);
$this
->
uris
[]
=
(
$segment
!==
'/'
)
?
trim
(
$segment
,
'/'
)
:
$segment
;
}
}
/**
...
...
@@ -66,8 +82,14 @@ class Route {
*/
public
function
call
(
Application
$application
)
{
$this
->
validate
();
if
(
!
$this
->
callback
instanceof
Closure
and
!
is_array
(
$this
->
callback
))
{
throw
new
\Exception
(
'Invalid route defined for URI ['
.
$this
->
key
.
']'
);
}
// 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.
if
(
!
is_null
(
$response
=
$this
->
filter
(
array_merge
(
$this
->
before
(),
array
(
'before'
)),
array
(
$application
),
true
)))
{
return
$this
->
finish
(
$application
,
$response
);
...
...
@@ -80,19 +102,6 @@ class Route {
return
$this
->
finish
(
$application
,
$application
->
responder
->
error
(
'404'
));
}
/**
* Validate that a given route is callable.
*
* @return void
*/
protected
function
validate
()
{
if
(
!
$this
->
callback
instanceof
Closure
and
!
is_array
(
$this
->
callback
))
{
throw
new
\Exception
(
'Invalid route defined for URI ['
.
$this
->
key
.
']'
);
}
}
/**
* Extract the route closure from the route.
*
...
...
@@ -121,6 +130,9 @@ class Route {
$response
=
call_user_func_array
(
$closure
,
$this
->
parameters
);
// If the route closure returns an array, we assume that they are returning a
// reference to a controller and method and will use the given controller method
// to handle the request to the application.
if
(
is_array
(
$response
))
{
$response
=
$this
->
delegate
(
$application
,
$response
[
0
],
$response
[
1
],
$this
->
parameters
);
...
...
@@ -142,7 +154,7 @@ class Route {
{
if
(
!
file_exists
(
$path
=
$this
->
controller_path
.
strtolower
(
str_replace
(
'.'
,
'/'
,
$controller
))
.
EXT
))
{
throw
new
\Exception
(
"Controller [
$controller
]
is not defined
."
);
throw
new
\Exception
(
"Controller [
$controller
]
does not exist
."
);
}
require
$path
;
...
...
@@ -158,6 +170,9 @@ class Route {
$response
=
$controller
->
before
();
}
// Again, as was the case with route closures, if the controller "before" method returns
// 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.
return
(
is_null
(
$response
))
?
call_user_func_array
(
array
(
$controller
,
$method
),
$parameters
)
:
$response
;
}
...
...
@@ -170,10 +185,7 @@ class Route {
*/
protected
function
resolve
(
Container
$container
,
$controller
)
{
if
(
$container
->
registered
(
'controllers.'
.
$controller
))
{
return
$container
->
resolve
(
'controllers.'
.
$controller
);
}
if
(
$container
->
registered
(
'controllers.'
.
$controller
))
return
$container
->
resolve
(
'controllers.'
.
$controller
);
$controller
=
str_replace
(
' '
,
'_'
,
ucwords
(
str_replace
(
'.'
,
' '
,
$controller
)))
.
'_Controller'
;
...
...
laravel/view.php
View file @
5e40e296
...
...
@@ -93,6 +93,18 @@ class View_Factory {
$this
->
composer
=
$composer
;
}
/**
* Create a new view instance.
*
* @param string $view
* @param array $data
* @return View
*/
public
function
make
(
$view
,
$data
=
array
())
{
return
new
View
(
$view
,
$data
,
$this
->
path
(
$view
),
$this
->
composer
,
$this
);
}
/**
* Create a new view instance from a view 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