PHPSA\Definition\ClassDefinition::addMethod PHP Метод

addMethod() публичный Метод

public addMethod ( ClassMethod $classMethod, boolean $overwrite = true ) : boolean
$classMethod ClassMethod
$overwrite boolean Should we overwrite method if it already exists
Результат boolean Did we overwrite method?
    public function addMethod(ClassMethod $classMethod, $overwrite = true)
    {
        if ($overwrite) {
            $this->methods[$classMethod->getName()] = $classMethod;
        } else {
            $name = $classMethod->getName();
            if (isset($this->methods[$name])) {
                return false;
            } else {
                $this->methods[$name] = $classMethod;
            }
        }
        return true;
    }

Usage Example

Пример #1
0
 protected function parseTopDefinitions($topStatement, $aliasManager, $filepath, $namespace)
 {
     foreach ($topStatement as $statement) {
         if ($statement instanceof Node\Stmt\Use_) {
             if (!empty($statement->uses)) {
                 foreach ($statement->uses as $use) {
                     $aliasManager->add($use->name->parts);
                 }
             }
         } elseif ($statement instanceof Node\Stmt\Class_) {
             $definition = new ClassDefinition($statement->name, $statement->type);
             $definition->setFilepath($filepath);
             $definition->setNamespace($namespace);
             foreach ($statement->stmts as $stmt) {
                 if ($stmt instanceof Node\Stmt\ClassMethod) {
                     $method = new ClassMethod($stmt->name, $stmt, $stmt->type);
                     $definition->addMethod($method);
                 } elseif ($stmt instanceof Node\Stmt\Property) {
                     $definition->addProperty($stmt);
                 } elseif ($stmt instanceof Node\Stmt\ClassConst) {
                     $definition->addConst($stmt);
                 }
             }
             $this->getCompiler()->addClass($definition);
         } elseif ($statement instanceof Node\Stmt\Function_) {
             $definition = new FunctionDefinition($statement->name, $statement);
             $definition->setFilepath($filepath);
             $definition->setNamespace($namespace);
             $this->getCompiler()->addFunction($definition);
         }
     }
 }
All Usage Examples Of PHPSA\Definition\ClassDefinition::addMethod