Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Validator / IsInstanceOf.php
blobe823efd1f4a44bab5d488d37336d7c1ae967aa2f
1 <?php
2 /**
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
8 */
9 namespace Zend\Validator;
11 use Traversable;
13 class IsInstanceOf extends AbstractValidator
15 const NOT_INSTANCE_OF = 'notInstanceOf';
17 /**
18 * Validation failure message template definitions
20 * @var array
22 protected $messageTemplates = array(
23 self::NOT_INSTANCE_OF => "The input is not an instance of '%className%'",
26 /**
27 * Additional variables available for validation failure messages
29 * @var array
31 protected $messageVariables = array(
32 'className' => 'className'
35 /**
36 * Class name
38 * @var string
40 protected $className;
42 /**
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);
71 /**
72 * Get class name
74 * @return string
76 public function getClassName()
78 return $this->className;
81 /**
82 * Set class name
84 * @param string $className
85 * @return self
87 public function setClassName($className)
89 $this->className = $className;
90 return $this;
93 /**
94 * Returns true if $value is instance of $this->className
96 * @param mixed $value
97 * @return bool
99 public function isValid($value)
101 if ($value instanceof $this->className) {
102 return true;
104 $this->error(self::NOT_INSTANCE_OF);
105 return false;