| 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 |  |  |     public function __construct(ActionFactory $commandFactory) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->commandFactory = $commandFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         parent::__construct($commandFactory); // backward compatibility | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @see DomainInterface::create() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     public function create(ZoneTypeInterface $zoneType, ComponentCollection $components = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         return $this->commandFactory | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             ->createAction('create') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 ->setZoneType($zoneType) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 ->setComponents($components ?: new ComponentCollection()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ->resolve() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @see DomainInterface::edit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function edit(ZoneInterface $zone, ComponentCollection $components) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         return $this->commandFactory | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ->createAction('edit') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 ->init($zone) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 ->setComponents($components) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ->resolve() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @see DomainInterface::addComponent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function addComponent(ZoneInterface $zone, ComponentTypeInterface $componentType, array $componentData = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return $this->commandFactory | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             ->createAction('add_component') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 ->init($zone) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 ->setComponentType($componentType) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 ->setComponentData($componentData) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             ->resolve() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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: