예제 #1
0
 public function testConstructor()
 {
     $resourceViewModel = new ResourceViewModel(['foo' => 'bar'], ['version' => 'v2', 'template' => 'users/user']);
     $this->assertEquals(['foo' => 'bar'], $resourceViewModel->getVariables());
     $this->assertEquals('users/user', $resourceViewModel->getTemplate());
     $this->assertEquals('v2', $resourceViewModel->getVersion());
 }
예제 #2
0
 /**
  * @param  string      $template
  * @param  array       $variables
  * @param  string|null $version
  * @return array
  */
 public function __invoke($template, array $variables, $version = null)
 {
     // If a version name has explicitly been set, we reuse this one, otherwise we use the one
     // defined in the "current view model"
     if (null === $version) {
         $version = $this->view->viewModel()->getCurrent()->getVersion();
     }
     $templatePath = $version . '/' . $template . '.php';
     // We create a new resource view model
     $resourceViewModel = new ResourceViewModel($variables, ['version' => $version]);
     $resourceViewModel->setTemplate($templatePath);
     return $this->view->render($resourceViewModel);
 }