Asserts that a class implements an interface.

@param string $interfaceName
@param string $className
974477
final protected function assertClassImplementsInterface(string $interfaceName, string $className): void
    {
        $this->assertInterfaceExists($interfaceName);
        $this->assertClassExists($className);

        $reflection = new \ReflectionClass($className);

        self::assertTrue($reflection->implementsInterface($interfaceName), \sprintf(
            'Failed asserting that class "%s" implements interface "%s".',
            $className,
            $interfaceName
        ));
    }
1203627
public static function implementsInterface($value, string $interface): bool
    {
        if (!is_object($value)) {
            if (!(static::classExists($value) || static::interfaceExists($value))) {
                return false;
            }
            $value = (string) $value;
        }

        $reflection = new ReflectionClass($value);

        return $reflection->implementsInterface($interface);
    }
132153
public static function autoload($className)
    {
        // validate classname
        if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/m', $className)) {
            throw new Exception("Class name '$className' is invalid");
        }

        $classFile = self::$_baseDir . '/' . str_replace('_', '/', $className) . '.php';

        // check if file exists
        if (!file_exists($classFile)) {
            throw new Exception("File $classFile does not exist!");
        }

        require $classFile;

        if (!class_exists($className) && !interface_exists($className)) {
            throw new Exception("Class $className could not be found!");
        }
    }
534808
public function add($interactorName, $className)
    {
        if (! $this->definitionExists($interactorName, $className)) {
            $this->validate($interactorName, $className);
            $this->set($interactorName, $className);
        }
    }
362349
protected function forgetClass($className)
    {
        $this->log('Forget class ' . $className, LogLevel::DEBUG);
        if (isset($this->classesCurrentlyBeingForgotten[$className])) {
            $this->log('Detected recursion while forgetting class ' . $className, LogLevel::WARNING);
            return;
        }
        $this->classesCurrentlyBeingForgotten[$className] = true;

        if (class_exists($className)) {
            $interfaceNames = class_implements($className);
            foreach ($interfaceNames as $interfaceName) {
                if (isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className])) {
                    unset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className]);
                }
            }
        } else {
            foreach ($this->availableClassNames as $interfaceNames) {
                foreach ($interfaceNames as $interfaceName) {
                    if (isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className])) {
                        unset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className]);
                    }
                }
            }
        }

        if (isset($this->classReflectionData[$className][self::DATA_CLASS_SUBCLASSES])) {
            foreach (array_keys($this->classReflectionData[$className][self::DATA_CLASS_SUBCLASSES]) as $subClassName) {
                $this->forgetClass($subClassName);
            }
        }

        foreach (array_keys($this->annotatedClasses) as $annotationClassName) {
            if (isset($this->annotatedClasses[$annotationClassName][$className])) {
                unset($this->annotatedClasses[$annotationClassName][$className]);
            }
        }

        if (isset($this->classSchemata[$className])) {
            unset($this->classSchemata[$className]);
        }

        foreach (array_keys($this->classesByMethodAnnotations) as $annotationClassName) {
            unset($this->classesByMethodAnnotations[$annotationClassName][$className]);
        }

        unset($this->classReflectionData[$className]);
        unset($this->classesCurrentlyBeingForgotten[$className]);
    }
108214
public function registerType($typeName, $className)
    {
        if (isset($this->bindings[$typeName])) {
            throw new \InvalidArgumentException("`$typeName` is already registerd.");
        }

        $type = new \ReflectionClass($typeName);
        $class = new \ReflectionClass($className);
        $this->bindings[$typeName] = new Service($type, $class);

        return $this;
    }
896576
public static function hasInterface($objectOrClass, string $interfaceClassName): bool
    {
        return in_array($interfaceClassName, self::getInterfaces($objectOrClass));
    }
13847
protected function verifyClass(ClassNode $node, InterfaceNode $interfaceNode): void
    {
        $classMethods = $node->getMethods();
        $interfaceMethods = $interfaceNode->getMethods();

        $notMatchingMethods = $this->findNotMatchingMethodsForBridgeClass($classMethods, $interfaceMethods);

        foreach ($notMatchingMethods as $notMatchingMethod) {
            $message = sprintf(
                'The bridge has incorrect method \'%s\' signature. That violates the rule "%s"',
                $notMatchingMethod->getName(),
                static::RULE
            );

            $this->addViolation($node, [$message]);
        }
    }
