for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Goetas\Twital\Node;
use Goetas\Twital\Compiler;
use Goetas\Twital\Exception;
use Goetas\Twital\Node;
/**
*
* @author Asmir Mustafic <[email protected]>
*/
class ImportNode implements Node
{
public function visit(\DOMElement $node, Compiler $context)
if ($node->hasAttribute("from-exp")) {
$filename = $node->getAttribute("from-exp");
} elseif ($node->hasAttribute("from")) {
$filename = '"' . $node->getAttribute("from") . '"';
} else {
throw new Exception("The 'from' or 'from-exp' attribute is required");
}
if ($node->hasAttribute("as")) {
$code = "import $filename as " . $node->getAttribute("as");
$context->createControlNode("import " . ($node->getAttribute("fro-exp") ? $node->getAttribute("name-exp") : ("'" . $node->getAttribute("name") . "'")) . " as " . $node->getAttribute("as"));
} elseif ($node->hasAttribute("aliases")) {
$code = "from $filename import " . $node->getAttribute("aliases");
throw new Exception("As or Alias attribute is required");
$pi = $context->createControlNode($code);
$node->parentNode->replaceChild($pi, $node);