/**
* Can the advised interfaces be implemented by the introduction advice?
*
* Invoked before adding an IntroductionAdvisor.
*
* @return void
* @throws \InvalidArgumentException if the advised interfaces can't be implemented by the introduction advice
*/
public function validateInterfaces()
{
$refInterface = new ReflectionClass(reset($this->advice->getInterfaces()));
$refImplementation = new ReflectionClass(reset($this->advice->getTraits()));
if (!$refInterface->isInterface()) {
throw new \InvalidArgumentException("Only interface can be introduced");
}
if (!$refImplementation->isTrait()) {
throw new \InvalidArgumentException("Only trait can be used as implementation");
}
foreach ($refInterface->getMethods() as $interfaceMethod) {
if (!$refImplementation->hasMethod($interfaceMethod->name)) {
throw new \DomainException("Implementation requires method {$interfaceMethod->name}");
}
}
}