Permalink
Browse files

Merge branch '2.1' of github.com:OPL/Open-Power-Template into 2.1

  • Loading branch information...
2 parents 6abf4dd + e839451 commit 582cf6300f075c0bcd2cd0283f6b9673c568f0c3 @zyxist zyxist committed Oct 12, 2010
Showing with 580 additions and 280 deletions.
  1. +19 −3 lib/Opt/Compiler/Class.php
  2. +1 −2 lib/Opt/Expression/Standard.php
  3. +1 −1 lib/Opt/Format/SwitchEquals.php
  4. +46 −6 lib/Opt/Instruction/Abstract.php
  5. +5 −0 lib/Opt/Instruction/Capture.php
  6. +45 −14 lib/Opt/Instruction/Loop/Abstract.php
  7. +1 −1 lib/Opt/Instruction/Section.php
  8. +57 −112 lib/Opt/Instruction/Selector.php
  9. +8 −6 lib/Opt/Instruction/Switch.php
  10. +14 −3 lib/Opt/Xml/Element.php
  11. +5 −8 paths.sample.ini
  12. +6 −6 tests/Package/Instruction/AllTests.php
  13. +59 −0 tests/Package/Instruction/CaptureTest.php
  14. +56 −0 tests/Package/Instruction/ForTest.php
  15. +1 −0 tests/Package/Instruction/SectionTest.php
  16. +62 −0 tests/Package/Instruction/SelectorTest.php
  17. +0 −21 tests/Package/Instruction/Tests/Capture/capture_5.txt
  18. +1 −1 tests/Package/Instruction/Tests/Capture/{capture_3.txt → capture_attribute.txt}
  19. +1 −1 tests/Package/Instruction/Tests/Capture/{capture_1.txt → capture_basic.txt}
  20. +2 −2 tests/Package/Instruction/Tests/Capture/{capture_6.txt → capture_invalid_identifier.txt}
  21. +14 −0 tests/Package/Instruction/Tests/Capture/capture_missing_identifier.txt
  22. +1 −1 tests/Package/Instruction/Tests/Capture/{capture_2.txt → capture_unchanged.txt}
  23. +5 −5 tests/Package/Instruction/Tests/Capture/{capture_4.txt → capture_use.txt}
  24. +21 −0 tests/Package/Instruction/Tests/Capture/capture_use_dynamic.txt
  25. +0 −25 tests/Package/Instruction/Tests/For/for_2.txt
  26. +1 −2 tests/Package/Instruction/Tests/For/{for_1.txt → for_basic.txt}
  27. +24 −0 tests/Package/Instruction/Tests/For/for_separator_attr.txt
  28. +2 −3 tests/Package/Instruction/Tests/For/{for_3.txt → for_separator_tag.txt}
  29. +37 −0 tests/Package/Instruction/Tests/Section/section_attribute_separators.txt
  30. +0 −19 tests/Package/Instruction/Tests/Selector/selector_6.txt
  31. +0 −15 tests/Package/Instruction/Tests/Selector/selector_7.txt
  32. +3 −3 tests/Package/Instruction/Tests/Selector/{selector_8.txt → selector_attribute.txt}
  33. +28 −0 tests/Package/Instruction/Tests/Selector/selector_attribute_separator.txt
  34. +3 −3 tests/Package/Instruction/Tests/Selector/{selector_1.txt → selector_basic.txt}
  35. +19 −0 tests/Package/Instruction/Tests/Selector/selector_else.txt
  36. +15 −0 tests/Package/Instruction/Tests/Selector/selector_multiple_else.txt
  37. +3 −3 tests/Package/Instruction/Tests/Selector/{selector_5.txt → selector_separator.txt}
  38. +4 −4 tests/Package/Instruction/Tests/Selector/{selector_3.txt → selector_show.txt}
  39. +4 −4 tests/Package/Instruction/Tests/Selector/{selector_4.txt → selector_show_test.txt}
  40. +3 −3 tests/Package/Instruction/Tests/Selector/{selector_2.txt → selector_test.txt}
  41. +3 −3 tests/Package/Instruction/Tests/Switch/switch_else.txt
