FeaturePhp/Collaboration/ClassComposer.php
public function refine($role) {
        $fileSource = $role->getFileSpecification()->getSource();
        $parser = (new fphp\Helper\PhpParser())->parseFile($fileSource);
        $ast = $parser->getAst();
        $class = $parser->getExactlyOneClass($fileSource);

        if (!$this->targetClass) { // not refining, but defining the target class
            $this->targetClass = $class->name;
            $this->mangleClassName($class, $role);
        } else { // refining
            if ($class->name !== $this->targetClass)
                throw new ClassComposerException("\"$fileSource\" refines \"$class->name\" (expected \"$this->targetClass\")");
            if ($class->extends)
                throw new ClassComposerException("refining role at \"$fileSource\" may not extend a class");
            
            $this->mangleClassName($class, $role);
            $this->extendClass($class);
        }
        
        return new ClassComposer($this->targetClass, $class->name, array_merge($this->ast, $ast));
    }
public function refine($role) {
        $fileSource = $role->getFileSpecification()->getSource();
        $parser = (new fphp\Helper\PhpParser())->parseFile($fileSource);
        $ast = $parser->getAst();
        $class = $parser->getExactlyOneClass($fileSource);

        if (!$this->targetClass) { // not refining, but defining the target class
            $this->targetClass = $class->name;
            $this->mangleClassName($class, $role);
        } else { // refining
            if ($class->name !== $this->targetClass)
                throw new ClassComposerException("\"$fileSource\" refines \"$class->name\" (expected \"$this->targetClass\")");
            if ($class->extends)
                throw new ClassComposerException("refining role at \"$fileSource\" may not extend a class");
            
            $this->mangleClassName($class, $role);
            $this->extendClass($class);
        }
        
        return new ClassComposer($this->targetClass, $class->name, array_merge($this->ast, $ast));
    }
public function refine ( $ role ) { $ fileSource = $ role -> getFileSpecification ( ) -> getSource ( ) ; $ parser = ( new fphp \ Helper \ PhpParser ( ) ) -> parseFile ( $ fileSource ) ; $ ast = $ parser -> getAst ( ) ; $ class = $ parser -> getExactlyOneClass ( $ fileSource ) ; if ( ! $ this -> targetClass ) { // not refining, but defining the target class $ this -> targetClass = $ class -> name ; $ this -> mangleClassName ( $ class , $ role ) ; } else { // refining if ( $ class -> name !== $ this -> targetClass ) throw new ClassComposerException ( "\"$fileSource\" refines \"$class->name\" (expected \"$this->targetClass\")" ) ; if ( $ class -> extends ) throw new ClassComposerException ( "refining role at \"$fileSource\" may not extend a class" ) ; $ this -> mangleClassName ( $ class , $ role ) ; $ this -> extendClass ( $ class ) ; } return new ClassComposer ( $ this -> targetClass , $ class -> name , array_merge ( $ this -> ast , $ ast ) ) ; }
Returns a new class composer containing a role's refinements.
@param Role $role
@return ClassComposer
Returns a new class composer containing a role s refinements .