/** * Resolve method name conflict with ignoring one trait over the other * * @param string $trait The trait that will be used * @param string $method The method of the trait which causes the conflict * @param string $insteadOfTrait The trait which will be ignored * * @return $this * @throws \Aviogram\Common\PHPClass\Exception\ClassTrait When the base trait is not used * @throws \Aviogram\Common\PHPClass\Exception\ClassTrait When the method does not exists */ public function resolveConflictInsteadOf($trait, $method, $insteadOfTrait) { $fullClass = $this->classFile->getFullClassName($trait); if (method_exists($fullClass, $method) === false) { throw \Aviogram\Common\PHPClass\Exception\ClassTrait::undefinedMethod($trait, $method); } if ($trait !== $this->name && $insteadOfTrait !== $this->name) { throw \Aviogram\Common\PHPClass\Exception\ClassTrait::knownTraitNotUsedByResolveInsteadOf($this->name); } else { if ($trait !== $this->name && in_array($trait, $this->secondNames) === false) { if ($this->classFile->isClassDefined($trait) === false) { throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($trait); } $this->secondNames[] = $trait; } else { if ($insteadOfTrait !== $this->name && in_array($insteadOfTrait, $this->secondNames) === false) { if ($this->classFile->isClassDefined($insteadOfTrait) === false) { throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($insteadOfTrait); } $this->secondNames[] = $insteadOfTrait; } } } $this->conflicts[] = "{$trait}::{$method} insteadOf {$insteadOfTrait};"; return $this; }
/** * @param string $class * @param null|string $alias * @param bool $checkClassExists Use FALSE when you want to use a namespace instead of a class * * @return $this * @throws Exception\ClassUse When the given class does not exists */ public function addUse($class, $alias = null, $checkClassExists = true) { if ($checkClassExists === true && $this->classFile->isClassDefined("\\{$class}") === false && $this->classFile->isInterfaceDefined("\\{$class}") === false && $this->classFile->isTraitDefined("\\{$class}") === false) { throw Exception\ClassUse::classUseNotFound($class); } $use = new ClassUse($class, $alias); $this->append($use); return $this; }
/** * Checks if the class is defined or not * * @param string $class * * @return boolean */ protected function isClassDefined($class) { return $this->classFile->isClassDefined($class); }