3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
9 namespace Zend\Validator
;
13 class IsInstanceOf
extends AbstractValidator
15 const NOT_INSTANCE_OF
= 'notInstanceOf';
18 * Validation failure message template definitions
22 protected $messageTemplates = array(
23 self
::NOT_INSTANCE_OF
=> "The input is not an instance of '%className%'",
27 * Additional variables available for validation failure messages
31 protected $messageVariables = array(
32 'className' => 'className'
43 * Sets validator options
45 * @param array|Traversable $options
46 * @throws Exception\InvalidArgumentException
48 public function __construct($options = null)
50 if ($options instanceof Traversable
) {
51 $options = iterator_to_array($options);
54 // If argument is not an array, consider first argument as class name
55 if (!is_array($options)) {
56 $options = func_get_args();
58 $tmpOptions = array();
59 $tmpOptions['className'] = array_shift($options);
61 $options = $tmpOptions;
64 if (!array_key_exists('className', $options)) {
65 throw new Exception\
InvalidArgumentException('Missing option "className"');
68 parent
::__construct($options);
76 public function getClassName()
78 return $this->className
;
84 * @param string $className
87 public function setClassName($className)
89 $this->className
= $className;
94 * Returns true if $value is instance of $this->className
99 public function isValid($value)
101 if ($value instanceof $this->className
) {
104 $this->error(self
::NOT_INSTANCE_OF
);