|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Technology Queue Manager |
|
4
|
|
|
* |
|
5
|
|
|
* @author Jacky Casas |
|
6
|
|
|
* @copyright Expansion - le jeu |
|
7
|
|
|
* |
|
8
|
|
|
* @package Prométhée |
|
9
|
|
|
* @update 10.02.14 |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace Asylamba\Modules\Promethee\Manager; |
|
12
|
|
|
|
|
13
|
|
|
use Asylamba\Classes\Entity\EntityManager; |
|
14
|
|
|
use Asylamba\Modules\Promethee\Model\TechnologyQueue; |
|
15
|
|
|
use Asylamba\Classes\Scheduler\RealTimeActionScheduler; |
|
16
|
|
|
|
|
17
|
|
|
class TechnologyQueueManager |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var EntityManager **/ |
|
20
|
|
|
protected $entityManager; |
|
21
|
|
|
/** @var RealTimeActionScheduler **/ |
|
22
|
|
|
protected $realtimeActionScheduler; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param EntityManager $entityManager |
|
26
|
|
|
* @param RealTimeActionScheduler $realtimeActionScheduler |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(EntityManager $entityManager, RealTimeActionScheduler $realtimeActionScheduler) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->entityManager = $entityManager; |
|
31
|
|
|
$this->realtimeActionScheduler = $realtimeActionScheduler; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function scheduleQueues() |
|
35
|
|
|
{ |
|
36
|
|
|
$queues = $this->entityManager->getRepository(TechnologyQueue::class)->getAll(); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
foreach ($queues as $queue) { |
|
39
|
|
|
$this->realtimeActionScheduler->schedule('athena.orbital_base_manager', 'uTechnologyQueue', $queue, $queue->getEndedAt()); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param int $id |
|
45
|
|
|
* @return TechnologyQueue |
|
46
|
|
|
*/ |
|
47
|
|
|
public function get($id) |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->entityManager->getRepository(TechnologyQueue::class)->get($id); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param int $playerId |
|
54
|
|
|
* @param int $technology |
|
55
|
|
|
* @return TechnologyQueue |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getPlayerTechnologyQueue($playerId, $technology) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->entityManager->getRepository(TechnologyQueue::class)->getPlayerTechnologyQueue($playerId, $technology); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param int $placeId |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getPlaceQueues($placeId) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->entityManager->getRepository(TechnologyQueue::class)->getPlaceQueues($placeId); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param int $playerId |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getPlayerQueues($playerId) |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->entityManager->getRepository(TechnologyQueue::class)->getPlayerQueues($playerId); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param TechnologyQueue $technologyQueue |
|
82
|
|
|
*/ |
|
83
|
|
|
public function add(TechnologyQueue $technologyQueue) { |
|
84
|
|
|
$this->entityManager->persist($technologyQueue); |
|
85
|
|
|
$this->entityManager->flush($technologyQueue); |
|
86
|
|
|
|
|
87
|
|
|
$this->realtimeActionScheduler->schedule('athena.orbital_base_manager', 'uTechnologyQueue', $technologyQueue, $technologyQueue->getEndedAt()); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: