function testValidFactory() { $v = new Valid_For_Inheritance($this); //Does not work in php4 :( //$this->assertReference(ValidFactory::getInstance($v), $v); $this->assertIsA(ValidFactory::getInstance($v), 'Valid_For_Inheritance'); $this->assertIsA(ValidFactory::getInstance('string'), 'Valid_String'); $this->assertIsA(ValidFactory::getInstance('uint'), 'Valid_UInt'); $this->assertNull(ValidFactory::getInstance('machinbidulechose')); $key = md5(uniqid(rand(), true)); $w = ValidFactory::getInstance('string', $key); $this->assertEqual($w->getKey(), $key); }
/** * Apply validator on submitted user value and return the value if valid * Else return default value * @param string $variable Name of the parameter to get. * @param mixed $validator Name of the validator (string, uint, email) or an instance of a validator * @param mixed $default_value Value return if the validator is not valid. Optional, default is null. */ public function getValidated($variable, $validator = 'string', $default_value = null) { $is_valid = false; if ($v = ValidFactory::getInstance($validator, $variable)) { $is_valid = $this->valid($v); } else { trigger_error('Validator ' . $validator . ' is not found', E_USER_ERROR); } return $is_valid ? $this->get($variable) : $default_value; }