| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace CultuurNet\UDB3\Label\ReadModels\Relations\Repository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use CultuurNet\UDB3\Label\ReadModels\Relations\Repository\Doctrine\SchemaConfigurator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use CultuurNet\UDB3\Label\ValueObjects\LabelName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use CultuurNet\UDB3\Label\ValueObjects\RelationType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use ValueObjects\String\String as StringLiteral; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  | class LabelRelation implements \JsonSerializable | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |      * @var LabelName | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     private $labelName; | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * @var RelationType | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     private $relationType; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      * @var StringLiteral | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     private $relationId; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * Entity constructor. | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      * @param LabelName $labelName | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * @param RelationType $relationType | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * @param StringLiteral $relationId | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         LabelName $labelName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         RelationType $relationType, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         StringLiteral $relationId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->labelName = $labelName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->relationType = $relationType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->relationId = $relationId; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * @return LabelName | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function getLabelName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return $this->labelName; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * @return RelationType | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function getRelationType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return $this->relationType; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * @return StringLiteral | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     public function getRelationId() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         return $this->relationId; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |      * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     public function jsonSerialize() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             SchemaConfigurator::LABEL_NAME => $this->labelName->toNative(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             SchemaConfigurator::RELATION_TYPE => $this->relationType->toNative(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             SchemaConfigurator::RELATION_ID => $this->relationId->toNative() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         ]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |      * @param array $relation | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |      * @return LabelRelation | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public static function fromRelationalData(array $relation) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         return new static( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             new LabelName($relation[SchemaConfigurator::LABEL_NAME]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             RelationType::fromNative($relation[SchemaConfigurator::RELATION_TYPE]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             new StringLiteral($relation[SchemaConfigurator::RELATION_ID]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 91 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |  |