498820
public function setClassName($className)
    {
        Assert::stringNotEmpty($className, 'The class name must be a non-empty string. Got: %s');

        $pos = strrpos($className, '\\');

        if (false === $pos) {
            $this->namespaceName = '';
            $this->shortClassName = $className;
        } else {
            $this->namespaceName = substr($className, 0, $pos);
            $this->shortClassName = substr($className, $pos + 1);
        }

        return $this;
    }
112438
public function checkInterfaceImplements(self $classDefinition, self $interfaceDefinition)
    {
        foreach ($interfaceDefinition->getMethods() as $method) {
            if (!$classDefinition->hasMethod($method->getName())) {
                throw new CompilerException(
                    sprintf(
                        'Class %s must implement a method called: "%s" as requirement of interface: "%s"',
                        $classDefinition->getCompleteName(),
                        $method->getName(),
                        $interfaceDefinition->getCompleteName()
                    )
                );
            }

            if (!$method->hasParameters()) {
                continue;
            }

            $implementedMethod = $classDefinition->getMethod($method->getName());
            if ($implementedMethod->getNumberOfRequiredParameters() > $method->getNumberOfRequiredParameters() ||
                $implementedMethod->getNumberOfParameters() < $method->getNumberOfParameters()
            ) {
                throw new CompilerException(
                    sprintf(
                        'Method %s::%s() does not have the same number of required parameters in interface: "%s"',
                        $classDefinition->getCompleteName(),
                        $method->getName(),
                        $interfaceDefinition->getCompleteName()
                    )
                );
            }
        }
    }
478541
public static boolean implementsInterface(Class<?> c, Class<?> i) {
		if (c == i)
			return true;

		for (Class<?> x : c.getInterfaces())
			if (implementsInterface(x, i))
				return true;

		return false;
	}
143578
protected function addInterface(string $name, string $class)
    {
        if (!$this->hasInterface($name)) {
            $this->interfaces[$name] = $class;
            return;
        }
        $interfaces = $this->getInterface($name);

        if (!is_array($interfaces)) {
            $interfaces = [$interfaces];
        }

        if (!in_array($class, $interfaces)) {
            $interfaces[] = $class;
            $this->interfaces[$name] = $interfaces;
        }
    }
295570
protected function injectFactoryWhenRequired($className, $Instance)
    {
        if ($this->getDependencyContainer()->isFactoryRequired($className)) {
            if (($Instance instanceof FactoryAwareInterface) === false) {
                throw new MissingFactoryAwareInterfaceException($className);
            }
            /* @var FactoryAwareInterface $Instance */
            $Instance->setFactory($this);
        }
    }
772055
public function load($className) {
        if (class_exists($className, FALSE) || interface_exists($className, FALSE)) {
            return;
        }

        foreach ($this->dirs as $dir) {
            if ($this->loadClass($this->basePath . DIRECTORY_SEPARATOR . $dir, $className)) {
                return;
            }
    	}
    }
625894
final public function hasclass($classname)
    {
        return !!$this->hasattr('class')?in_array($classname, explode(' ', $this->attrs->class)):FALSE;
    }
877232
protected function resolveInterfaceAncestors($interfaceName)
    {
        $ancestors = array($interfaceName);
        $phpFileInfo = $this->getDefinitionFile('interface', $interfaceName);

        if (null !== $phpFileInfo) {
            if ($phpFileInfo->hasInterfaceUsageByClass($interfaceName)) {
                $interfaceUsages = $phpFileInfo->getInterfaceUsageByClass($interfaceName);
                foreach ($interfaceUsages as $interfaceUsage) {
                    $ancestors = array_merge($ancestors, $this->resolveInterfaceAncestors($interfaceUsage->name()));
                }
            }
        }

        return $ancestors;
    }
785161
private function checkMethodExists($className, $methodName)
    {
        if (!$this->isMethodAvailable($className, $methodName)) {
            throw new Exception(Piwik::translate('General_ExceptionMethodNotFound', array($methodName, $className)));
        }
    }