/** * @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; }
/** * Resolve method name conflict with aliasing the method name * * @param string $trait The trait that causing the conflict * @param string $method The method of the trait that causing the conflict * @param string $alias The alias for the method * * @return $this * @throws \Aviogram\Common\PHPClass\Exception\ClassTrait When the trait does not exists * @throws \Aviogram\Common\PHPClass\Exception\ClassTrait When the method is not defined on the trait */ public function resolveConflictAlias($trait, $method, $alias) { $fullClass = $this->classFile->getFullClassName($trait); if (method_exists($fullClass, $method) === false) { throw \Aviogram\Common\PHPClass\Exception\ClassTrait::undefinedMethod($trait, $method); } $this->conflicts[] = "{$trait}::{$method} as {$alias};"; if ($trait !== $this->name && in_array($trait, $this->secondNames) === false) { if ($this->classFile->isTraitDefined($trait) === false) { throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($trait); } $this->secondNames[] = $trait; } return $this; }
/** * Checks if the trait is defined or not * * @param string $trait * * @return boolean */ protected function isTraitDefined($trait) { return $this->classFile->isTraitDefined($trait); }