1
|
|
|
<?php |
2
|
|
|
namespace gossi\codegen\model; |
3
|
|
|
|
4
|
|
|
use gossi\codegen\model\parts\ConstantsPart; |
5
|
|
|
use gossi\codegen\model\parts\InterfacesPart; |
6
|
|
|
use gossi\codegen\parser\FileParser; |
7
|
|
|
use gossi\codegen\parser\visitor\ConstantParserVisitor; |
8
|
|
|
use gossi\codegen\parser\visitor\InterfaceParserVisitor; |
9
|
|
|
use gossi\codegen\parser\visitor\MethodParserVisitor; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Represents a PHP interface. |
13
|
|
|
* |
14
|
|
|
* @author Thomas Gossmann |
15
|
|
|
*/ |
16
|
|
|
class PhpInterface extends AbstractPhpStruct implements GenerateableInterface, ConstantsInterface { |
17
|
|
|
|
18
|
|
|
use ConstantsPart; |
19
|
|
|
use InterfacesPart; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Creates a PHP interface from reflection |
23
|
|
|
* |
24
|
|
|
* @deprecated Use fromFile() instead |
25
|
|
|
* @param \ReflectionClass $ref |
26
|
|
|
* @return PhpInterface |
27
|
|
|
*/ |
28
|
|
|
public static function fromReflection(\ReflectionClass $ref) { |
29
|
|
|
return static::fromFile($ref->getFileName()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Creates a PHP interface from file |
34
|
|
|
* |
35
|
|
|
* @param string $filename |
36
|
|
|
* @return PhpInterface |
37
|
|
|
*/ |
38
|
3 |
|
public static function fromFile($filename) { |
39
|
3 |
|
$interface = new PhpInterface(); |
40
|
3 |
|
$parser = new FileParser($filename); |
41
|
3 |
|
$parser->addVisitor(new InterfaceParserVisitor($interface)); |
42
|
3 |
|
$parser->addVisitor(new MethodParserVisitor($interface)); |
43
|
3 |
|
$parser->addVisitor(new ConstantParserVisitor($interface)); |
44
|
3 |
|
$parser->parse(); |
45
|
|
|
|
46
|
3 |
|
return $interface; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create a new PHP interface |
51
|
|
|
* |
52
|
|
|
* @param string $name qualified name |
53
|
|
|
*/ |
54
|
10 |
|
public function __construct($name = null) { |
55
|
10 |
|
parent::__construct($name); |
56
|
10 |
|
$this->initConstants(); |
57
|
10 |
|
$this->initInterfaces(); |
58
|
10 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritDoc |
62
|
|
|
*/ |
63
|
4 |
|
public function generateDocblock() { |
64
|
4 |
|
parent::generateDocblock(); |
65
|
|
|
|
66
|
4 |
|
foreach ($this->constants as $constant) { |
67
|
1 |
|
$constant->generateDocblock(); |
68
|
4 |
|
} |
69
|
4 |
|
} |
70
|
|
|
} |
71
|
|
|
|