public function validateContract($class, $contract)
    {
        $validateObject = function ($object) {
            //does need trigger when calling *_exists with object
            $condition = is_string($object) ? class_exists($object) || interface_exists($object) : is_object($object);
            if (false === $condition) {
                $this->throwException(new \InvalidArgumentException('Class not exists ' . $object));
            }
        };

        $convertClassToString = function ($object) {
            if (is_object($object)) {
                $object = get_class($object);
            }

            return is_string($object) ? $object : false;
        };

        $validateObject($class);
        $validateObject($contract);

        if (!($class instanceof $contract)) {

            if (is_object($class)) {
                $class = get_class($class);
            }
            $this->throwException(new \LogicException($convertClassToString($class) . ' needs to be an instance of ' . $convertClassToString($contract)));
        }

        return $class;
    }
public function validateContract($class, $contract)
    {
        $validateObject = function ($object) {
            //does need trigger when calling *_exists with object
            $condition = is_string($object) ? class_exists($object) || interface_exists($object) : is_object($object);
            if (false === $condition) {
                $this->throwException(new \InvalidArgumentException('Class not exists ' . $object));
            }
        };

        $convertClassToString = function ($object) {
            if (is_object($object)) {
                $object = get_class($object);
            }

            return is_string($object) ? $object : false;
        };

        $validateObject($class);
        $validateObject($contract);

        if (!($class instanceof $contract)) {

            if (is_object($class)) {
                $class = get_class($class);
            }
            $this->throwException(new \LogicException($convertClassToString($class) . ' needs to be an instance of ' . $convertClassToString($contract)));
        }

        return $class;
    }
public function validateContract ( $ class , $ contract ) { $ validateObject = function ( $ object ) { //does need trigger when calling *_exists with object $ condition = is_string ( $ object ) ? class_exists ( $ object ) || interface_exists ( $ object ) : is_object ( $ object ) ; if ( false === $ condition ) { $ this -> throwException ( new \ InvalidArgumentException ( 'Class not exists ' . $ object ) ) ; } } ; $ convertClassToString = function ( $ object ) { if ( is_object ( $ object ) ) { $ object = get_class ( $ object ) ; } return is_string ( $ object ) ? $ object : false ; } ; $ validateObject ( $ class ) ; $ validateObject ( $ contract ) ; if ( ! ( $ class instanceof $ contract ) ) { if ( is_object ( $ class ) ) { $ class = get_class ( $ class ) ; } $ this -> throwException ( new \ LogicException ( $ convertClassToString ( $ class ) . ' needs to be an instance of ' . $ convertClassToString ( $ contract ) ) ) ; } return $ class ; }
Validates that class is instance of contract

@param $class
@param $contract

@return string|object

@throws \InvalidArgumentException|\LogicException
Validates that class is instance of contract