| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Aggrego. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * (c) Tomasz Kunicki <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | declare(strict_types = 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | namespace Aggrego\Domain\Board; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Aggrego\AggregateEventConsumer\Uuid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Aggrego\Domain\Board\Builder as BoardBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Aggrego\Domain\Board\Exception\UnsupportedPrototypeBuilderException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Aggrego\Domain\Profile\BoardTransformation\Factory as BoardTransformationFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Assert\Assertion; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Ramsey\Uuid\Uuid as RamseyUuid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class FromBoardFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** @var BoardBuilder[] */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $builders; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** @var BoardTransformationFactory */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private $transformationFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         array $builders, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         BoardTransformationFactory $transformationFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         Assertion::allIsInstanceOf($builders, BoardBuilder::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->builders = $builders; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->transformationFactory = $transformationFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     public function fromBoard(Board $board): Board | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $transformation = $this->transformationFactory->factory($board->getProfile()); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         $prototype = $transformation->transform($board); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $key = $prototype->getKey(); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $profile = $prototype->getProfile(); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $parentUuid = $board->getUuid(); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         $uuid = new Uuid( | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             RamseyUuid::uuid5( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 RamseyUuid::NAMESPACE_DNS, | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |                 serialize($key->getValue()) . $profile . $parentUuid->getValue() | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             )->toString() | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         foreach ($this->builders as $builder) { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             if (!$builder->isSupported($prototype)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |                 continue; | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             return $builder->build( | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |                 $uuid, | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |                 $prototype->getKey(), | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |                 $prototype->getProfile(), | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |                 $prototype->getMetadata(), | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |                 $parentUuid | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         throw new UnsupportedPrototypeBuilderException(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  | 
            
                        
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.