Ejemplo n.º 1
0
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()));
    }
}
Ejemplo n.º 2
0
 protected function setUp()
 {
     $this->handler = new Handler(new CheckerCollection(), ValidatorSingleton::getInstance());
     ValidatorSingleton::getInstance()->setNextValidator(new \checkTypes\Validator\MultiTypeValidator())->setNextValidator(new \checkTypes\Validator\TypeValidator())->setNextValidator(new \checkTypes\Validator\ObjectValidator())->setNextValidator(new \checkTypes\Validator\DefaultValueValidator());
     CheckerCollection::getInstance()->add('mixed', new \checkTypes\Checker\CheckerMixed())->add('boolean', new \checkTypes\Checker\CheckerBoolean())->add('bool', new \checkTypes\Checker\CheckerBoolean())->add('integer', new \checkTypes\Checker\CheckerInteger())->add('int', new \checkTypes\Checker\CheckerInteger())->add('double', new \checkTypes\Checker\CheckerFloat())->add('float', new \checkTypes\Checker\CheckerFloat())->add('string', new \checkTypes\Checker\CheckerString())->add('array', new \checkTypes\Checker\CheckerArray())->add('resource', new \checkTypes\Checker\CheckerResource())->add('callable', new \checkTypes\Checker\CheckerCallable())->add('self', new \checkTypes\Checker\CheckerSelf())->add('parent', new \checkTypes\Checker\CheckerParent());
 }