Location: PHPKode > scripts > QValidation > qvalidation/Validation/DataType/Object.php
<?php

class Validation_DataType_Object extends Validation {

	public static function getInstance(){
		return new Validation_DataType_Object;
	}

	/**
	 * validateInstanceOf
	 * @desc check the instance of an object
	 * @param array $value
	 * @return bool
	 */
	public function validateInstanceOf(array $value) {
		if (is_array($value) && count($value) == 2) {
			if(is_object($value[0]) and is_string($value[1])){
				return $value[0] instanceof $value[1];
			}
		}
		return false;
	}

	/**
	 * validateAsChildOf
	 * @desc check whether an object is a sub class of another class
	 * @example
	 * array("classA","classB")
	 * array(new ObjectA, new ObjectB)
	 * @param array $value
	 * @return bool
	 */
	public function validateAsChildOf(array $value) {
		if (is_array($value) && count($value) == 2) {
			$className = is_object($value[0]) ? get_class($value[0]) : (is_string($value[0])?$value[0]:false);
			$classNameParent = is_object($value[1]) ? get_class($value[1]) : (is_string($value[1])?$value[1]:false);
			if($className and $classNameParent) {
				$r = new ReflectionClass($className);
				return $r->isSubclassOf($classNameParent);
			}
		}
		return false;
	}

	/**
	 * validateCallback
	 * @desc checks an object whether it has a callable method or not
	 * array((object) object, (string) methodname)
	 * @example array(new Test,"render");
	 * @param array $value
	 * @return boolean
	 */
	public static function validateCallback(array $value) {
		if (is_array($value) && count($value) == 2) {
			$value = array_values($value);
			if ((!is_string($value[0]) && !is_object($value[0])) || (is_string($value[0]) && !class_exists($value[0]))) {
				return false;
			}
			$isObj = is_object($value[0]);
			$class = new ReflectionClass($isObj ? get_class($value[0]) : $value[0]);
			if ($class->isAbstract()) {
				return false;
			}
			try {
				$method = $class->getMethod($value[1]);
				if (!$method->isPublic() || $method->isAbstract()) {
					return false;
				}
				if (!$isObj && !$method->isStatic()) {
					return false;
				}
			} catch (ReflectionException $e) {
				return false;
			}
			return true;
		} elseif (is_string($value) && function_exists($value)) {
			return true;
		}
		return false;
	}

}
Return current item: QValidation