added application access to composers.
This commit is contained in:
parent
5e40e296bd
commit
893bb83895
|
@ -39,7 +39,7 @@
|
|||
|
|
||||
*/
|
||||
|
||||
'home.index' => array('name' => 'home', function($view)
|
||||
'home.index' => array('name' => 'home', function($laravel, $view)
|
||||
{
|
||||
//
|
||||
}),
|
||||
|
|
|
@ -158,11 +158,17 @@
|
|||
}),
|
||||
|
||||
|
||||
'laravel.view' => array('singleton' => true, 'resolver' => function()
|
||||
'laravel.view' => array('singleton' => true, 'resolver' => function($container)
|
||||
{
|
||||
require_once SYS_PATH.'view'.EXT;
|
||||
|
||||
return new View_Factory(VIEW_PATH, new View_Composer(require APP_PATH.'composers'.EXT));
|
||||
return new View_Factory($container->resolve('laravel.view.composer'), VIEW_PATH);
|
||||
}),
|
||||
|
||||
|
||||
'laravel.view.composer' => array('resolver' => function($container)
|
||||
{
|
||||
return new View_Composer($container->resolve('laravel.application'), require APP_PATH.'composers'.EXT);
|
||||
}),
|
||||
|
||||
/*
|
||||
|
|
|
@ -8,6 +8,13 @@
|
|||
*/
|
||||
class View_Composer {
|
||||
|
||||
/**
|
||||
* The application instance.
|
||||
*
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
/**
|
||||
* The view composers.
|
||||
*
|
||||
|
@ -21,8 +28,9 @@ class View_Composer {
|
|||
* @param array $composers
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($composers)
|
||||
public function __construct(Application $application, $composers)
|
||||
{
|
||||
$this->application = $application;
|
||||
$this->composers = $composers;
|
||||
}
|
||||
|
||||
|
@ -52,7 +60,7 @@ public function compose(View $view)
|
|||
{
|
||||
foreach ((array) $this->composers[$view->view] as $key => $value)
|
||||
{
|
||||
if ($value instanceof \Closure) return call_user_func($value, $view);
|
||||
if ($value instanceof \Closure) return call_user_func($value, $this->application, $view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,13 +74,6 @@ public function compose(View $view)
|
|||
*/
|
||||
class View_Factory {
|
||||
|
||||
/**
|
||||
* The directory containing the views.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* The view composer instance.
|
||||
*
|
||||
|
@ -80,17 +81,24 @@ class View_Factory {
|
|||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* The directory containing the views.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Create a new view factory instance.
|
||||
*
|
||||
* @param array $composers
|
||||
* @param string $path
|
||||
* @param View_Composer $composer
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($path, View_Composer $composer)
|
||||
public function __construct(View_Composer $composer, $path)
|
||||
{
|
||||
$this->path = $path;
|
||||
$this->composer = $composer;
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue