check type in Smarty plugin
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class TypeCollection implements \Iterator
|
||||
* (PHP 5 >= 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user