phplibrary/core/validator/rule/count.php
2016-07-14 16:29:26 +03:00

34 lines
817 B
PHP

<?php
require_once 'abstract.php';
/**
* Проверка формата даты
*/
class Rule_Count extends Rule_Abstract
{
public $size = 1;
public $max = false;
public function getErrorMsg()
{
return "Количество записей должно быть не менне {$this->size} и не более {$this->max}";
}
function not_empty($s) {
return $s != "";
}
public function isValid(Collection $container, $status = null)
{
if (!$this->max) {
$this->max = $this->size;
}
$count = count(array_filter(array_map('trim',
explode(";", $container->get($this->field))), array($this, 'not_empty')));
return $count >= $this->size && $count <= $this->max;
}
}