PhpDeal\Aspect\AbstractContractAspect::ensureContracts PHP Метод

ensureContracts() защищенный Метод

Performs verification of contracts for given invocation
protected ensureContracts ( Go\Aop\Intercept\MethodInvocation $invocation, array $contracts, object | string $instance, string $scope, array $args )
$invocation Go\Aop\Intercept\MethodInvocation Current invocation
$contracts array Contract annotation
$instance object | string Invocation instance or string for static class
$scope string Scope of method
$args array List of arguments for the method
    protected function ensureContracts(MethodInvocation $invocation, array $contracts, $instance, $scope, array $args)
    {
        static $invoker = null;
        if (!$invoker) {
            $invoker = function () {
                extract(func_get_arg(0));
                return eval('return ' . func_get_arg(1) . '; ?>');
            };
        }
        $instance = is_object($instance) ? $instance : null;
        $boundInvoker = $invoker->bindTo($instance, $scope);
        foreach ($contracts as $contract) {
            $contractExpression = $contract->value;
            try {
                $invocationResult = $boundInvoker->__invoke($args, $contractExpression);
                // we accept as a result only true or null
                // null may be a result of assertions from beberlei/assert which passed
                if ($invocationResult !== null && $invocationResult !== true) {
                    $errorMessage = 'Invalid return value received from the assertion body,' . ' only boolean or void can be returned';
                    throw new DomainException($errorMessage);
                }
            } catch (\Error $internalError) {
                // PHP-7 friendly interceptor for fatal errors
                throw new ContractViolation($invocation, $contractExpression, $internalError);
            } catch (\Exception $internalException) {
                throw new ContractViolation($invocation, $contractExpression, $internalException);
            }
        }
    }