Assert\Assertion::implementsInterface PHP Method

implementsInterface() public static method

Assert that the class implements the interface
public static implementsInterface ( mixed $class, string $interfaceName, string | null $message = null, string | null $propertyPath = null ) : boolean
$class mixed
$interfaceName string
$message string | null
$propertyPath string | null
return boolean
    public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null)
    {
        $reflection = new \ReflectionClass($class);
        if (!$reflection->implementsInterface($interfaceName)) {
            $message = sprintf($message ?: 'Class "%s" does not implement interface "%s".', static::stringify($class), static::stringify($interfaceName));
            throw static::createException($class, $message, static::INTERFACE_NOT_IMPLEMENTED, $propertyPath, array('interface' => $interfaceName));
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param mixed $value
  */
 protected function setValue($value)
 {
     //We use the string assertion first
     parent::setValue($value);
     //and then check, if we really got an item class
     Assertion::implementsInterface($value, 'Prooph\\Processing\\Type\\Type');
 }
All Usage Examples Of Assert\Assertion::implementsInterface