check type in Smarty plugin

This commit is contained in:
Etienne Roudeix
2013-06-24 12:31:47 +02:00
parent 06543bb68c
commit 00a8ad51b3
3 changed files with 36 additions and 82 deletions

View File

@@ -237,7 +237,15 @@ class TheliaLoop implements SmartyPluginInterface {
continue;
}
/* check default */
/* check type */
if($value !== null && !$argument->type->isValid($value)) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('Invalid value for "%s" argument', $argument->name);
continue;
}
/* set default */
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
if($value === null) {
$value = $argument->default;
}

View File

@@ -65,7 +65,7 @@ class TypeCollection implements \Iterator
* (PHP 5 &gt;= 5.0.0)<br/>
* Return the current element
* @link http://php.net/manual/en/iterator.current.php
* @return \Thelia\Core\Template\Element\LoopResultRow
* @return \Thelia\Type\TypeInterface
*/
public function current()
{
@@ -116,4 +116,25 @@ class TypeCollection implements \Iterator
{
$this->position = 0;
}
/**
* @param $value
*
* @return bool
*/
public function isValid($value)
{
$this->rewind();
while ($this->valid()) {
$type = $this->current();
if($type->isValid($value)) {
return true;
}
$this->next();
}
return false;
}
}