These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of Dedipanel project |
||
5 | * |
||
6 | * (c) 2010-2015 Dedipanel <http://www.dedicated-panel.net> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace DP\Core\GameBundle\Entity; |
||
13 | |||
14 | use Doctrine\ORM\Mapping as ORM; |
||
15 | use Symfony\Component\Validator\Constraints as Assert; |
||
16 | use Symfony\Component\Validator\Context\ExecutionContextInterface; |
||
17 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
||
18 | |||
19 | /** |
||
20 | * DP\Core\GameBundle\Entity\Game |
||
21 | * @author Albin Kerouanton |
||
22 | * |
||
23 | * @ORM\Table(name="game") |
||
24 | * @ORM\Entity(repositoryClass="DP\Core\GameBundle\Entity\GameRepository") |
||
25 | * @Assert\Callback(methods={"validateAppId"}) |
||
26 | * @UniqueEntity(fields="name", message="game.assert.name.unique") |
||
27 | * @UniqueEntity(fields={"appId","appMod"}, message="game.assert.unique_id_mod") |
||
28 | */ |
||
29 | class Game |
||
30 | { |
||
31 | /** |
||
32 | * @var integer $id |
||
33 | * |
||
34 | * @ORM\Column(name="id", type="integer") |
||
35 | * @ORM\Id |
||
36 | * @ORM\GeneratedValue(strategy="AUTO") |
||
37 | */ |
||
38 | private $id; |
||
39 | |||
40 | /** |
||
41 | * @var string $name |
||
42 | * |
||
43 | * @ORM\Column(name="name", type="string", length=32) |
||
44 | * @Assert\NotBlank(message="game.assert.name.needed") |
||
45 | */ |
||
46 | private $name = ''; |
||
47 | |||
48 | /** |
||
49 | * @var string $installName |
||
50 | * |
||
51 | * @ORM\Column(name="installName", type="string", length=24) |
||
52 | * @Assert\NotBlank(message="game.assert.installName") |
||
53 | */ |
||
54 | private $installName; |
||
55 | |||
56 | /** |
||
57 | * @var boolean $steamCmd |
||
58 | * |
||
59 | * @ORM\Column(name="steamCmd", type="boolean") |
||
60 | */ |
||
61 | private $steamCmd = false; // default value |
||
62 | |||
63 | /** |
||
64 | * @var string $launchName |
||
65 | * |
||
66 | * @ORM\Column(name="launchName", type="string", length=24) |
||
67 | * @Assert\NotBlank(message="game.assert.launchName") |
||
68 | */ |
||
69 | private $launchName; |
||
70 | |||
71 | /** |
||
72 | * @var string $bin |
||
73 | * |
||
74 | * @ORM\Column(name="bin", type="string", length=24) |
||
75 | * @Assert\NotBlank(message="game.assert.bin") |
||
76 | */ |
||
77 | private $bin; |
||
78 | |||
79 | /** |
||
80 | * @var integer $appId |
||
81 | * |
||
82 | * @ORM\Column(name="appId", type="integer", nullable=true) |
||
83 | */ |
||
84 | protected $appId; |
||
85 | |||
86 | /** |
||
87 | * @var integer $appMod |
||
88 | * |
||
89 | * @ORM\Column(name="appMod", type="string", length=20, nullable=true) |
||
90 | */ |
||
91 | protected $appMod; |
||
92 | |||
93 | |||
94 | /** |
||
95 | * @var boolean $orangebox |
||
96 | * |
||
97 | * @ORM\Column(name="orangebox", type="boolean") |
||
98 | */ |
||
99 | private $orangebox = false; // default value |
||
100 | |||
101 | /** |
||
102 | * @var boolean $source |
||
103 | * |
||
104 | * @ORM\Column(name="source", type="boolean") |
||
105 | */ |
||
106 | private $source = false; // default value, useful for source tv |
||
107 | |||
108 | /** |
||
109 | * @var string $map |
||
110 | * |
||
111 | * @ORM\Column(name="map", type="string", length=40, nullable=true) |
||
112 | */ |
||
113 | private $map; |
||
114 | |||
115 | /** |
||
116 | * @var boolean $available |
||
117 | * |
||
118 | * @ORM\Column(name="available", type="boolean") |
||
119 | * @Assert\NotNull(message="game.assert.available") |
||
120 | */ |
||
121 | private $available = true; |
||
122 | |||
123 | /** |
||
124 | * @var string $binDir |
||
125 | * |
||
126 | * @ORM\Column(name="binDir", type="string", length=20, nullable=true) |
||
127 | */ |
||
128 | private $binDir; |
||
129 | |||
130 | /** |
||
131 | * @ORM\Column(name="sourceImagesMaps", type="string", length=255, nullable=true) |
||
132 | * @var string |
||
133 | */ |
||
134 | private $sourceImagesMaps; |
||
135 | |||
136 | /** |
||
137 | * @var \Doctrine\Common\Collections\ArrayCollection $gameServers |
||
138 | * |
||
139 | * @ORM\OneToMany(targetEntity="DP\GameServer\GameServerBundle\Entity\GameServer", mappedBy="game") |
||
140 | */ |
||
141 | private $gameServers; |
||
142 | |||
143 | /** |
||
144 | * @var \Doctrine\Common\Collections\ArrayCollection $plugins |
||
145 | * |
||
146 | * @ORM\ManyToMany(targetEntity="DP\Core\GameBundle\Entity\Plugin", inversedBy="games") |
||
147 | * @ORM\JoinTable(name="game_plugin", |
||
148 | * joinColumns={@ORM\JoinColumn(name="game_id", referencedColumnName="id")}, |
||
149 | * inverseJoinColumns={@ORM\JoinColumn(name="plugin_id", referencedColumnName="id")} |
||
150 | * ) |
||
151 | */ |
||
152 | private $plugins; |
||
153 | |||
154 | /** |
||
155 | * @ORM\Column(name="type", type="string", length=32) |
||
156 | * @Assert\Choice(choices={"steam", "minecraft"}, message="game.assert.type") |
||
157 | */ |
||
158 | private $type; |
||
159 | |||
160 | /** |
||
161 | * @ORM\Column(name="configTemplate", type="text", nullable=true) |
||
162 | */ |
||
163 | private $configTemplate; |
||
164 | |||
165 | |||
166 | public function __construct() |
||
167 | { |
||
168 | $this->plugins = new \Doctrine\Common\Collections\ArrayCollection(array()); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Get id |
||
173 | * |
||
174 | * @return integer |
||
175 | */ |
||
176 | public function getId() |
||
177 | { |
||
178 | return $this->id; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Set name |
||
183 | * |
||
184 | * @param string $name |
||
185 | */ |
||
186 | public function setName($name) |
||
187 | { |
||
188 | $this->name = $name; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * Get name |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getName() |
||
197 | { |
||
198 | return $this->name; |
||
199 | } |
||
200 | |||
201 | /** |
||
202 | * Set installName |
||
203 | * |
||
204 | * @param string $installName |
||
205 | */ |
||
206 | public function setInstallName($installName) |
||
207 | { |
||
208 | $this->installName = $installName; |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * Get installName |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | public function getInstallName() |
||
217 | { |
||
218 | return $this->installName; |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * Set launchName |
||
223 | * |
||
224 | * @param string $launchName |
||
225 | */ |
||
226 | public function setLaunchName($launchName) |
||
227 | { |
||
228 | $this->launchName = $launchName; |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * Get launchName |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | public function getLaunchName() |
||
237 | { |
||
238 | return $this->launchName; |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * Set bin |
||
243 | * |
||
244 | * @param string $bin |
||
245 | */ |
||
246 | public function setBin($bin) |
||
247 | { |
||
248 | $this->bin = $bin; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * Get bin |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | public function getBin() |
||
257 | { |
||
258 | return $this->bin; |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Set orangebox |
||
263 | * |
||
264 | * @param boolean $orangebox |
||
265 | */ |
||
266 | public function setOrangebox($orangebox) |
||
267 | { |
||
268 | $this->orangebox = $orangebox; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * Get orangebox |
||
273 | * |
||
274 | * @return boolean |
||
275 | */ |
||
276 | public function isOrangebox() |
||
277 | { |
||
278 | return $this->orangebox; |
||
279 | } |
||
280 | |||
281 | /** |
||
282 | * Set source |
||
283 | * |
||
284 | * @param boolean $source |
||
285 | */ |
||
286 | public function setSource($source) |
||
287 | { |
||
288 | $this->source = $source; |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * Get source |
||
293 | * |
||
294 | * @return boolean |
||
295 | */ |
||
296 | public function isSource() |
||
297 | { |
||
298 | return $this->source; |
||
299 | } |
||
300 | |||
301 | /** |
||
302 | * Set map |
||
303 | * |
||
304 | * @param string $map |
||
305 | */ |
||
306 | public function setMap($map) |
||
307 | { |
||
308 | $this->map = $map; |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * Get map |
||
313 | * |
||
314 | * @return string |
||
315 | */ |
||
316 | public function getMap() |
||
317 | { |
||
318 | return $this->map; |
||
319 | } |
||
320 | |||
321 | /** |
||
322 | * Set available |
||
323 | * |
||
324 | * @param boolean $available |
||
325 | */ |
||
326 | public function setAvailable($available) |
||
327 | { |
||
328 | $this->available = $available; |
||
329 | } |
||
330 | |||
331 | /** |
||
332 | * Get available |
||
333 | * |
||
334 | * @return boolean |
||
335 | */ |
||
336 | public function getAvailable() |
||
337 | { |
||
338 | return $this->available; |
||
339 | } |
||
340 | |||
341 | public function __toString() |
||
342 | { |
||
343 | return $this->name; |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * Set binary directory |
||
348 | * |
||
349 | * @param string $binDir |
||
350 | */ |
||
351 | public function setBinDir($binDir) |
||
352 | { |
||
353 | $this->binDir = $binDir; |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * Get binary directory |
||
358 | * |
||
359 | * @return string |
||
360 | */ |
||
361 | public function getBinDir() |
||
362 | { |
||
363 | if ($this->isOrangebox()) { |
||
364 | return 'orangebox/'; |
||
365 | } |
||
366 | elseif (empty($this->binDir)) { |
||
367 | return ''; |
||
368 | } |
||
369 | else { |
||
370 | return $this->binDir; |
||
371 | } |
||
372 | } |
||
373 | |||
374 | /** |
||
375 | * Set source of images maps |
||
376 | * |
||
377 | * @param string $sourceImagesMaps |
||
378 | */ |
||
379 | public function setSourceImagesMaps($sourceImagesMaps) |
||
380 | { |
||
381 | $this->sourceImagesMaps = $sourceImagesMaps; |
||
382 | } |
||
383 | |||
384 | /** |
||
385 | * Get source of images maps |
||
386 | * |
||
387 | * @return string |
||
388 | */ |
||
389 | public function getSourceImagesMaps() |
||
390 | { |
||
391 | return $this->sourceImagesMaps; |
||
392 | } |
||
393 | |||
394 | /** |
||
395 | * Add plugins |
||
396 | * |
||
397 | * @param $plugin \Doctrine\Common\Collections\ArrayCollection |
||
398 | */ |
||
399 | public function addPlugin(\DP\Core\GameBundle\Entity\Plugin $plugin) |
||
400 | { |
||
401 | $this->plugins[] = $plugin; |
||
402 | |||
403 | if (!$plugin->getGames()->contains($this)) { |
||
404 | $plugin->addGame($this); |
||
405 | } |
||
406 | } |
||
407 | |||
408 | public function removePlugin(Plugin $plugin) |
||
409 | { |
||
410 | $this->plugins->removeElement($plugin); |
||
411 | } |
||
412 | |||
413 | /** |
||
414 | * Set plugin list |
||
415 | * |
||
416 | * @param array $plugins |
||
417 | */ |
||
418 | public function setPlugins(array $plugins = array()) |
||
419 | { |
||
420 | $this->plugins = new \Doctrine\Common\Collections\ArrayCollection($plugins); |
||
421 | } |
||
422 | |||
423 | /** |
||
424 | * Get plugins |
||
425 | * |
||
426 | * @return \Doctrine\Common\Collections\ArrayCollection |
||
427 | */ |
||
428 | public function getPlugins() |
||
429 | { |
||
430 | return $this->plugins; |
||
431 | } |
||
432 | |||
433 | /** |
||
434 | * Set game type (steam or minecraft) |
||
435 | * |
||
436 | * @param string $type |
||
437 | */ |
||
438 | public function setType($type) |
||
439 | { |
||
440 | $this->type = $type; |
||
441 | } |
||
442 | |||
443 | /** |
||
444 | * @return string Game type |
||
445 | */ |
||
446 | public function getType() |
||
447 | { |
||
448 | return $this->type; |
||
449 | } |
||
450 | |||
451 | public function isBukkit() |
||
452 | { |
||
453 | return $this->getInstallName() == 'bukkit'; |
||
454 | } |
||
455 | |||
456 | /** |
||
457 | * Set the server config file template |
||
458 | * @param string|null $configTemplate |
||
459 | */ |
||
460 | public function setConfigTemplate($configTemplate) |
||
461 | { |
||
462 | $this->configTemplate = $configTemplate; |
||
463 | } |
||
464 | |||
465 | /** |
||
466 | * Get the server config file template |
||
467 | * |
||
468 | * @return string |
||
469 | */ |
||
470 | public function getConfigTemplate() |
||
471 | { |
||
472 | return $this->configTemplate; |
||
473 | } |
||
474 | |||
475 | /** |
||
476 | * Set steamCmd |
||
477 | * |
||
478 | * @param boolean $steamCmd |
||
479 | * @return Game |
||
480 | */ |
||
481 | public function setSteamCmd($steamCmd) |
||
482 | { |
||
483 | $this->steamCmd = $steamCmd; |
||
484 | |||
485 | return $this; |
||
486 | } |
||
487 | |||
488 | /** |
||
489 | * Get steamCmd |
||
490 | * |
||
491 | * @return boolean |
||
492 | */ |
||
493 | public function getSteamCmd() |
||
494 | { |
||
495 | return $this->steamCmd; |
||
496 | } |
||
497 | |||
498 | /** |
||
499 | * Set appId |
||
500 | * |
||
501 | * @param integer $appId |
||
502 | * @return Game |
||
503 | */ |
||
504 | public function setAppId($appId) |
||
505 | { |
||
506 | $this->appId = $appId; |
||
507 | |||
508 | return $this; |
||
509 | } |
||
510 | |||
511 | /** |
||
512 | * Get appId |
||
513 | * |
||
514 | * @return integer |
||
515 | */ |
||
516 | public function getAppId() |
||
517 | { |
||
518 | return $this->appId; |
||
519 | } |
||
520 | |||
521 | /** |
||
522 | * Set appMod |
||
523 | * |
||
524 | * @param string $appMod |
||
525 | * @return Game |
||
526 | */ |
||
527 | public function setAppMod($appMod) |
||
528 | { |
||
529 | $this->appMod = $appMod; |
||
0 ignored issues
–
show
|
|||
530 | |||
531 | return $this; |
||
532 | } |
||
533 | |||
534 | /** |
||
535 | * Get appMod |
||
536 | * |
||
537 | * @return integer |
||
538 | */ |
||
539 | public function getAppMod() |
||
540 | { |
||
541 | return $this->appMod; |
||
542 | } |
||
543 | |||
544 | /** |
||
545 | * Get orangebox |
||
546 | * |
||
547 | * @return boolean |
||
548 | */ |
||
549 | public function getOrangebox() |
||
550 | { |
||
551 | return $this->orangebox; |
||
552 | } |
||
553 | |||
554 | /** |
||
555 | * Get source |
||
556 | * |
||
557 | * @return boolean |
||
558 | */ |
||
559 | public function getSource() |
||
560 | { |
||
561 | return $this->source; |
||
562 | } |
||
563 | |||
564 | /** |
||
565 | * Add gameServers |
||
566 | * |
||
567 | * @param \DP\GameServer\GameServerBundle\Entity\GameServer $gameServers |
||
568 | * @return Game |
||
569 | */ |
||
570 | public function addGameServer(\DP\GameServer\GameServerBundle\Entity\GameServer $gameServers) |
||
571 | { |
||
572 | $this->gameServers[] = $gameServers; |
||
573 | |||
574 | return $this; |
||
575 | } |
||
576 | |||
577 | /** |
||
578 | * Remove gameServers |
||
579 | * |
||
580 | * @param \DP\GameServer\GameServerBundle\Entity\GameServer $gameServers |
||
581 | */ |
||
582 | public function removeGameServer(\DP\GameServer\GameServerBundle\Entity\GameServer $gameServers) |
||
583 | { |
||
584 | $this->gameServers->removeElement($gameServers); |
||
585 | } |
||
586 | |||
587 | /** |
||
588 | * Get gameServers |
||
589 | * |
||
590 | * @return \Doctrine\Common\Collections\Collection |
||
591 | */ |
||
592 | public function getGameServers() |
||
593 | { |
||
594 | return $this->gameServers; |
||
595 | } |
||
596 | |||
597 | public function validateAppId(ExecutionContextInterface $context) |
||
598 | { |
||
599 | $appId = $this->getAppId(); |
||
600 | |||
601 | if (true === $this->getSteamCmd() && empty($appId)) { |
||
602 | $context->buildViolation('game.assert.appId.needed') |
||
603 | ->atPath('appId') |
||
604 | ->addViolation(); |
||
605 | } |
||
606 | elseif (false === $this->getSteamCmd() && !empty($appId)) { |
||
607 | $context->buildViolation('game.assert.appId.not_needed') |
||
608 | ->atPath('appId') |
||
609 | ->addViolation(); |
||
610 | } |
||
611 | } |
||
612 | } |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.