diff --git a/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php b/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php new file mode 100644 index 000000000..1be69e18f --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php @@ -0,0 +1,44 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Core\Template\Loop\Argument; + +/** + * + * @author Etienne Roudeix + * + */ +class Argument +{ + protected $name; + protected $type; + protected $mandatory; + protected $default; + + public function __construct($name, \Thelia\Type\TypeCollection $type, $mandatory = false, $default = null) + { + $this->name = $name; + $this->type = $type; + $this->mandatory = $mandatory ? true : false; + $this->default = $default; + } +} diff --git a/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php b/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php new file mode 100644 index 000000000..84cf958db --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php @@ -0,0 +1,119 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Core\Template\Loop\Argument; + +/** + * + * @author Etienne Roudeix + * + */ + +class ArgumentCollection implements \Iterator +{ + private $position; + protected $arguments = array(); + + public function __construct() + { + foreach(func_get_args() as $argument) { + $this->addArgument($argument); + } + } + + public function isEmpty() + { + return count($this->arguments) == 0; + } + + /** + * @param Argument $argument + * + * @return ArgumentCollection + */ + public function addArgument(Argument $argument) + { + $this->arguments[] = $argument; + return $this; + } + + public function getCount() + { + return count($this->arguments); + } + + /** + * (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->arguments[$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->arguments; + } + + /** + * (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->arguments; + } + + /** + * (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->arguments[$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; + } +} diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index 66ef3f084..5f03336ce 100755 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -26,7 +26,14 @@ namespace Thelia\Core\Template\Loop; use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; + +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Log\Tlog; + use Thelia\Model\CategoryQuery; +use Thelia\Type\TypeCollection; +use Thelia\Type; /** * @@ -74,18 +81,83 @@ class Category extends BaseLoop public function defineArgs() { - return array( - "id" => "optional", - "parent" => "optional", - "current" => "optional", - "not_empty" => 0, - "visible" => 1, - "link" => "optional", - "order" => "optional", - "random" => 0, - "exclude" => "optional", - "limit" => 10, - "offset" => 0, + return new ArgumentCollection( + new Argument( + 'id', + new TypeCollection( + new Type\AnyType() + ) + ), + new Argument( + 'parent', + new TypeCollection( + new Type\AnyType() + ) + ), + new Argument( + 'current', + new TypeCollection( + new Type\AnyType() + ) + ), + new Argument( + 'not_empty', + new TypeCollection( + new Type\AnyType() + ), + false, + 0 + ), + new Argument( + 'visible', + new TypeCollection( + new Type\AnyType() + ), + false, + 1 + ), + new Argument( + 'link', + new TypeCollection( + new Type\AnyType() + ) + ), + new Argument( + 'order', + new TypeCollection( + new Type\AnyType() + ) + ), + new Argument( + 'random', + new TypeCollection( + new Type\AnyType() + ), + false, + 0 + ), + new Argument( + 'exclude', + new TypeCollection( + new Type\AnyType() + ) + ), + new Argument( + 'limit', + new TypeCollection( + new Type\AnyType() + ), + false, + 10 + ), + new Argument( + 'offset', + new TypeCollection( + new Type\AnyType() + ), + false, + 0 + ) ); } diff --git a/core/lib/Thelia/Type/AnyType.php b/core/lib/Thelia/Type/AnyType.php new file mode 100644 index 000000000..5b00a5aeb --- /dev/null +++ b/core/lib/Thelia/Type/AnyType.php @@ -0,0 +1,42 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Type; + +/** + * + * @author Etienne Roudeix + * + */ + +class AnyType implements TypeInterface +{ + public function getType() + { + return 'Any type'; + } + + public function isValid($value) + { + return true; + } +} diff --git a/core/lib/Thelia/Type/TypeCollection.php b/core/lib/Thelia/Type/TypeCollection.php new file mode 100644 index 000000000..6ec10731b --- /dev/null +++ b/core/lib/Thelia/Type/TypeCollection.php @@ -0,0 +1,119 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Type; + +/** + * + * @author Etienne Roudeix + * + */ + +class TypeCollection implements \Iterator +{ + private $position; + protected $types = array(); + + public function __construct() + { + foreach(func_get_args() as $type) { + $this->addType($type); + } + } + + public function isEmpty() + { + return count($this->types) == 0; + } + + /** + * @param TypeInterface $type + * + * @return TypeCollection + */ + public function addType(TypeInterface $type) + { + $this->types[] = $type; + return $this; + } + + public function getCount() + { + return count($this->types); + } + + /** + * (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->types[$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->types; + } + + /** + * (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->types; + } + + /** + * (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->types[$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; + } +} diff --git a/core/lib/Thelia/Type/TypeInterface.php b/core/lib/Thelia/Type/TypeInterface.php new file mode 100644 index 000000000..ae626f0b9 --- /dev/null +++ b/core/lib/Thelia/Type/TypeInterface.php @@ -0,0 +1,36 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Type; + +/** + * + * @author Etienne Roudeix + * + */ + +interface TypeInterface +{ + public function getType(); + + public function isValid($value); +}