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
c688eef3
Commit
c688eef3
authored
Aug 05, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added back support for named views.
parent
6346c54a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
4 deletions
+100
-4
view.php
system/view.php
+100
-4
No files found.
system/view.php
View file @
c688eef3
...
...
@@ -77,6 +77,53 @@ class View {
return
new
static
(
$view
,
$data
);
}
/**
* Create a new view instance from a view name.
*
* @param string $name
* @param array $data
* @return View
*/
private
static
function
of
(
$name
,
$data
=
array
())
{
// Search the active module first, then the application module, then all other modules.
$modules
=
array_unique
(
array_merge
(
array
(
ACTIVE_MODULE
,
'application'
),
Config
::
get
(
'application.modules'
)));
foreach
(
$modules
as
$module
)
{
static
::
load_composers
(
$module
);
if
(
!
is_null
(
$view
=
static
::
find_view_for_name
(
$name
,
static
::
$composers
[
$module
])))
{
return
new
static
(
$view
,
$data
);
}
}
throw
new
\Exception
(
"Named view [
$name
] is not defined."
);
}
/**
* Find the view for a given name in an array of composers.
*
* @param string $name
* @param array $composers
* @return string
*/
private
static
function
find_view_for_name
(
$name
,
$composers
)
{
foreach
(
$composers
as
$key
=>
$value
)
{
if
(
is_string
(
$value
)
and
$value
==
$name
)
{
return
$key
;
}
elseif
(
is_array
(
$value
)
and
isset
(
$value
[
'name'
])
and
$value
[
'name'
]
==
$name
)
{
return
$key
;
}
}
}
/**
* Parse a view identifier and get the module, path, and view name.
*
...
...
@@ -108,14 +155,63 @@ class View {
*/
private
function
compose
()
{
if
(
!
isset
(
static
::
$composers
[
$this
->
module
]))
static
::
load_composers
(
$this
->
module
);
if
(
isset
(
static
::
$composers
[
$this
->
module
][
$this
->
view
]))
{
static
::
$composers
[
$this
->
module
]
=
(
file_exists
(
$path
=
$this
->
path
.
'composers'
.
EXT
))
?
require
$path
:
array
();
$composer
=
static
::
$composers
[
$this
->
module
][
$this
->
view
];
if
(
!
is_null
(
$composer
=
$this
->
find_composer_handler
(
$composer
)))
{
return
call_user_func
(
$composer
,
$this
);
}
}
}
if
(
isset
(
static
::
$composers
[
$this
->
module
][
$this
->
view
]))
/**
* Find the composer handler / function in a composer definition.
*
* If the composer value itself is callable, it will be returned, otherwise the
* first callable value in the composer array will be returned.
*
* @param mixed $composer
* @return Closure
*/
private
function
find_composer_handler
(
$composer
)
{
if
(
is_string
(
$composer
))
return
;
if
(
is_callable
(
$composer
))
return
$composer
;
foreach
(
$composer
as
$value
)
{
if
(
is_callable
(
$value
))
return
$value
;
}
}
/**
* Load the view composers for a given module.
*
* @param string $module
* @return void
*/
private
static
function
load_composers
(
$module
)
{
if
(
isset
(
static
::
$composers
[
$module
]))
return
;
$composers
=
(
$module
==
'application'
)
?
APP_PATH
.
'composers'
.
EXT
:
MODULE_PATH
.
$module
.
'/composers'
.
EXT
;
static
::
$composers
[
$module
]
=
(
file_exists
(
$composers
))
?
require
$composers
:
array
();
}
/**
* Magic Method for handling the dynamic creation of named views.
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
{
if
(
strpos
(
$method
,
'of_'
)
===
0
)
{
call_user_func
(
static
::
$composers
[
$this
->
module
][
$this
->
view
],
$thi
s
);
return
static
::
of
(
substr
(
$method
,
3
),
$parameter
s
);
}
}
...
...
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