View
@@ -706,7 +706,7 @@ public function parseSpecialChars($text)
*/
public function isIdentifier($id)
{
- return preg_match('/[A-Za-z]([A-Za-z0-9.\_]|\-)*/si', $id);
+ return preg_match('/^[A-Za-z]([A-Za-z0-9.\_]|\-)*$/si', $id);
} // end isIdentifier();
/**
@@ -1239,7 +1239,7 @@ public function appendOutput($text)
/**
* Sets the new node children queue used in stages 2 and 3 of the compilation.
*
- * @param SplQueue|Opt_Xml_Scannable $children The children list.
+ * @param SplQueue|Opt_Xml_Scannable|array $children The children list.
*/
public function setChildren($children)
{
@@ -1250,7 +1250,7 @@ public function setChildren($children)
$this->_newQueue = $children;
}
}
- else if($children instanceof Opt_Xml_Scannable)
+ elseif($children instanceof Opt_Xml_Scannable)
{
if($children->hasChildren() > 0)
{
@@ -1261,6 +1261,22 @@ public function setChildren($children)
}
}
}
+ elseif(is_array($children))
+ {
+ $notCreated = true;
+ foreach($children as $childList)
+ {
+ if(count($childList) > 0 && $notCreated)
+ {
+ $notCreated = false;
+ $this->_newQueue = new SplQueue;
+ }
+ foreach($childList as $child)
+ {
+ $this->_newQueue->enqueue($child);
+ }
+ }
+ }
} // end setChildren();
/*
@@ -447,7 +447,7 @@ public function _compileVariable(array $variable, $type, $weight, $context = 0,
// Check if any section with the specified name exists.
$sectionName = $this->_compiler->convert($item);
- if(($section = $proc->getSection($sectionName)) !== null)
+ if(($section = Opt_Instruction_Section_Abstract::getSection($sectionName)) !== null)
{
$path = $sectionName;
$state['section'] = $section;
@@ -458,7 +458,6 @@ public function _compileVariable(array $variable, $type, $weight, $context = 0,
$hook = 'section:item'.$this->_dfCalls[$context];
if(!$section['format']->property($hook))
{
- var_dump($hook);
throw new Opt_Format_Exception('The operation '.$hook.' is not supported by format '.$section['format']->getName());
}
$section['format']->assign('value', $contextInfo[0]);
@@ -97,7 +97,7 @@ protected function _build($hookName)
case 'switch:enterTestEnd.later':
return ' } ';
case 'switch:testsBefore':
- $code = $this->_stateInitializer.' switch($__test) { ';
+ $code = $this->_stateInitializer.' $__state_'.self::$_counter.' = null; switch($__test) { ';
$this->_stateInitializer = '';
return $code;
case 'switch:testsAfter':
@@ -80,6 +80,13 @@
private $_ambiguous = array();
/**
+ * The linked processor, where the actual processing nodes are redirected.
+ * @internal
+ * @var Opt_Instruction_Abstract
+ */
+ private $_linkedProcessor = null;
+
+ /**
* Creates a new instruction processor for the specified compiler.
*
* @param Opt_Compiler_Class $compiler The compiler object.
@@ -122,6 +129,27 @@ public function reset()
} // end reset();
/**
+ * Attaches this instruction processor to another one, so that our nodes
+ * redirected to processing are redirected to that processor. This is
+ * useful, where we want to use some API methods provided by other
+ * processors.
+ *
+ * @param Opt_Instruction_Abstract $linkedProcessor
+ */
+ public function attach(Opt_Instruction_Abstract $linkedProcessor)
+ {
+ $this->_linkedProcessor = $linkedProcessor;
+ } // end attach();
+
+ /**
+ * Detaches the linked processor.
+ */
+ public function detach()
+ {
+ $this->_linkedProcessor = null;
+ } // end detach();
+
+ /**
* This method is called automatically for each XML element that the
* processor has registered, because of backwards compatibility mode is on.
* It can handle many instructions tags, and the default implementation
@@ -292,15 +320,21 @@ public function processSystemVar($opt)
*/
final protected function _process(Opt_Xml_Node $node)
{
- if($this->_queue === null)
+ $proc = $this;
+ if($this->_linkedProcessor !== null)
{
- $this->_queue = new SplQueue;
+ $proc = $this->_linkedProcessor;
+ }
+
+ if($proc->_queue === null)
+ {
+ $proc->_queue = new SplQueue;
}
if($node->hasChildren())
{
foreach($node as $child)
{
- $this->_queue->enqueue($child);
+ $proc->_queue->enqueue($child);
}
}
} // end _process();
@@ -313,11 +347,17 @@ public function processSystemVar($opt)
*/
final protected function _enqueue(Opt_Xml_Node $node)
{
- if($this->_queue === null)
+ $proc = $this;
+ if($this->_linkedProcessor !== null)
+ {
+ $proc = $this->_linkedProcessor;
+ }
+
+ if($proc->_queue === null)
{
- $this->_queue = new SplQueue;
+ $proc->_queue = new SplQueue;
}
- $this->_queue->enqueue($node);
+ $proc->_queue->enqueue($node);
} // end _enqueue();
/**
@@ -139,11 +139,16 @@ public function processAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr)
* allows a simple access to the captured codes.
*
* @internal
+ * @throws Opt_Instruction_Exception
* @param array $namespace The namespace to parse
* @return string
*/
public function processSystemVar($opt)
{
+ if(!isset($opt[2]))
+ {
+ throw new Opt_Instruction_Exception('opt:capture error: missing the captured block name in the special call $system.capture.');
+ }
return 'self::$_capture[\''.$opt[2].'\']';
} // end processSystemVar();
} // end Opt_Instruction_Capture;
@@ -24,6 +24,8 @@
*/
abstract class Opt_Instruction_Loop_Abstract extends Opt_Instruction_Abstract
{
+ const ATTRIBUTE_FORM = true;
+
/**
* Processes the loop separator. The programmer must provide the
* variable name that will be used to check if we need to apply
@@ -32,38 +34,67 @@
* XML node.
*
* If the node contains too many opt:separator tags, an exception
- * is thrown.
+ * is thrown. The method returns the found separator element.
+ *
+ * If the method is used with an attribute form of the loop, the fourth
+ * argument should be set to Opt_Instruction_Loop_Abstract::ATTRIBUTE_FORM.
*
* @throws Opt_Instruction_Exception
* @param string $varname The internal variable name
* @param string $arg The value of "separator" attribute
* @param Opt_Xml_Scannable $node The node the separator will be added to.
+ * @param boolean $attributeForm Optimize for the attribute form?
+ * @return Opt_Xml_Element
*/
- public function processSeparator($varname, $arg, Opt_Xml_Scannable $node)
+ public function processSeparator($varname, $arg, Opt_Xml_Scannable $node, $attributeForm = false)
{
$items = $node->getElementsByTagNameNS('opt', 'separator', false);
switch(sizeof($items))
{
case 1:
// Move this node to the beginning
- $node->removeChild($items[0]);
- $node->insertBefore($items[0], 0);
- $this->_process($items[0]);
- $items[0]->set('hidden', false);
+ if($attributeForm)
+ {
+ $node->removeChild($items[0]);
+ $node->getParent()->insertBefore($items[0], $node);
+ $items[0]->set('hidden', false);
+ $this->_process($items[0]);
+ $items[0]->copyBuffer($node, Opt_Xml_Buffer::TAG_BEFORE, Opt_Xml_Buffer::TAG_BEFORE);
+ $node->clear(Opt_Xml_Buffer::TAG_BEFORE);
- // Add PHP code
- $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, ' '.$varname.' = 0;');
- $items[0]->addBefore(Opt_Xml_Buffer::TAG_BEFORE, 'if('.$varname.' == 1){');
- $items[0]->addAfter(Opt_Xml_Buffer::TAG_AFTER, '}else{ '.$varname.' = 1; }');
- break;
+ // Add PHP code
+ $items[0]->addBefore(Opt_Xml_Buffer::TAG_BEFORE, ' '.$varname.' = 0;');
+ $items[0]->addBefore(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, 'if('.$varname.' == 1){');
+ $items[0]->addAfter(Opt_Xml_Buffer::TAG_CONTENT_AFTER, '}else{ '.$varname.' = 1; }');
+ }
+ else
+ {
+ $node->removeChild($items[0]);
+ $node->insertBefore($items[0], 0);
+ $this->_process($items[0]);
+ $items[0]->set('hidden', false);
+
+ // Add PHP code
+ $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, ' '.$varname.' = 0;');
+ $items[0]->addBefore(Opt_Xml_Buffer::TAG_BEFORE, 'if('.$varname.' == 1){');
+ $items[0]->addAfter(Opt_Xml_Buffer::TAG_AFTER, '}else{ '.$varname.' = 1; }');
+ }
+ return $items[0];
case 0:
- if(!is_null($arg))
+ if($arg !== null)
{
$node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, $varname.' = 0;');
- $node->addBefore(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, 'if('.$varname.' == 1){ echo '.$arg.'; }else{ '.$varname.' = 1; }');
+ if($attributeForm)
+ {
+ $node->addAfter(Opt_Xml_Buffer::TAG_OPENING_BEFORE, 'if('.$varname.' == 1){ echo '.$arg.'; }else{ '.$varname.' = 1; }');
+ }
+ else
+ {
+ $node->addBefore(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, 'if('.$varname.' == 1){ echo '.$arg.'; }else{ '.$varname.' = 1; }');
+ }
}
- break;
+ return null;
default:
throw new Opt_Instruction_Exception('Too many "opt:separator" elements: zero or one expected.');
}
@@ -248,7 +248,7 @@ protected function _processAttrSection(Opt_Xml_Node $node, Opt_Xml_Attribute $at
$code .= $section['format']->get('section:startDescLoop');
}
$node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, $code);
- $this->processSeparator('$__sect_'.$section['name'], $section['separator'], $node);
+ $this->processSeparator('$__sect_'.$section['name'], $section['separator'], $node, Opt_Instruction_Loop_Abstract::ATTRIBUTE_FORM);
$attr->set('postprocess', true);
} // end _processAttrSection();
Oops, something went wrong.

0 comments on commit 582cf63

Please sign in to comment.