1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace WsdlToPhp\PhpGenerator\Component; |
6
|
|
|
|
7
|
|
|
use WsdlToPhp\PhpGenerator\Component\PhpClass as PhpClassComponent; |
8
|
|
|
use WsdlToPhp\PhpGenerator\Component\PhpInterface as PhpInterfaceComponent; |
9
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpDeclare; |
10
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpFile as PhpFileElement; |
11
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpFunction as PhpFunctionElement; |
12
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpVariable as PhpVariableElement; |
13
|
|
|
|
14
|
|
|
class PhpFile extends AbstractComponent |
15
|
|
|
{ |
16
|
14 |
|
public function __construct(string $name) |
17
|
|
|
{ |
18
|
14 |
|
$this->setMainElement(new PhpFileElement($name)); |
19
|
14 |
|
} |
20
|
|
|
|
21
|
4 |
|
public function addClassComponent(PhpClassComponent $class): self |
22
|
|
|
{ |
23
|
4 |
|
$this->mainElement->addChild($class->toString()); |
24
|
|
|
|
25
|
4 |
|
return $this; |
26
|
|
|
} |
27
|
|
|
|
28
|
2 |
|
public function addInterfaceComponent(PhpInterfaceComponent $interface): self |
29
|
|
|
{ |
30
|
2 |
|
$this->mainElement->addChild($interface->toString()); |
31
|
|
|
|
32
|
2 |
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
public function addVariableElement(PhpVariableElement $variable): self |
36
|
|
|
{ |
37
|
2 |
|
$this->mainElement->addChild($variable); |
38
|
|
|
|
39
|
2 |
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
2 |
|
public function addVariable(string $name, $value = null): self |
43
|
|
|
{ |
44
|
2 |
|
return $this->addVariableElement(new PhpVariableElement($name, $value)); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
public function addFunctionElement(PhpFunctionElement $function): self |
48
|
|
|
{ |
49
|
2 |
|
$this->mainElement->addChild($function); |
50
|
|
|
|
51
|
2 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
public function addFunction(string $name, array $parameters = []): self |
55
|
|
|
{ |
56
|
2 |
|
return $this->addFunctionElement(new PhpFunctionElement($name, $parameters)); |
57
|
|
|
} |
58
|
|
|
|
59
|
6 |
|
public function addUse(string $use, string $as = null, bool $last = false): self |
60
|
|
|
{ |
61
|
6 |
|
$expression = empty($as) ? 'use %1$s;%3$s' : 'use %1$s as %2$s;%3$s'; |
62
|
6 |
|
$this->mainElement->addChild(sprintf($expression, $use, $as, $last ? self::BREAK_LINE_CHAR : '')); |
63
|
|
|
|
64
|
6 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
6 |
|
public function setDeclareElement(PhpDeclare $phpDeclare): self |
68
|
|
|
{ |
69
|
6 |
|
$this->mainElement->addChild(sprintf('%s%s', self::BREAK_LINE_CHAR, $phpDeclare->toString())); |
70
|
|
|
|
71
|
6 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
public function setDeclare(string $name, $value): self |
75
|
|
|
{ |
76
|
2 |
|
return $this->setDeclareElement(new PhpDeclare($name, $value)); |
77
|
|
|
} |
78
|
|
|
|
79
|
6 |
|
public function setNamespace(string $namespace): self |
80
|
|
|
{ |
81
|
6 |
|
$this->mainElement->addChild( |
82
|
6 |
|
sprintf( |
83
|
6 |
|
'%snamespace %s;%s', |
84
|
6 |
|
self::BREAK_LINE_CHAR, |
85
|
|
|
$namespace, |
86
|
6 |
|
self::BREAK_LINE_CHAR |
87
|
|
|
) |
88
|
|
|
); |
89
|
|
|
|
90
|
6 |
|
return $this; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|