<?php namespace Library; require dirname(__FILE__) . '/../../library/FabricationEngine.php'; require dirname(__FILE__) . '/../../library/Fabricator.php'; require dirname(__FILE__) . '/../../library/PhpClass.php'; require dirname(__FILE__) . '/../../library/UML.php'; require dirname(__FILE__) . '/../../library/Html.php'; try { if (PHP_SAPI !== 'cli') { throw new Exception('This is command line script'); } else { $engine = new \Fabrication\FabricationEngine(); $UML = new \Fabrication\UML($engine); // get diagram name from script argument or default. $diagramName = isset($argv[1]) ? $argv[1] : 'Application'; $diagramPath = dirname(__FILE__) . '/' . $diagramName . '.dia'; // load the diagram $engine->run($diagramPath, 'file', 'xml'); // show layer objects in a php class representation. foreach ($UML->retriveLayerObjects() as $name => $object) { $objectType = $object->attributes->getNamedItem('type')->nodeValue; // UML - Class if ($object->nodeName == 'dia:object' && $objectType == "UML - Class") { $phpClass = new \Fabrication\PhpClass(); $phpClass->setName($name); $phpClass->setStereotype($UML->getStereoType($object)); $umlAttributes = $UML->getAttributes($object); if (is_object($umlAttributes) && $umlAttributes->length > 0) { foreach ($umlAttributes as $umlAttribute) {
<?php require_once dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new Fabrication\FabricationEngine(); $pattern = <<<EOD <div>PatternTemplate: <div class="uid">UID.</div> <div class="title">Title.</div> <div class="content">Content.</div> </div> EOD; $dataset = array(array('uid' => 1, 'title' => 'Title 1', 'content' => 'Content 1'), array('uid' => 2, 'title' => 'Title 2', 'content' => 'Content 2'), array('uid' => 3, 'title' => 'Title 3', 'content' => 'Content 3')); echo $engine->saveXML($engine->template($pattern, $dataset, 'class')); // view generated parts echo $engine->view("//div[@class='uid_1']/text()"); echo $engine->view("//div[@class='title_1']/text()"); echo $engine->view("//div[@class='content_1']/text()"); echo $engine->view("//div[@class='uid_2']/text()"); echo $engine->view("//div[@class='title_2']/text()"); echo $engine->view("//div[@class='content_2']/text()"); echo $engine->view("//div[@class='uid_3']/text()"); echo $engine->view("//div[@class='title_3']/text()"); echo $engine->view("//div[@class='content_3']/text()");
<?php require_once dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new Fabrication\FabricationEngine(); $engine->input('hello', 'world'); var_dump($engine->output('hello', 'php.array', array('tags' => false)));
<?php require dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new \Fabrication\FabricationEngine(); echo $engine->getDoctype() . "\n"; $engine->setOption('doctype', 'html.5'); echo $engine->getDoctype() . "\n"; $template = '<html><head><title></title></head><body>' . '<h2>Hello 1</h2><article>Hello World 1</article>' . '<h2>Hello 2</h2><article>Hello World 2</article>' . '</body></html>'; $engine->run($template); $result = $engine->getArticle(); var_dump($result->item(0)->nodeValue); var_dump($result->item(1)->nodeValue); $engine->view('//article[position()=1]'); $engine->view('//article[position()=2]');
<?php require dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new \Fabrication\FabricationEngine(); $engine->input('#greeting', $engine->create('div', 'World')); $template = '<html><head></head><body><div id="greeting">Hello</div></body></html>'; $engine->run($template); var_dump($engine->saveHTML());
<?php require dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new \Fabrication\FabricationEngine(); $engine->input('hello', 'world'); var_dump($engine->output('hello'));
<?php /** * Example: Create a div element with an id attribute and value. * */ require_once dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new Fabrication\FabricationEngine(); # Create DOM Element of the type div with an id attribute with the value of hello-world. $hi = $engine->create('div', 'Hello', ['id' => 'hello']); # Render the element. $helloText = $hi->ownerDocument->saveXML($hi); # Append to the engine and view the html structure $engine->appendChild($hi); $engine->input('#hello', 'world'); echo $engine->saveHTML();
<?php require dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new \Fabrication\FabricationEngine(); $engine->run('http://slashdot.org', 'file'); echo $engine->saveHTML();
<?php /** * Example: Create a div element with an id attribute and value. * with children recursively. * */ require_once dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new Fabrication\FabricationEngine(); $hi = $engine->create('div', '', array('id' => 'hello-world'), array(array('name' => 'u', 'value' => 'Hello', 'attributes' => array('id' => 'hello'), 'children' => array()), array('name' => 'strong', 'attributes' => array('id' => 'world'), 'children' => array(array('name' => 'i', 'value' => 'W'), array('name' => 'i', 'value' => 'o'), array('name' => 'i', 'value' => 'r'), array('name' => 'i', 'value' => 'l'), array('name' => 'i', 'value' => 'd'))))); $engine->appendChild($hi); echo $engine->saveHTML();
<?php require dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new \Fabrication\FabricationEngine(); $engine->registerNamespace('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $engine->registerNamespace('xmlns:slash', 'http://purl.org/rss/1.0/modules/slash/'); $engine->run('https://packagist.org/feeds/vendor.components.rss', 'file'); $channelTitle = $engine->query('//rss/channel/title'); $channelDescription = $engine->query('//rss/channel/description'); $channelGenerator = $engine->query('//rss/channel/generator'); $channelItems = $engine->query('//rss/channel/item'); $output = "{\n"; foreach ($channelItems as $item) { foreach ($item->childNodes as $key => $value) { if ($value->nodeName == "guid") { $parts = explode(" ", $value->nodeValue); $output .= "\t\"require\": {\n"; $output .= "\t\t\t\"{$parts[0]}\": \"{$parts[1]}\"\n"; $output .= "\t},\n"; } } } $output .= "}\n\n"; echo $output;
<?php require dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new \Fabrication\FabricationEngine(); $engine->input('#hello', 'world'); $template = '<html><head></head><body><div id="hello"></div></body></html>'; $engine->run($template); var_dump($engine->output('#hello')); var_dump($engine->saveHTML('//div[@id="hello"]/text()')); var_dump($engine->saveHTML());
<?php require dirname(__FILE__) . '/../../library/FabricationEngine.php'; $engine = new \Fabrication\FabricationEngine(); $engine->run('http://slashdot.org', 'file'); $htmlTitle = $engine->query('/html/head/title'); echo $htmlTitle->item(0)->nodeName . ' = ' . $htmlTitle->item(0)->nodeValue . "\n";
<?php require dirname(__FILE__) . '/../../library/FabricationEngine.php'; $workload = array(100, 1000, 10000, 100000); foreach ($workload as $key => $load) { $engine = new \Fabrication\FabricationEngine(); foreach (array_rand(range(0, $load), $load) as $number) { $engine->input($number, 'value'); $engine->output($number); } echo $engine->timeTaken() . " seconds workload = {$load}\n"; unset($engine); }