1 | <?php |
||
25 | abstract class Directive implements DirectiveInterface |
||
26 | { |
||
27 | /** @var string the name of the key/context */ |
||
28 | private $name; |
||
29 | |||
30 | /** @var string the value of the key/context */ |
||
31 | private $value; |
||
32 | |||
33 | /** |
||
34 | * Base contructor. |
||
35 | * |
||
36 | * @param string $name the name of the key/context to instanciate |
||
37 | * @param string $value the optional value of the key/context to instanciate |
||
38 | */ |
||
39 | 11 | public function __construct($name, $value = '') |
|
40 | { |
||
41 | 11 | $this->name = $name; |
|
42 | 11 | $this->value = $value; |
|
43 | 11 | } |
|
44 | |||
45 | /** |
||
46 | * Gets the key name. |
||
47 | * |
||
48 | * @return string the key name |
||
49 | */ |
||
50 | 3 | public function getName() |
|
51 | { |
||
52 | 3 | return $this->name; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get the key value. |
||
57 | * |
||
58 | * @return string the key value |
||
59 | */ |
||
60 | 6 | public function getValue() |
|
61 | { |
||
62 | 6 | return $this->value; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Adds a Directive at the end of a list. |
||
67 | * |
||
68 | * @param DirectiveInterface $directive a directive to add |
||
69 | */ |
||
70 | 1 | public function add(DirectiveInterface $directive) |
|
71 | { |
||
72 | 1 | return $this; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Confirms if the directive contains a specified directive. |
||
77 | * |
||
78 | * @param string $name the directive for which to check existence |
||
79 | * |
||
80 | * @return bool true if the sub-directive exists, false otherwise |
||
81 | */ |
||
82 | abstract public function hasDirective($name); |
||
83 | |||
84 | /** |
||
85 | * Confirms if the directive is simple. |
||
86 | * |
||
87 | * Simple directive cannot have sub directive |
||
88 | * |
||
89 | * @return bool true if the directive is simple, false otherwise |
||
90 | */ |
||
91 | abstract public function isSimple(); |
||
92 | |||
93 | /** |
||
94 | * Dumps the directive respecting a server syntax. |
||
95 | * |
||
96 | * @param ServerInterface $server a server instance |
||
97 | * @param int $spaces the indentation spaces |
||
98 | * |
||
99 | * @return string the dumped directive |
||
100 | */ |
||
101 | abstract public function dump(ServerInterface $server, $spaces = 0); |
||
102 | |||
103 | /** |
||
104 | * Dumps a simple directive. |
||
105 | * |
||
106 | * @param ServerInterface $server a server instance |
||
107 | * @param int $spaces the indentation spaces |
||
108 | * |
||
109 | * @return string the dumped simple directive |
||
110 | */ |
||
111 | 1 | protected function dumpSimple(ServerInterface $server, $spaces = 0) |
|
121 | } |
||
122 |