1 | <?php |
||
40 | abstract class GameServer extends AbstractServer |
||
41 | { |
||
42 | /** |
||
43 | * @var integer $id |
||
44 | * |
||
45 | * @ORM\Column(name="id", type="integer") |
||
46 | * @ORM\Id |
||
47 | * @ORM\GeneratedValue(strategy="AUTO") |
||
48 | */ |
||
49 | protected $id; |
||
50 | |||
51 | /** |
||
52 | * @var string $name |
||
53 | * |
||
54 | * @ORM\Column(name="name", type="string", length=32) |
||
55 | */ |
||
56 | protected $name; |
||
57 | |||
58 | /** |
||
59 | * @var integer $port |
||
60 | * |
||
61 | * @ORM\Column(name="port", type="integer") |
||
62 | */ |
||
63 | protected $port; |
||
64 | |||
65 | /** |
||
66 | * @var integer $maxplayers |
||
67 | * |
||
68 | * @ORM\Column(name="maxplayers", type="integer") |
||
69 | */ |
||
70 | protected $maxplayers; |
||
71 | |||
72 | /** |
||
73 | * @ORM\ManyToOne(targetEntity="DP\Core\MachineBundle\Entity\Machine", inversedBy="gameServers") |
||
74 | * @ORM\JoinColumn(name="machineId", referencedColumnName="id") |
||
75 | */ |
||
76 | protected $machine; |
||
77 | |||
78 | /** |
||
79 | * @ORM\ManyToOne(targetEntity="DP\Core\GameBundle\Entity\Game", inversedBy="gameServers") |
||
80 | * @ORM\JoinColumn(name="gameId", referencedColumnName="id") |
||
81 | */ |
||
82 | protected $game; |
||
83 | |||
84 | /** |
||
85 | * @var string $rcon |
||
86 | * |
||
87 | * @ORM\Column(name="rconPassword", type="string", length=32) |
||
88 | */ |
||
89 | protected $rconPassword; |
||
90 | |||
91 | protected $query; |
||
92 | protected $rcon; |
||
93 | |||
94 | /** |
||
95 | * @var \Doctrine\Common\Collections\ArrayCollection $plugins |
||
96 | * |
||
97 | * @ORM\ManyToMany(targetEntity="DP\Core\GameBundle\Entity\Plugin") |
||
98 | * @ORM\JoinTable(name="gameserver_plugins", |
||
99 | * joinColumns={@ORM\JoinColumn(name="server_id", referencedColumnName="id")}, |
||
100 | * inverseJoinColumns={@ORM\JoinColumn(name="plugin_id", referencedColumnName="id")} |
||
101 | * ) |
||
102 | */ |
||
103 | private $plugins; |
||
104 | |||
105 | |||
106 | public function __construct() |
||
110 | |||
111 | /** |
||
112 | * Get id |
||
113 | * |
||
114 | * @return integer |
||
115 | */ |
||
116 | public function getId() |
||
120 | |||
121 | /** |
||
122 | * Set machine |
||
123 | * |
||
124 | * @param Machine $machine |
||
125 | */ |
||
126 | public function setMachine(Machine $machine) |
||
130 | |||
131 | /** |
||
132 | * Get machine |
||
133 | * |
||
134 | * @return Machine |
||
135 | */ |
||
136 | public function getMachine() |
||
140 | |||
141 | /** |
||
142 | * Set name |
||
143 | * |
||
144 | * @param string $name |
||
145 | */ |
||
146 | public function setName($name) |
||
150 | |||
151 | /** |
||
152 | * Get name |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | public function getName() |
||
160 | |||
161 | /** |
||
162 | * Set port |
||
163 | * |
||
164 | * @param integer $port |
||
165 | */ |
||
166 | public function setPort($port) |
||
170 | |||
171 | /** |
||
172 | * Get port |
||
173 | * |
||
174 | * @return integer |
||
175 | */ |
||
176 | public function getPort() |
||
180 | |||
181 | /** |
||
182 | * Set game |
||
183 | * |
||
184 | * @param Game $game |
||
185 | */ |
||
186 | public function setGame($game) |
||
190 | |||
191 | /** |
||
192 | * Get gameId |
||
193 | * |
||
194 | * @return integer |
||
195 | */ |
||
196 | public function getGame() |
||
200 | |||
201 | /** |
||
202 | * Set maxplayers |
||
203 | * |
||
204 | * @param integer $maxplayers |
||
205 | */ |
||
206 | public function setMaxplayers($maxplayers) |
||
210 | |||
211 | /** |
||
212 | * Get maxplayers |
||
213 | * |
||
214 | * @return integer |
||
215 | */ |
||
216 | public function getMaxplayers() |
||
220 | |||
221 | /** |
||
222 | * Get absolute path of binaries directory |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | public function getAbsoluteBinDir() |
||
230 | |||
231 | /** |
||
232 | * Get absolute path of game content directory |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | public function getAbsoluteGameContentDir() |
||
240 | |||
241 | public function getScreenName() |
||
247 | |||
248 | public function getInstallScreenName() |
||
254 | |||
255 | public function getPluginInstallScreenName($scriptName = '') |
||
261 | |||
262 | public function getScreenNameHash($screenName, $hashLength = 20) |
||
269 | |||
270 | public function setQuery(QueryInterface $query) |
||
274 | |||
275 | public function getQuery() |
||
279 | |||
280 | /** |
||
281 | * Set rconPassword |
||
282 | * |
||
283 | * @param string $rconPassword |
||
284 | */ |
||
285 | public function setRconPassword($rconPassword) |
||
289 | |||
290 | /** |
||
291 | * Get rconPassword |
||
292 | * |
||
293 | * @return string |
||
294 | */ |
||
295 | public function getRconPassword() |
||
299 | |||
300 | public function isEmptyRconPassword() |
||
304 | |||
305 | public function setRcon(RconInterface $rcon) |
||
311 | |||
312 | public function getRcon() |
||
316 | |||
317 | /** |
||
318 | * Add plugin |
||
319 | * |
||
320 | * @param \DP\Core\GameBundle\Entity\Plugin $plugin |
||
321 | */ |
||
322 | public function addPlugin(\DP\Core\GameBundle\Entity\Plugin $plugin) |
||
326 | |||
327 | /** |
||
328 | * Remove a server plugin |
||
329 | * @param \DP\Core\GameBundle\Entity\Plugin $plugin |
||
330 | */ |
||
331 | public function removePlugin(\DP\Core\GameBundle\Entity\Plugin $plugin) |
||
335 | |||
336 | /** |
||
337 | * Get plugins recorded as "installed on the server" |
||
338 | * |
||
339 | * @return \Doctrine\Common\Collections\ArrayCollection |
||
340 | */ |
||
341 | public function getPlugins() |
||
350 | |||
351 | public function getInstalledPlugins() |
||
355 | |||
356 | public function getNotInstalledPlugins() |
||
367 | |||
368 | public function getServerLogs() |
||
377 | |||
378 | public function getInstallLogs() |
||
387 | |||
388 | public function finalizeInstallation(\Twig_Environment $twig) |
||
398 | |||
399 | /** |
||
400 | * @todo: refacto domain logic |
||
401 | */ |
||
402 | public function installPlugin(\Twig_Environment $twig, Plugin $plugin) |
||
406 | |||
407 | public function uninstallPlugin(\Twig_Environment $twig, Plugin $plugin) |
||
411 | |||
412 | abstract public function uploadShellScripts(\Twig_Environment $twig); |
||
413 | |||
414 | abstract public function uploadDefaultServerConfigurationFile(); |
||
415 | |||
416 | abstract public function removeInstallationFiles(); |
||
417 | |||
418 | abstract public function regenerateScripts(\Twig_Environment $twig); |
||
419 | |||
420 | public static function loadValidatorMetadata(ClassMetadata $metadata) |
||
434 | } |
||
435 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.