diff --git a/src/Goetas/Twital/Attribute.php b/src/Goetas/Twital/Attribute.php index e576e84..0e1db6c 100644 --- a/src/Goetas/Twital/Attribute.php +++ b/src/Goetas/Twital/Attribute.php @@ -1,8 +1,6 @@ ownerElement; diff --git a/src/Goetas/Twital/Attribute/AttrAttribute.php b/src/Goetas/Twital/Attribute/AttrAttribute.php index 0a72e18..2da0410 100644 --- a/src/Goetas/Twital/Attribute/AttrAttribute.php +++ b/src/Goetas/Twital/Attribute/AttrAttribute.php @@ -3,9 +3,8 @@ use Goetas\Twital\Attribute; use Goetas\Twital\Compiler; -use DOMAttr; use Goetas\Twital\Helper\ParserHelper; -use Exception; +use Goetas\Twital\Exception; /** * @@ -14,13 +13,12 @@ */ class AttrAttribute implements Attribute { - public static function getVarname(\DOMNode $node) { return "__a9" . strtr(spl_object_hash($node), "-","_"); } - public function visit(DOMAttr $att, Compiler $context) + public function visit(\DOMAttr $att, Compiler $context) { $node = $att->ownerElement; $expressions = ParserHelper::staticSplitExpression($att->value, ","); diff --git a/src/Goetas/Twital/Attribute/BaseAttribute.php b/src/Goetas/Twital/Attribute/BaseAttribute.php index 900dacd..28e8e6e 100644 --- a/src/Goetas/Twital/Attribute/BaseAttribute.php +++ b/src/Goetas/Twital/Attribute/BaseAttribute.php @@ -3,7 +3,6 @@ use Goetas\Twital\Attribute as AttributeBase; use Goetas\Twital\Compiler; -use DOMAttr; /** * @@ -12,7 +11,7 @@ */ class BaseAttribute implements AttributeBase { - public function visit(DOMAttr $att, Compiler $context) + public function visit(\DOMAttr $att, Compiler $context) { $node = $att->ownerElement; diff --git a/src/Goetas/Twital/Attribute/BlockInnerAttribute.php b/src/Goetas/Twital/Attribute/BlockInnerAttribute.php index ed4c343..223eb81 100644 --- a/src/Goetas/Twital/Attribute/BlockInnerAttribute.php +++ b/src/Goetas/Twital/Attribute/BlockInnerAttribute.php @@ -3,7 +3,6 @@ use Goetas\Twital\Attribute as AttributeBase; use Goetas\Twital\Compiler; -use DOMAttr; /** * This will translate '
- * array(
- * 'http://www.w3.org/1998/Math/MathML' => array(
- * 'math'=> new MathML\MathAttribute()
- * )
- * )
+ * array(
+ * 'http://www.w3.org/1998/Math/MathML' => array(
+ * 'math'=> new MathML\MathAttribute()
+ * )
+ * )
*
*
* @return array
@@ -31,11 +31,11 @@ public function getAttributes();
* first level as namespace and second level as attribute name.
* Example:
*
- * array(
- * 'http://www.w3.org/1998/Math/MathML' => array(
- * 'math'=> new MathML\MathNode()
- * )
- * )
+ * array(
+ * 'http://www.w3.org/1998/Math/MathML' => array(
+ * 'math'=> new MathML\MathNode()
+ * )
+ * )
*
*
* @return array
@@ -48,4 +48,4 @@ public function getNodes();
*/
public function getSubscribers();
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/Extension/AbstractExtension.php b/src/Goetas/Twital/Extension/AbstractExtension.php
index adcb385..e1a35f6 100644
--- a/src/Goetas/Twital/Extension/AbstractExtension.php
+++ b/src/Goetas/Twital/Extension/AbstractExtension.php
@@ -10,7 +10,6 @@
*/
abstract class AbstractExtension implements Extension
{
-
public function getAttributes()
{
return array();
diff --git a/src/Goetas/Twital/Extension/CoreExtension.php b/src/Goetas/Twital/Extension/CoreExtension.php
index 14b43d5..190bf64 100644
--- a/src/Goetas/Twital/Extension/CoreExtension.php
+++ b/src/Goetas/Twital/Extension/CoreExtension.php
@@ -67,7 +67,7 @@ public function getNodes()
$nodes[Twital::NS]['omit'] = new Node\OmitNode();
$nodes[Twital::NS]['embed'] = new Node\EmbedNode();
$nodes[Twital::NS]['use'] = new Node\UseNode();
+
return $nodes;
}
}
-
diff --git a/src/Goetas/Twital/Helper/DOMHelper.php b/src/Goetas/Twital/Helper/DOMHelper.php
index b37bb48..39cd8ed 100644
--- a/src/Goetas/Twital/Helper/DOMHelper.php
+++ b/src/Goetas/Twital/Helper/DOMHelper.php
@@ -1,6 +1,11 @@
+ *
+ */
class DOMHelper
{
public static function removeChilds(\DOMNode $ref)
@@ -9,6 +14,7 @@ public static function removeChilds(\DOMNode $ref)
$ref->removeChild($ref->firstChild);
}
}
+
public static function insertAfterSet(\DOMNode $node, array $newNodes)
{
$ref = $node;
@@ -26,10 +32,12 @@ public static function replaceWithSet(\DOMNode $node, array $newNodes)
self::insertAfterSet($node, $newNodes);
$node->parentNode->removeChild($node);
}
+
public static function remove(\DOMNode $ref)
{
return $ref->parentNode->removeChild($ref);
}
+
public static function checkNamespaces(\DOMElement $element, array $namespaces = array())
{
if ($element->namespaceURI === null && preg_match('/^([a-z0-9\-]+):(.+)$/i', $element->nodeName, $mch) && isset($namespaces[$mch[1]])) {
@@ -71,6 +79,7 @@ public static function copyElementInNs($oldElement, $newNamespace)
$element->appendChild($child);
}
$oldElement->parentNode->replaceChild($element, $oldElement);
+
return $element;
}
}
diff --git a/src/Goetas/Twital/Helper/ParserHelper.php b/src/Goetas/Twital/Helper/ParserHelper.php
index 5b834f7..a3884bb 100644
--- a/src/Goetas/Twital/Helper/ParserHelper.php
+++ b/src/Goetas/Twital/Helper/ParserHelper.php
@@ -1,11 +1,15 @@
+ *
+ */
class ParserHelper
{
-
private static $closing = array(
'}' => '{',
')' => '(',
@@ -49,8 +53,8 @@ public static function staticSplitExpression($str, $splitter, $limit = 0)
if (! count($in) && $chr === $splitter) {
$parts[] = substr($str, $prev, $i - $prev);
$prev = $i + 1;
- if($limit>1 && count($parts)==($limit-1)){
- break;
+ if ($limit>1 && count($parts)==($limit-1)) {
+ break;
}
}
}
diff --git a/src/Goetas/Twital/Node/BlockNode.php b/src/Goetas/Twital/Node/BlockNode.php
index 91c5d95..b009e94 100644
--- a/src/Goetas/Twital/Node/BlockNode.php
+++ b/src/Goetas/Twital/Node/BlockNode.php
@@ -4,7 +4,7 @@
use Goetas\Twital\Node;
use Goetas\Twital\Compiler;
use Goetas\Twital\Helper\DOMHelper;
-use Exception;
+use Goetas\Twital\Exception;
use Goetas\Twital\Twital;
/**
@@ -19,9 +19,6 @@ public function visit(\DOMElement $node, Compiler $context)
if (! $node->hasAttribute("name")) {
throw new Exception("Name attribute is required");
}
- $xp = new \DOMXPath($node->ownerDocument);
-
- $currPrima = $node->previousSibling;
$sandbox = $node->ownerDocument->createElementNS(Twital::NS, "sandbox");
$node->parentNode->insertBefore($sandbox,$node);
@@ -40,4 +37,4 @@ public function visit(\DOMElement $node, Compiler $context)
DOMHelper::replaceWithSet($sandbox, iterator_to_array($sandbox->childNodes));
DOMHelper::replaceWithSet($node, iterator_to_array($node->childNodes));
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/Node/EmbedNode.php b/src/Goetas/Twital/Node/EmbedNode.php
index c388937..22b00e8 100644
--- a/src/Goetas/Twital/Node/EmbedNode.php
+++ b/src/Goetas/Twital/Node/EmbedNode.php
@@ -2,10 +2,9 @@
namespace Goetas\Twital\Node;
use Goetas\Twital\Node;
-use Exception;
+use Goetas\Twital\Exception;
use Goetas\Twital\Compiler;
use Goetas\Twital\Helper\DOMHelper;
-use Goetas\Twital\Twital;
/**
*
@@ -14,7 +13,6 @@
*/
class EmbedNode implements Node
{
-
public function visit(\DOMElement $node, Compiler $context)
{
if ($node->hasAttribute("from-exp")) {
@@ -58,4 +56,4 @@ public function visit(\DOMElement $node, Compiler $context)
DOMHelper::replaceWithSet($node, $set);
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/Node/ExtendsNode.php b/src/Goetas/Twital/Node/ExtendsNode.php
index a57df70..6603aed 100644
--- a/src/Goetas/Twital/Node/ExtendsNode.php
+++ b/src/Goetas/Twital/Node/ExtendsNode.php
@@ -2,10 +2,9 @@
namespace Goetas\Twital\Node;
use Goetas\Twital\Node;
-use Exception;
+use Goetas\Twital\Exception;
use Goetas\Twital\Compiler;
use Goetas\Twital\Helper\DOMHelper;
-use Goetas\Twital\Twital;
/**
*
@@ -14,7 +13,6 @@
*/
class ExtendsNode implements Node
{
-
public function visit(\DOMElement $node, Compiler $context)
{
if ($node->hasAttribute("from-exp")) {
@@ -26,8 +24,8 @@ public function visit(\DOMElement $node, Compiler $context)
}
// remove any non-element node
- foreach (iterator_to_array($node->childNodes) as $child){
- if(!($child instanceof \DOMElement)){
+ foreach (iterator_to_array($node->childNodes) as $child) {
+ if (!($child instanceof \DOMElement)) {
$child->parentNode->removeChild($child);
}
}
@@ -37,7 +35,7 @@ public function visit(\DOMElement $node, Compiler $context)
$ext = $context->createControlNode("extends {$filename}");
$set = iterator_to_array($node->childNodes);
- if(count($set)){
+ if (count($set)) {
$n = $node->ownerDocument->createTextNode("\n");
array_unshift($set, $n);
}
@@ -46,4 +44,4 @@ public function visit(\DOMElement $node, Compiler $context)
DOMHelper::replaceWithSet($node, $set);
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/Node/ImportNode.php b/src/Goetas/Twital/Node/ImportNode.php
index 49f712e..4678875 100644
--- a/src/Goetas/Twital/Node/ImportNode.php
+++ b/src/Goetas/Twital/Node/ImportNode.php
@@ -12,7 +12,6 @@
*/
class ImportNode implements Node
{
-
public function visit(\DOMElement $node, Compiler $context)
{
if ($node->hasAttribute("from-exp")) {
@@ -36,4 +35,4 @@ public function visit(\DOMElement $node, Compiler $context)
$node->parentNode->replaceChild($pi, $node);
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/Node/IncludeNode.php b/src/Goetas/Twital/Node/IncludeNode.php
index 84d45e0..7c4386a 100644
--- a/src/Goetas/Twital/Node/IncludeNode.php
+++ b/src/Goetas/Twital/Node/IncludeNode.php
@@ -12,7 +12,6 @@
*/
class IncludeNode implements Node
{
-
public function visit(\DOMElement $node, Compiler $context)
{
$code = "include ";
@@ -25,7 +24,6 @@ public function visit(\DOMElement $node, Compiler $context)
throw new Exception("The 'from' or 'from-exp' attribute is required");
}
-
if ($node->hasAttribute("ignore-missing") && $node->getAttribute("ignore-missing") !== "false") {
$code .= " ignore missing";
}
@@ -42,4 +40,4 @@ public function visit(\DOMElement $node, Compiler $context)
$pi = $context->createControlNode($code);
$node->parentNode->replaceChild($pi, $node);
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/Node/MacroNode.php b/src/Goetas/Twital/Node/MacroNode.php
index 9f967e3..096ef2a 100644
--- a/src/Goetas/Twital/Node/MacroNode.php
+++ b/src/Goetas/Twital/Node/MacroNode.php
@@ -4,7 +4,7 @@
use Goetas\Twital\Node;
use Goetas\Twital\Compiler;
use Goetas\Twital\Helper\DOMHelper;
-use Exception;
+use Goetas\Twital\Exception;
/**
*
@@ -13,7 +13,6 @@
*/
class MacroNode implements Node
{
-
public function visit(\DOMElement $node, Compiler $context)
{
if (! $node->hasAttribute("name")) {
@@ -27,7 +26,6 @@ public function visit(\DOMElement $node, Compiler $context)
$start = $context->createControlNode("macro " . $node->getAttribute("name") . "(" . $node->getAttribute("args") . ")");
array_unshift($set, $start);
-
$set[] = $context->createControlNode("endmacro");
DOMHelper::replaceWithSet($node, $set);
diff --git a/src/Goetas/Twital/Node/OmitNode.php b/src/Goetas/Twital/Node/OmitNode.php
index ca6e057..0227bb3 100644
--- a/src/Goetas/Twital/Node/OmitNode.php
+++ b/src/Goetas/Twital/Node/OmitNode.php
@@ -18,4 +18,4 @@ public function visit(\DOMElement $node, Compiler $context)
$context->compileChilds($node);
DOMHelper::replaceWithSet($node, iterator_to_array($node->childNodes));
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/Node/UseNode.php b/src/Goetas/Twital/Node/UseNode.php
index d93e8cd..539efb6 100644
--- a/src/Goetas/Twital/Node/UseNode.php
+++ b/src/Goetas/Twital/Node/UseNode.php
@@ -3,7 +3,7 @@
use Goetas\Twital\Node;
use Goetas\Twital\Compiler;
-use Exception;
+use Goetas\Twital\Exception;
/**
*
@@ -14,7 +14,6 @@ class UseNode implements Node
{
public function visit(\DOMElement $node, Compiler $context)
{
-
$code = "use ";
if ($node->hasAttribute("from")) {
@@ -30,4 +29,4 @@ public function visit(\DOMElement $node, Compiler $context)
$pi = $context->createControlNode($code);
$node->parentNode->replaceChild($pi, $node);
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/SourceAdapter.php b/src/Goetas/Twital/SourceAdapter.php
index 51f8ef2..9c2764b 100644
--- a/src/Goetas/Twital/SourceAdapter.php
+++ b/src/Goetas/Twital/SourceAdapter.php
@@ -10,12 +10,15 @@ interface SourceAdapter
{
/**
* Gets the raw template source code and return a {Goetas\Twital\Template} instance.
+ *
* @param string $string
* @return \Goetas\Twital\Template
*/
public function load($string);
+
/**
* Gets a {Goetas\Twital\Template} instance and return the raw template source code.
+ *
* @param \Goetas\Twital\Template $dom
* @return string
*/
diff --git a/src/Goetas/Twital/SourceAdapter/HTML5Adapter.php b/src/Goetas/Twital/SourceAdapter/HTML5Adapter.php
index 7b1de93..271a97b 100644
--- a/src/Goetas/Twital/SourceAdapter/HTML5Adapter.php
+++ b/src/Goetas/Twital/SourceAdapter/HTML5Adapter.php
@@ -65,10 +65,10 @@ public function dump(Template $template)
{
$metadata = $template->getMetadata();
-
if (! $metadata['doctype']) {
return HTML5::saveHTML($template->getDocument()->childNodes);
}
+
return HTML5::saveHTML($template->getDocument()->childNodes);
}
@@ -87,4 +87,4 @@ protected function collectMetadata(\DOMDocument $dom, $source)
return $metadata;
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/SourceAdapter/XHTMLAdapter.php b/src/Goetas/Twital/SourceAdapter/XHTMLAdapter.php
index 7d3bab8..b48b4de 100644
--- a/src/Goetas/Twital/SourceAdapter/XHTMLAdapter.php
+++ b/src/Goetas/Twital/SourceAdapter/XHTMLAdapter.php
@@ -26,6 +26,7 @@ public function dump(Template $template)
$source .= $dom->saveXML($node);
}
}
+
return $this->replaceShortTags($source);
}
diff --git a/src/Goetas/Twital/SourceAdapter/XMLAdapter.php b/src/Goetas/Twital/SourceAdapter/XMLAdapter.php
index ffc594a..d3ff5cf 100644
--- a/src/Goetas/Twital/SourceAdapter/XMLAdapter.php
+++ b/src/Goetas/Twital/SourceAdapter/XMLAdapter.php
@@ -52,6 +52,7 @@ public function dump(Template $template)
foreach ($dom->childNodes as $node) {
$source .= $dom->saveXML($node);
}
+
return $source;
}
}
diff --git a/src/Goetas/Twital/Template.php b/src/Goetas/Twital/Template.php
index 2f39611..d2bf2b3 100644
--- a/src/Goetas/Twital/Template.php
+++ b/src/Goetas/Twital/Template.php
@@ -10,7 +10,6 @@
*/
class Template
{
-
/**
* The template {DOMDocument}
*
@@ -54,4 +53,4 @@ public function getMetadata()
{
return $this->metadata;
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/Twital.php b/src/Goetas/Twital/Twital.php
index 0faf80e..1c0b7fa 100644
--- a/src/Goetas/Twital/Twital.php
+++ b/src/Goetas/Twital/Twital.php
@@ -13,7 +13,6 @@
*/
class Twital
{
-
const NS = 'urn:goetas:twital';
protected $extensionsInitialized = false;
@@ -62,12 +61,14 @@ public function getEventDispatcher()
public function getNodes()
{
$this->initExtensions();
+
return $this->nodes;
}
public function getAttributes()
{
$this->initExtensions();
+
return $this->attributes;
}
@@ -78,7 +79,7 @@ protected function initExtensions()
$this->attributes = array_merge_recursive($this->attributes, $extension->getAttributes());
$this->nodes = array_merge_recursive($this->nodes, $extension->getNodes());
- foreach ($extension->getSubscribers() as $subscriber){
+ foreach ($extension->getSubscribers() as $subscriber) {
$this->dispatcher->addSubscriber($subscriber);
}
}
@@ -111,6 +112,7 @@ public function compile(SourceAdapter $adapter, $source)
$sourceEvent = new SourceEvent($this, $source);
$this->dispatcher->dispatch('compiler.post_dump', $sourceEvent);
+
return $sourceEvent->getTemplate();
}
@@ -128,4 +130,4 @@ public function getExtensions()
{
return $this->extensions;
}
-}
\ No newline at end of file
+}
diff --git a/src/Goetas/Twital/TwitalLoader.php b/src/Goetas/Twital/TwitalLoader.php
index ef22587..020c052 100644
--- a/src/Goetas/Twital/TwitalLoader.php
+++ b/src/Goetas/Twital/TwitalLoader.php
@@ -13,7 +13,6 @@
*/
class TwitalLoader implements \Twig_LoaderInterface
{
-
/**
* Array of patterns used to decide if a template is twital-compilable or not.
* Items are strings or callbacks
@@ -35,10 +34,11 @@ class TwitalLoader implements \Twig_LoaderInterface
* @var Twital
*/
protected $twital;
+
/**
* Creates a new Twital loader.
* @param \Twig_LoaderInterface $loader
- * @param Compiler $twital
+ * @param Twital $twital
* @param bool $addDefaults If NULL, some standard rules will be used (`*.twital.*` and `*.twital`).
*/
public function __construct(\Twig_LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true)
@@ -57,18 +57,19 @@ public function __construct(\Twig_LoaderInterface $loader = null, Twital $twital
}
}
-
/**
* Add a new pattern that can decide if a template is twital-compilable or not.
* If $pattern is a string, then must be a valid regex that matches the template filename.
* If $pattern is a callback, then must return true if the template is compilable, false otherwise.
*
* @param string|callback $pattern
+ * @param SourceAdapter $adapter
* @return \Goetas\Twital\TwitalLoader
*/
public function addSourceAdapter($pattern, SourceAdapter $adapter)
{
$this->sourceAdapters[$pattern] = $adapter;
+
return $this;
}
@@ -85,6 +86,7 @@ public function getSourceAdapters()
/**
* Decide if a template is twital-compilable or not.
*
+ * @param string $name
* @return SourceAdapter
*/
public function getSourceAdapter($name)
@@ -94,6 +96,7 @@ public function getSourceAdapter($name)
return $adapter;
}
}
+
return null;
}
@@ -152,17 +155,20 @@ public function getLoader()
public function setLoader(\Twig_LoaderInterface $loader)
{
$this->loader = $loader;
+
return $this;
}
+
/**
* @return \Goetas\Twital\Twital
*/
- public function getTwital() {
+ public function getTwital()
+ {
+ if ($this->twital===null) {
+ $this->twital = new Twital();
+ }
- if ($this->twital===null) {
- $this->twital = new Twital();
- }
- return $this->twital;
- }
+ return $this->twital;
+ }
-}
\ No newline at end of file
+}
diff --git a/tests/Goetas/Twital/Tests/CoreAttributeTest.php b/tests/Goetas/Twital/Tests/CoreAttributeTest.php
index ce45c4a..4d78ca6 100644
--- a/tests/Goetas/Twital/Tests/CoreAttributeTest.php
+++ b/tests/Goetas/Twital/Tests/CoreAttributeTest.php
@@ -4,10 +4,8 @@
use Goetas\Twital\Twital;
use Goetas\Twital\SourceAdapter\XMLAdapter;
-
class CoreAttributeTest extends \PHPUnit_Framework_TestCase
{
-
/**
* Prepares the environment before running a test.
*/
@@ -56,5 +54,3 @@ public function getData()
);
}
}
-
-
diff --git a/tests/Goetas/Twital/Tests/CoreNodesTest.php b/tests/Goetas/Twital/Tests/CoreNodesTest.php
index ea27d14..c963df7 100644
--- a/tests/Goetas/Twital/Tests/CoreNodesTest.php
+++ b/tests/Goetas/Twital/Tests/CoreNodesTest.php
@@ -2,12 +2,9 @@
namespace Goetas\Twital\Tests;
use Goetas\Twital\Twital;
-use Goetas\Twital\SourceAdapter\XMLAdapter;
-
abstract class CoreNodesTest extends \PHPUnit_Framework_TestCase
{
-
protected $twital;
protected $sourceAdapter;
/**
@@ -20,7 +17,7 @@ protected function setUp()
$this->sourceAdapter = $this->getSourceAdapter();
}
- protected abstract function getSourceAdapter();
+ abstract protected function getSourceAdapter();
/**
* @dataProvider getData
@@ -79,6 +76,7 @@ public function getDataFormTemplates()
$expected,
);
}
+
return $data;
}
@@ -92,5 +90,3 @@ public function testVisitNodeTemplates($source, $expected)
}
}
-
-
diff --git a/tests/Goetas/Twital/Tests/DynamicAttrAttributeTest.php b/tests/Goetas/Twital/Tests/DynamicAttrAttributeTest.php
index ba8d24e..c3097c9 100644
--- a/tests/Goetas/Twital/Tests/DynamicAttrAttributeTest.php
+++ b/tests/Goetas/Twital/Tests/DynamicAttrAttributeTest.php
@@ -2,10 +2,8 @@
namespace Goetas\Twital\Tests;
use Goetas\Twital\TwitalLoader;
-use Goetas\Twital\Twital;
use Goetas\Twital\SourceAdapter\XMLAdapter;
-
class DynamicAttrAttributeTest extends \PHPUnit_Framework_TestCase
{
/**
@@ -48,8 +46,8 @@ public function getData()
array('', ''),
array('