1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* RecyclingMissionManager |
5
|
|
|
* |
6
|
|
|
* @author Jacky Casas |
7
|
|
|
* @copyright Asylamba |
8
|
|
|
* |
9
|
|
|
* @package Zeus |
10
|
|
|
* @version 09.02.15 |
11
|
|
|
**/ |
12
|
|
|
namespace Asylamba\Modules\Athena\Manager; |
13
|
|
|
|
14
|
|
|
use Asylamba\Classes\Entity\EntityManager; |
15
|
|
|
use Asylamba\Classes\Scheduler\RealTimeActionScheduler; |
16
|
|
|
|
17
|
|
|
use Asylamba\Modules\Athena\Model\RecyclingMission; |
18
|
|
|
|
19
|
|
|
class RecyclingMissionManager |
20
|
|
|
{ |
21
|
|
|
/** @var EntityManager **/ |
22
|
|
|
protected $entityManager; |
23
|
|
|
/** @var RealTimeActionScheduler **/ |
24
|
|
|
protected $realtimeActionScheduler; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param EntityManager $entityManager |
28
|
|
|
* @param RealTimeActionScheduler $realtimeActionScheduler |
29
|
|
|
*/ |
30
|
|
|
public function __construct(EntityManager $entityManager, RealTimeActionScheduler $realtimeActionScheduler) |
31
|
|
|
{ |
32
|
|
|
$this->entityManager = $entityManager; |
33
|
|
|
$this->realtimeActionScheduler = $realtimeActionScheduler; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function scheduleMissions() |
37
|
|
|
{ |
38
|
|
|
$missions = $this->entityManager->getRepository(RecyclingMission::class)->getAll(); |
|
|
|
|
39
|
|
|
|
40
|
|
|
foreach ($missions as $mission) { |
41
|
|
|
$this->realtimeActionScheduler->schedule( |
42
|
|
|
'athena.orbital_base_manager', |
43
|
|
|
'uRecycling', |
44
|
|
|
$mission, |
45
|
|
|
$mission->uRecycling |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param int $id |
52
|
|
|
* @return RecyclingMission |
53
|
|
|
*/ |
54
|
|
|
public function get($id) |
55
|
|
|
{ |
56
|
|
|
return $this->entityManager->getRepository(RecyclingMission::class)->get($id); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param int $baseId |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getBaseMissions($baseId) |
64
|
|
|
{ |
65
|
|
|
return $this->entityManager->getRepository(RecyclingMission::class)->getBaseMissions($baseId); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param int $baseId |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function getBaseActiveMissions($baseId) |
73
|
|
|
{ |
74
|
|
|
return $this->entityManager->getRepository(RecyclingMission::class)->getBaseActiveMissions($baseId); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param RecyclingMission $recyclingMission |
79
|
|
|
*/ |
80
|
|
|
public function add(RecyclingMission $recyclingMission) |
81
|
|
|
{ |
82
|
|
|
$this->entityManager->persist($recyclingMission); |
83
|
|
|
$this->entityManager->flush($recyclingMission); |
84
|
|
|
|
85
|
|
|
$this->realtimeActionScheduler->schedule( |
86
|
|
|
'athena.orbital_base_manager', |
87
|
|
|
'uRecycling', |
88
|
|
|
$recyclingMission, |
|
|
|
|
89
|
|
|
$recyclingMission->uRecycling |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param int $baseId |
95
|
|
|
*/ |
96
|
|
|
public function removeBaseMissions($baseId) |
97
|
|
|
{ |
98
|
|
|
foreach ($this->getBaseActiveMissions($baseId) as $mission) { |
99
|
|
|
$this->realtimeActionScheduler->cancel($mission, $mission->uRecycling); |
100
|
|
|
} |
101
|
|
|
$this->entityManager->getRepository(RecyclingMission::class)->removeBaseMissions($baseId); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} |
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: