<?php
/**
* ArrayValidator ... checks array length
*
* Parameters:
* 'min'
* 'max'
*/
class ArrayValidator extends AgaviValidator
{
/**
* Validates the input.
*
* @return bool The value is in the array.
*/
protected function validate()
{
$value = $this->getData($this->getArgument() );
if (!is_array($value) )
{
$this->throwError();
return false;
}
$size = count($value);
if ($this->hasParameter('min') )
{
if ($size < $this->getParameter('min') )
{
$this->throwError('min');
return false;
}
}
if ($this->hasParameter('max') )
{
if ($size > $this->getParameter('max') )
{
$this->throwError('max');
return false;
}
}
return true;
}
}
?>