/** * @param \checkTypes\Handler $handler * @param \checkTypes\Parameter $parameter * @param boolean $strict * * @return boolean */ public function isValid(Handler $handler, Parameter $parameter, $strict = false) { $checker = $handler->getCheckers()->get($parameter->type); $isValid = $checker !== NULL && call_user_func(array($checker, self::$methods[(int) $strict]), $parameter); if (!$isValid && $this->nexValidator !== NULL) { $isValid = $this->nexValidator->isValid($handler, $parameter, $strict); } return $isValid; }
function check($strict = false) { $trace = next(debug_backtrace(0)); if (!is_array($trace)) { throw new \LogicException('Invalid context'); } if (isset($trace['class'])) { $reflection = new \ReflectionMethod($trace['class'], $trace['function']); } else { $reflection = new \ReflectionFunction($trace['function']); } $handler = new Handler(new CheckerCollection(), ValidatorSingleton::getInstance()); try { $handler->check($reflection, $trace['args'], $strict); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException(sprintf('%s, called in %s on line %d and defined in %s on line %d', $e->getMessage(), $trace['file'], $trace['line'], $reflection->getFileName(), $reflection->getStartLine())); } }
public function testValidArrayOfStringNoStrict() { $this->handler->check(new \ReflectionMethod(__CLASS__, 'methodWithArrayOfString'), array(array('foo', 42))); }