1 | <?php declare(strict_types=1); |
||
19 | use phootwork\file\exception\FileNotFoundException; |
||
20 | |||
21 | /** |
||
22 | * Represents a PHP trait. |
||
23 | * |
||
24 | * @author Thomas Gossmann |
||
25 | */ |
||
26 | class PhpTrait extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, PropertiesInterface { |
||
27 | use PropertiesPart; |
||
28 | use TraitsPart; |
||
29 | |||
30 | 1 | /** |
|
31 | 1 | * Creates a PHP trait from a file |
|
32 | 1 | * |
|
33 | 1 | * @param string $filename |
|
34 | 1 | * |
|
35 | 1 | * @throws FileNotFoundException |
|
36 | 1 | * |
|
37 | 1 | * @return PhpTrait |
|
38 | * |
||
39 | 1 | */ |
|
40 | public static function fromFile(string $filename): self { |
||
41 | $trait = new self(); |
||
42 | $parser = new FileParser($filename); |
||
43 | $parser->addVisitor(new TraitParserVisitor($trait)); |
||
44 | $parser->addVisitor(new MethodParserVisitor($trait)); |
||
45 | $parser->addVisitor(new ConstantParserVisitor($trait)); |
||
46 | $parser->addVisitor(new PropertyParserVisitor($trait)); |
||
47 | 7 | $parser->parse(); |
|
48 | 7 | ||
49 | 7 | return $trait; |
|
50 | 7 | } |
|
51 | |||
52 | /** |
||
53 | * Creates a new PHP trait |
||
54 | * |
||
55 | 3 | * @param string $name qualified name |
|
56 | 3 | */ |
|
57 | public function __construct(string $name = '') { |
||
58 | 3 | parent::__construct($name); |
|
59 | 2 | $this->initProperties(); |
|
60 | $this->initTraits(); |
||
61 | 3 | } |
|
62 | |||
63 | /** |
||
71 |