diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php new file mode 100644 index 000000000..b6085ad7c --- /dev/null +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -0,0 +1,103 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Element; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + +/** + * + * Class BaseLoop + * @package Thelia\Tpex\Element\Loop + */ +abstract class BaseLoop +{ + /** + * @var \Symfony\Component\HttpFoundation\Request + */ + public $request; + + /** + * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface + */ + public $dispatcher; + + /** + * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher + */ + public function __construct(Request $request, EventDispatcherInterface $dispatcher) + { + $this->request = $request; + $this->dispatcher = $dispatcher; + } + + /** + * + * this function have to be implement in your own loop class. + * + * All your parameters are defined in defineArgs() and can be accessible like a class property. + * + * example : + * + * public function defineArgs() + * { + * return array ( + * "ref", + * "id" => "optional", + * "stock" => array( + * "optional", + * "default" => 10 + * ) + * ); + * } + * + * you can retrieve ref value using $this->ref + * + * @return mixed + */ + abstract public function exec(); + + /** + * + * define all args used in your loop + * + * array key is your arg name. + * + * example : + * + * return array ( + * "ref", + * "id" => "optional", + * "stock" => array( + * "optional", + * "default" => 10 + * ) + * ); + * + * @return array + */ + abstract public function defineArgs(); + +} diff --git a/core/lib/Thelia/Core/Template/Element/Exception/ElementNotFoundException.php b/core/lib/Thelia/Core/Template/Element/Exception/ElementNotFoundException.php new file mode 100644 index 000000000..a2695ce6b --- /dev/null +++ b/core/lib/Thelia/Core/Template/Element/Exception/ElementNotFoundException.php @@ -0,0 +1,29 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Element\Exception; + +class ElementNotFoundException extends \RuntimeException +{ + +} diff --git a/core/lib/Thelia/Core/Template/Element/Exception/InvalidElementException.php b/core/lib/Thelia/Core/Template/Element/Exception/InvalidElementException.php new file mode 100644 index 000000000..5a4983aa2 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Element/Exception/InvalidElementException.php @@ -0,0 +1,29 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Element\Exception; + +class InvalidElementException extends \RuntimeException +{ + +} diff --git a/core/lib/Thelia/Core/Template/Element/LoopResult.php b/core/lib/Thelia/Core/Template/Element/LoopResult.php new file mode 100644 index 000000000..a1d713c01 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Element/LoopResult.php @@ -0,0 +1,108 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Element; + +use Thelia\Core\Template\Element\LoopResultRow; + +class LoopResult implements \Iterator +{ + private $position; + protected $collection = array(); + + public function __construct() + { + $this->position = 0; + } + + public function isEmpty() + { + return count($this->collection) == 0; + } + + public function addRow(LoopResultRow $row) + { + $this->collection[] = $row; + } + + public function getCount() + { + return count($this->collection); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Return the current element + * @link http://php.net/manual/en/iterator.current.php + * @return \Thelia\Core\Template\Element\LoopResultRow + */ + public function current() + { + return $this->collection[$this->position]; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Move forward to next element + * @link http://php.net/manual/en/iterator.next.php + * @return void Any returned value is ignored. + */ + public function next() + { + ++$this->position; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Return the key of the current element + * @link http://php.net/manual/en/iterator.key.php + * @return mixed scalar on success, or null on failure. + */ + public function key() + { + return $this->position; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Checks if current position is valid + * @link http://php.net/manual/en/iterator.valid.php + * @return boolean The return value will be casted to boolean and then evaluated. + * Returns true on success or false on failure. + */ + public function valid() + { + return isset($this->collection[$this->position]); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Rewind the Iterator to the first element + * @link http://php.net/manual/en/iterator.rewind.php + * @return void Any returned value is ignored. + */ + public function rewind() + { + $this->position = 0; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Element/LoopResultRow.php b/core/lib/Thelia/Core/Template/Element/LoopResultRow.php new file mode 100644 index 000000000..24e14afab --- /dev/null +++ b/core/lib/Thelia/Core/Template/Element/LoopResultRow.php @@ -0,0 +1,46 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Element; + + +class LoopResultRow { + + protected $substitution = array(); + + public function set($key, $value) + { + $this->substitution["#".$key] = $value; + } + + public function get($key) + { + return $this->substitution["#".$key]; + } + + public function getVarVal() + { + return $this->substitution; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index 8738cc47e..4541e4c0f 100644 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -25,9 +25,9 @@ namespace Thelia\Core\Template\Loop; -use Thelia\Tpex\Element\Loop\BaseLoop; -use Thelia\Tpex\Element\Loop\LoopResult; -use Thelia\Tpex\Element\Loop\LoopResultRow; +use Thelia\Core\Template\Element\BaseLoop; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Model\CategoryQuery; /** @@ -94,7 +94,7 @@ class Category extends BaseLoop { /** * * - * @return \Thelia\Tpex\Element\Loop\LoopResult + * @return \Thelia\Core\Template\Element\LoopResult */ public function exec() { diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index 162f261b5..d8b1abd9a 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -26,6 +26,9 @@ namespace Thelia\Core\Template\Smarty\Plugins; use Thelia\Core\Template\Smarty\SmartyPluginInterface; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; +use Thelia\Core\Template\Element\Exception\ElementNotFoundException; +use Thelia\Core\Template\Element\Exception\InvalidElementException; + use Symfony\Component\HttpFoundation\Request; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -167,7 +170,7 @@ class TheliaLoop implements SmartyPluginInterface { * find the loop class with his name and construct an instance of this class * * @param string $name - * @return \Thelia\Tpex\Element\Loop\BaseLoop + * @return \Thelia\Core\Template\Element\BaseLoop * @throws \Thelia\Tpex\Exception\InvalidElementException * @throws \Thelia\Tpex\Exception\ElementNotFoundException */ @@ -180,8 +183,8 @@ class TheliaLoop implements SmartyPluginInterface { $class = new \ReflectionClass($this->loopDefinition[$name]); - if ($class->isSubclassOf("Thelia\Tpex\Element\Loop\BaseLoop") === false) { - throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Tpex\Element\Loop\BaseLoop", + if ($class->isSubclassOf("Thelia\Core\Template\Element\BaseLoop") === false) { + throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Core\Template\Element\BaseLoop", $name)); } diff --git a/local/modules/Test/Config/config.xml b/local/modules/Test/Config/config.xml deleted file mode 100644 index d68e49c37..000000000 --- a/local/modules/Test/Config/config.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/local/modules/Test/Loop/Doobitch.php b/local/modules/Test/Loop/Doobitch.php deleted file mode 100644 index 12cebe7ef..000000000 --- a/local/modules/Test/Loop/Doobitch.php +++ /dev/null @@ -1,48 +0,0 @@ - array("default" => "foo") - ); - } - - public function exec($text) - { - - $res = ""; - if($this->param1 == 2 || $this->param1 == 3) { - for($i = 0; $i < 4; $i++) { - $tmp = str_replace("#ALFRED", "foo".$i, $text); - if($i%2){ - $tmp = str_replace("#CHAPO", "bar".$i, $tmp); - } else { - $tmp = str_replace("#CHAPO", "", $tmp); - } - - - $res .= $tmp; - } - } - - echo $this->param2; - - return $res; - } -} \ No newline at end of file diff --git a/local/modules/Test/Loop/Foo.php b/local/modules/Test/Loop/Foo.php deleted file mode 100644 index aa161b72a..000000000 --- a/local/modules/Test/Loop/Foo.php +++ /dev/null @@ -1,33 +0,0 @@ -