Example #1
0
    public function testRenderRecursive()
    {
        $img = new HtmlLeaf(['kind' => 'img', 'attr' => ['id' => 'img1', 'class' => 'wide', 'href' => 'public/img/image1.jpg']]);
        $div = new HtmlNode(['child' => [$img], 'attr' => ['id' => 'div1']]);
        $expected = '
$' . $img->getID() . ' = new \\Simphotonics\\Dom\\HtmlLeaf([
  \'kind\' => \'img\',
  \'attr\'=> [
    \'id\' => \'img1\',
    \'class\' => \'wide\',
    \'href\' => \'public/img/image1.jpg\'
  ],
]); 

$' . $div->getID() . ' = new \\Simphotonics\\Dom\\HtmlNode([
  \'kind\' => \'div\',
  \'attr\'=> [
    \'id\' => \'div1\'
  ],
  \'child\'=> [
    $' . $img->getID() . '
  ]
]); 
';
        $this->assertEquals($expected, Renderer::renderRecursive($div));
    }
Example #2
0
 /**
  * Write PHP source code that generates top nodes
  * to file.
  * @method  exportNodes
  * @param   string       $filename  Path to file on file system.
  * @return  int|false               Number of bits writen or false on failure.
  */
 public function exportNodes($filename = 'parsedNodes.php')
 {
     // Render top nodes
     $source = '';
     foreach ($this->topNodes as $node) {
         if ($node instanceof NodeAccess) {
             $source .= NodeRenderer::renderRecursive($node);
         } else {
             $source .= NodeRenderer::render($node);
         }
     }
     return FileUtils::write2file($source, $filename, FileUtils::FILE_NEW);
 }
Example #3
0
 /**
  * Write PHP source code that generates an array containig empty
  * elements.
  * @method  exportEmptyElements
  * @param   string               $filename  Valid path to file.
  * @return  int|false                       No. of bits written or false.
  */
 public function exportEmptyElements($filename = 'emptyElements.php')
 {
     $elements = $this->getEmptyElements();
     $source = NodeRenderer::renderArray($elements, 'elements');
     return FileUtils::write2file($source, $filename, FileUtils::FILE_NEW);
 }