1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Synapse\Cmf\Framework\Theme\Zone\Domain; |
4
|
|
|
|
5
|
|
|
use Majora\Framework\Domain\ActionDispatcherDomain; |
6
|
|
|
use Majora\Framework\Domain\Action\ActionFactory; |
7
|
|
|
use Synapse\Cmf\Framework\Theme\ComponentType\Model\ComponentTypeInterface; |
8
|
|
|
use Synapse\Cmf\Framework\Theme\Component\Entity\ComponentCollection; |
9
|
|
|
use Synapse\Cmf\Framework\Theme\Component\Model\ComponentInterface; |
10
|
|
|
use Synapse\Cmf\Framework\Theme\ZoneType\Model\ZoneTypeInterface; |
11
|
|
|
use Synapse\Cmf\Framework\Theme\Zone\Model\ZoneInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Zone domain use cases class. |
15
|
|
|
*/ |
16
|
|
|
class ZoneDomain extends ActionDispatcherDomain implements DomainInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var ActionFactory |
20
|
|
|
*/ |
21
|
|
|
protected $commandFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Construct. |
25
|
|
|
* |
26
|
|
|
* @param ActionFactory $commandFactory |
27
|
|
|
*/ |
28
|
6 |
|
public function __construct(ActionFactory $commandFactory) |
29
|
|
|
{ |
30
|
6 |
|
$this->commandFactory = $commandFactory; |
31
|
|
|
|
32
|
6 |
|
parent::__construct($commandFactory); // backward compatibility |
33
|
6 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @see DomainInterface::create() |
37
|
|
|
*/ |
38
|
2 |
|
public function create(ZoneTypeInterface $zoneType, ComponentCollection $components = null) |
39
|
|
|
{ |
40
|
2 |
|
return $this->commandFactory |
|
|
|
|
41
|
2 |
|
->createAction('create') |
42
|
2 |
|
->setZoneType($zoneType) |
43
|
2 |
|
->setComponents($components ?: new ComponentCollection()) |
44
|
2 |
|
->resolve() |
45
|
1 |
|
; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @see DomainInterface::edit() |
50
|
|
|
*/ |
51
|
2 |
|
public function edit(ZoneInterface $zone, ComponentCollection $components) |
52
|
|
|
{ |
53
|
2 |
|
return $this->commandFactory |
|
|
|
|
54
|
2 |
|
->createAction('edit') |
55
|
2 |
|
->init($zone) |
56
|
2 |
|
->setComponents($components) |
57
|
2 |
|
->resolve() |
58
|
1 |
|
; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @see DomainInterface::addComponent() |
63
|
|
|
*/ |
64
|
2 |
|
public function addComponent(ZoneInterface $zone, ComponentTypeInterface $componentType, array $componentData = array()) |
65
|
|
|
{ |
66
|
2 |
|
return $this->commandFactory |
|
|
|
|
67
|
2 |
|
->createAction('add_component') |
68
|
2 |
|
->init($zone) |
69
|
2 |
|
->setComponentType($componentType) |
70
|
2 |
|
->setComponentData($componentData) |
71
|
2 |
|
->resolve() |
72
|
1 |
|
; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @see DomainInterface::removeComponent() |
77
|
|
|
*/ |
78
|
|
|
public function removeComponent(ZoneInterface $zone, ComponentInterface $component) |
79
|
|
|
{ |
80
|
|
|
return $this->commandFactory |
|
|
|
|
81
|
|
|
->createAction('delete_component') |
82
|
|
|
->init($zone) |
83
|
|
|
->setComponent($component) |
84
|
|
|
->resolve() |
85
|
|
|
; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
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 implementation 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 interface: