Devise\Pages\Viewvars\ViewvarComposer::compose PHP Method

compose() public method

Injects data from config into the current view
public compose ( Illuminate\View\View $view ) : void
$view Illuminate\View\View
return void
    public function compose($view)
    {
        if (!self::$loadMultipleTimes && !self::$firstView) {
            return;
        }
        $viewData = $view->getData();
        $viewName = $view->getName();
        $vars = $this->getVars($viewName);
        if (count($vars)) {
            $this->DataBuilder->setData($viewData);
            $data = $this->DataBuilder->compile($vars);
            foreach ($data as $varName => $value) {
                $view->with($varName, $value);
            }
        }
        self::$firstView = false;
    }

Usage Example

Beispiel #1
0
 public function test_it_composes()
 {
     $vars = ['var1' => 1, 'var2' => 2];
     $view = m::mock('Illuminate\\View\\View');
     $view->shouldReceive('getData')->times(1)->andReturn([]);
     $view->shouldReceive('getName')->times(1)->andReturn('cool-view');
     $view->shouldReceive('with')->times(2);
     $Config = m::mock('Illuminate\\Config\\Repository');
     $Config->shouldReceive('get')->with('devise.templates')->andReturn(['cool-view' => ['vars' => $vars]]);
     $DataBuilder = m::mock('Devise\\Pages\\Viewvars\\DataBuilder');
     $DataBuilder->shouldReceive('setData')->with([]);
     $DataBuilder->shouldReceive('compile')->with($vars)->andReturn($vars);
     $composer = new ViewvarComposer($DataBuilder, $Config);
     $composer->compose($view);
 }