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
0af326b6
Commit
0af326b6
authored
Aug 01, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on routing architecture.
parent
344f49e1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
22 deletions
+59
-22
index.php
public/index.php
+6
-1
filter.php
system/routing/filter.php
+25
-6
loader.php
system/routing/loader.php
+18
-11
route.php
system/routing/route.php
+4
-0
router.php
system/routing/router.php
+5
-3
url.php
system/url.php
+1
-1
No files found.
public/index.php
View file @
0af326b6
...
@@ -135,6 +135,11 @@ if (System\Config::get('session.driver') != '')
...
@@ -135,6 +135,11 @@ if (System\Config::get('session.driver') != '')
System\Session
::
load
(
System\Cookie
::
get
(
'laravel_session'
));
System\Session
::
load
(
System\Cookie
::
get
(
'laravel_session'
));
}
}
// --------------------------------------------------------------
// Register the route filters.
// --------------------------------------------------------------
System\Routing\Filter
::
register
(
require
APP_PATH
.
'filters'
.
EXT
);
// --------------------------------------------------------------
// --------------------------------------------------------------
// Execute the global "before" filter.
// Execute the global "before" filter.
// --------------------------------------------------------------
// --------------------------------------------------------------
...
@@ -145,7 +150,7 @@ $response = System\Routing\Filter::call('before', array(), true);
...
@@ -145,7 +150,7 @@ $response = System\Routing\Filter::call('before', array(), true);
// ----------------------------------------------------------
// ----------------------------------------------------------
if
(
is_null
(
$response
))
if
(
is_null
(
$response
))
{
{
$route
=
System\Routing\Router
::
make
(
Request
::
method
(),
Request
::
uri
())
->
route
();
$route
=
System\Routing\Router
::
make
(
Request
::
method
(),
Request
::
uri
()
,
new
System\Routing\Loader
)
->
route
();
$response
=
(
is_null
(
$route
))
?
System\Response
::
make
(
System\View
::
make
(
'error/404'
),
404
)
:
$route
->
call
();
$response
=
(
is_null
(
$route
))
?
System\Response
::
make
(
System\View
::
make
(
'error/404'
),
404
)
:
$route
->
call
();
}
}
...
...
system/routing/filter.php
View file @
0af326b6
...
@@ -7,7 +7,28 @@ class Filter {
...
@@ -7,7 +7,28 @@ class Filter {
*
*
* @var array
* @var array
*/
*/
public
static
$filters
;
private
static
$filters
=
array
();
/**
* Register a set of route filters.
*
* @param array $filters
* @return void
*/
public
static
function
register
(
$filters
)
{
static
::
$filters
=
array_merge
(
static
::
$filters
,
$filters
);
}
/**
* Clear all of the registered route filters.
*
* @return void
*/
public
static
function
clear
()
{
static
::
$filters
=
array
();
}
/**
/**
* Call a set of route filters.
* Call a set of route filters.
...
@@ -19,11 +40,6 @@ class Filter {
...
@@ -19,11 +40,6 @@ class Filter {
*/
*/
public
static
function
call
(
$filters
,
$parameters
=
array
(),
$override
=
false
)
public
static
function
call
(
$filters
,
$parameters
=
array
(),
$override
=
false
)
{
{
if
(
is_null
(
static
::
$filters
))
{
static
::
$filters
=
require
APP_PATH
.
'filters'
.
EXT
;
}
foreach
(
explode
(
', '
,
$filters
)
as
$filter
)
foreach
(
explode
(
', '
,
$filters
)
as
$filter
)
{
{
if
(
!
isset
(
static
::
$filters
[
$filter
]))
if
(
!
isset
(
static
::
$filters
[
$filter
]))
...
@@ -33,6 +49,9 @@ class Filter {
...
@@ -33,6 +49,9 @@ class Filter {
$response
=
call_user_func_array
(
static
::
$filters
[
$filter
],
$parameters
);
$response
=
call_user_func_array
(
static
::
$filters
[
$filter
],
$parameters
);
// "Before" filters may override the request cycle. For example, an authentication
// filter may redirect a user to a login view if they are not logged in. Because of
// this, we will return the first filter response if overriding is enabled.
if
(
!
is_null
(
$response
)
and
$override
)
if
(
!
is_null
(
$response
)
and
$override
)
{
{
return
$response
;
return
$response
;
...
...
system/routing/loader.php
View file @
0af326b6
...
@@ -8,28 +8,35 @@ class Loader {
...
@@ -8,28 +8,35 @@ class Loader {
* @param string
* @param string
* @return array
* @return array
*/
*/
public
static
function
load
(
$uri
)
public
function
load
(
$uri
)
{
{
$base
=
require
APP_PATH
.
'routes'
.
EXT
;
$base
=
require
APP_PATH
.
'routes'
.
EXT
;
if
(
!
is_dir
(
APP_PATH
.
'routes'
)
or
$uri
==
''
)
return
(
is_dir
(
APP_PATH
.
'routes'
)
and
$uri
!=
''
)
?
array_merge
(
$this
->
load_nested_routes
(
$uri
),
$base
)
:
$base
;
{
}
return
$base
;
}
list
(
$routes
,
$segments
)
=
array
(
array
(),
explode
(
'/'
,
$uri
));
/**
* Load the appropriate routes from the routes directory.
*
* This is done by working down the URI until we find the deepest
* possible matching route file.
*
* @param string $uri
* @return array
*/
private
function
load_nested_routes
(
$uri
)
{
$segments
=
explode
(
'/'
,
$uri
);
foreach
(
array_reverse
(
$segments
,
true
)
as
$key
=>
$value
)
foreach
(
array_reverse
(
$segments
,
true
)
as
$key
=>
$value
)
{
{
if
(
file_exists
(
$path
=
ROUTE_PATH
.
implode
(
'/'
,
array_slice
(
$segments
,
0
,
$key
+
1
))
.
EXT
))
if
(
file_exists
(
$path
=
ROUTE_PATH
.
implode
(
'/'
,
array_slice
(
$segments
,
0
,
$key
+
1
))
.
EXT
))
{
{
$routes
=
require
$path
;
return
require
$path
;
break
;
}
}
}
}
return
array
_merge
(
$routes
,
$base
);
return
array
(
);
}
}
}
}
\ No newline at end of file
system/routing/route.php
View file @
0af326b6
...
@@ -51,6 +51,10 @@ class Route {
...
@@ -51,6 +51,10 @@ class Route {
{
{
$response
=
null
;
$response
=
null
;
// The callback may be in array form, meaning it has attached filters or is named.
// However, the callback may also simply be a closure. If it is just a closure,
// we can execute it here. Otherwise, we will need to evaluate the route for any
// filters that need to be called.
if
(
is_callable
(
$this
->
callback
))
if
(
is_callable
(
$this
->
callback
))
{
{
$response
=
call_user_func_array
(
$this
->
callback
,
$this
->
parameters
);
$response
=
call_user_func_array
(
$this
->
callback
,
$this
->
parameters
);
...
...
system/routing/router.php
View file @
0af326b6
...
@@ -23,16 +23,16 @@ class Router {
...
@@ -23,16 +23,16 @@ class Router {
*
*
* @param string $method
* @param string $method
* @param string $uri
* @param string $uri
* @param
array $routes
* @param
Loader $loader
* @return void
* @return void
*/
*/
public
function
__construct
(
$method
,
$uri
,
$
routes
=
null
)
public
function
__construct
(
$method
,
$uri
,
$
loader
)
{
{
// Put the request method and URI in route form. Routes begin with
// Put the request method and URI in route form. Routes begin with
// the request method and a forward slash.
// the request method and a forward slash.
$this
->
request
=
$method
.
' /'
.
trim
(
$uri
,
'/'
);
$this
->
request
=
$method
.
' /'
.
trim
(
$uri
,
'/'
);
$this
->
routes
=
(
is_null
(
$routes
))
?
Loader
::
load
(
$uri
)
:
$routes
;
$this
->
routes
=
$loader
->
load
(
$uri
)
;
}
}
/**
/**
...
@@ -55,6 +55,8 @@ class Router {
...
@@ -55,6 +55,8 @@ class Router {
*/
*/
public
function
route
()
public
function
route
()
{
{
// Check for a literal route match first. If we find one, there is
// no need to spin through all of the routes.
if
(
isset
(
$this
->
routes
[
$this
->
request
]))
if
(
isset
(
$this
->
routes
[
$this
->
request
]))
{
{
return
Request
::
$route
=
new
Route
(
$this
->
request
,
$this
->
routes
[
$this
->
request
]);
return
Request
::
$route
=
new
Route
(
$this
->
request
,
$this
->
routes
[
$this
->
request
]);
...
...
system/url.php
View file @
0af326b6
...
@@ -71,7 +71,7 @@ class URL {
...
@@ -71,7 +71,7 @@ class URL {
*/
*/
public
static
function
to_route
(
$name
,
$parameters
=
array
(),
$https
=
false
)
public
static
function
to_route
(
$name
,
$parameters
=
array
(),
$https
=
false
)
{
{
if
(
!
is_null
(
$route
=
Rout
e_
Finder
::
find
(
$name
)))
if
(
!
is_null
(
$route
=
Rout
ing\
Finder
::
find
(
$name
)))
{
{
$uris
=
explode
(
', '
,
key
(
$route
));
$uris
=
explode
(
', '
,
key
(
$route
));
...
...
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