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
b65380d6
Commit
b65380d6
authored
Mar 12, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added automatic controller detection.
Signed-off-by:
Taylor Otwell
<
taylorotwell@gmail.com
>
parent
c514ca1e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletion
+53
-1
routes.php
application/routes.php
+1
-1
controller.php
laravel/routing/controller.php
+52
-0
No files found.
application/routes.php
View file @
b65380d6
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
|
|
*/
*/
Route
::
get
(
'/
, home
'
,
function
()
Route
::
get
(
'/'
,
function
()
{
{
return
View
::
make
(
'home.index'
);
return
View
::
make
(
'home.index'
);
});
});
...
...
laravel/routing/controller.php
View file @
b65380d6
...
@@ -8,6 +8,7 @@ use Laravel\Bundle;
...
@@ -8,6 +8,7 @@ use Laravel\Bundle;
use
Laravel\Request
;
use
Laravel\Request
;
use
Laravel\Redirect
;
use
Laravel\Redirect
;
use
Laravel\Response
;
use
Laravel\Response
;
use
FilesystemIterator
as
fIterator
;
abstract
class
Controller
{
abstract
class
Controller
{
...
@@ -62,6 +63,57 @@ abstract class Controller {
...
@@ -62,6 +63,57 @@ abstract class Controller {
}
}
}
}
/**
* Detect all of the controllers for a given bundle.
*
* @param string $bundle
* @param string $directory
* @return array
*/
public
static
function
detect
(
$bundle
=
DEFAULT_BUNDLE
,
$directory
=
null
)
{
if
(
is_null
(
$directory
))
{
$directory
=
Bundle
::
path
(
$bundle
)
.
'controllers'
;
}
// First we'll get the root path to the directory housing all of
// the bundle's controllers. This will be used later to figure
// out the identifiers needed for the found controllers.
$root
=
Bundle
::
path
(
$bundle
)
.
'controllers'
.
DS
;
$controllers
=
array
();
$items
=
new
fIterator
(
$directory
,
fIterator
::
SKIP_DOTS
);
foreach
(
$items
as
$item
)
{
// If the item is a directory, we will recurse back into the function
// to detect all of the nested controllers and we will keep adding
// them into the array of controllers for the bundle.
if
(
$item
->
isDir
())
{
$nested
=
static
::
detect
(
$bundle
,
$item
->
getRealPath
());
$controllers
=
array_merge
(
$controllers
,
$nested
);
}
// If the item is a file, we'll assume it is a controller and we
// will build the identifier string for the controller that we
// can pass into the route's controller method.
else
{
$controller
=
str_replace
(
array
(
$root
,
EXT
),
''
,
$item
->
getRealPath
());
$controller
=
str_replace
(
DS
,
'.'
,
$controller
);
$controllers
[]
=
Bundle
::
identifier
(
$bundle
,
$controller
);
}
}
return
$controllers
;
}
/**
/**
* Call an action method on a controller.
* Call an action method on a controller.
*
*
...
...
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