Example #1
0
 /**
  *
  */
 public function testInput1()
 {
     $form = $this->buildForm1();
     $model = new ViewData($form);
     $head = $model->node("org.division.head");
     $text = $model->node("comment");
     $form->setData(INPUT_GET, ['org' => ['division' => ['head' => 'green']], 'comment' => "New Comment"]);
     //
     $form->input(INPUT_GET);
     $this->assertEquals(["green"], $head->core()->getValue());
     $this->assertEquals("New Comment", $text->core()->getValue());
 }
Example #2
0
 /**
  * @param ViewModel $model
  * @param Response $response
  * @return string
  */
 public function render(ViewModel $model, Response $response = null)
 {
     $body = '';
     $helpers = $this->getHelpers();
     $suffix = $this->getScriptSuffix();
     // (0) Create the ROOT node
     $data = ViewData::cast($model->getData(), ['escape' => $helpers->get('escape')]);
     $this->injectHelpers($data);
     // (1) Render the view script
     $view_name = $model->getTemplate();
     if ($view_name) {
         $view_script = $view_name . $suffix;
         $view_path = $this->templatePath($view_script);
         if (file_exists($view_path)) {
             $body = $this->renderScript($view_path, $data);
         } else {
             throw new Exception\RuntimeException("Script file ({$view_path}) not found");
         }
     }
     // (2) Render the layout
     $layout_name = $this->modelLayout($model);
     if ($layout_name) {
         $layout_script = $layout_name . $suffix;
         $layout_path = $this->templatePath($layout_script);
         if (file_exists($layout_path)) {
             $data['content'] = $body;
             $body = $this->renderScript($layout_path, $data);
         } else {
             throw new Exception\RuntimeException("Layout file ({$layout_path}) not found");
         }
     }
     // (3) Push
     if ($response) {
         $response->setBody($body);
     }
     return $body;
 }
Example #3
0
 /**
  * @param mixed $data
  * @return ViewData
  */
 public function dataNode($data, $overwrite = false)
 {
     $node = ViewData::cast($data);
     $node->setEscape($this->getHelpers()->get('escape'));
     // Inject the helpers
     foreach ($this->getHelperArray() as $key => $wrapper) {
         if ($overwrite || !isset($node[$key])) {
             $node[$key] = $wrapper;
         }
     }
     return $node;
 }