<?php
namespace Moto\Validator; use Moto; class ClickAction extends AbstractValidator { const ERROR_BAD_ACTION = 'badAction'; protected $messageTemplates = array( self::ERROR_BAD_ACTION => 'Bad action', ); protected $_errors = array(); public function isValid($params, array $context = array()) { $this->abstractOptions['messages'] = array(); $isValid = true; if (empty($context['action'])) { $this->error(self::ERROR_BAD_ACTION); return false; } $action = $context['action']; $inputFilter = Moto\ClickAction\Factory::getValidator($action); if ($inputFilter instanceof \Closure || is_callable($inputFilter)) { $isValid = call_user_func($inputFilter, $params, $context); } elseif ($inputFilter instanceof Moto\InputFilter\AbstractInputFilter) { $inputFilter->setData($params); $isValid = $inputFilter->isValid(); if (!$isValid) { $this->abstractOptions['messages'] = array_merge($this->abstractOptions['messages'], $inputFilter->getMessages()); } } else { $this->error(self::ERROR_BAD_ACTION); return false; } return $isValid; } public function getMessages() { return $this->abstractOptions['messages']; } }