Example #1
0
<?php

function __autoload($class_name)
{
    include 'classes/' . $class_name . '.php';
}
$bodyName;
if (isset($_GET["body"])) {
    $bodyName = $_GET["body"];
} else {
    $bodyName = "body-partial";
}
$htmlBuilder = new HTMLBuilder("html/header-partial.html", "html/" . $bodyName . ".html", "html/footer-partial.html");
$htmlBuilder->buildHeader();
$htmlBuilder->buildBody();
$htmlBuilder->buildFooter();
?>
  
<?php

function __autoload($c)
{
    require_once "classes/" . $c . ".php";
}
// should probably be loaded from a DB somewhere
$routes = ["home" => ["body" => "body.partial.html", "title" => "Homepage!"], "contact" => ["body" => "contact.partial.html", "title" => "Contact pagina!", "header" => "header.partial.html"], "404" => ["body" => "404.partial.html", "title" => "Oops! Page not found"]];
$router = new Router($routes);
// Router
if (isset($_GET['r'])) {
    // route is requested
    $route = $_GET['r'];
    // find the requested route // if it doesnt exist, this will be 404
    $router->findRoute($route);
} else {
    // get the homepage
    $router->findRoute("home");
}
// create a new page with default values (html path, default header, default footer) for the current route
$page = new HTMLBuilder("html/", "header.partial.html", "footer.partial.html", $router);
$page->buildPage();
<?php

$headerb = "html/header-partial.php";
$bodyb = "html/body-partial.php";
$footerb = "html/footer-partial.php";
$class_name = "HTMLBuilder";
function __autoload($class_name)
{
    include "classes/" . $class_name . '.php';
}
$builder = new HTMLBuilder($headerb, $bodyb, $footerb);
$builder->includeHeader();
$builder->includeBody();
$builder->includeFooter();
?>


 /**
  * @test
  */
 public function encapsulateTag()
 {
     $builder = new HTMLBuilder('p');
     $actual = $builder->encapsulate('div')->build();
     $expected = '<div><p></p></div>';
     $this->assertEquals($expected, $actual);
 }
<?php

require_once '../includes/htmlbuilder.php';
$b = new HTMLBuilder();
$b->p(function ($b) {
});
var_dump((string) $b);
Example #6
0
function link_to($text, $url, $html_options = array())
{
    $builder = new HTMLBuilder('a');
    $builder->addAttribute('href', $url);
    $builder->addAttributes($html_options);
    $builder->setValue($text);
    echo $builder->build();
}
Example #7
0
<?php

//echo "ok";
//klasses inladen
function __autoload($classname)
{
    require_once "classes/" . $classname . ".php";
}
//html genereren op basis van deel-html.
$html = new HTMLBuilder(file_get_contents("html/header.partial.html"), file_get_contents('html/body.partial.html'), file_get_contents('html/footer.partial.html'));
var_dump($html->findfiles(".txt"));
//var_dump($testhtml);
//require_once("html/body.partial.html");
//$files = $html->listfiles();
//var_dump($files);
?>

<?php 
echo $html->buildHTML();
?>


 public function __construct(HTMLBuilder $builder)
 {
     $this->document = $builder->document();
     $this->element = $builder->element();
 }