| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the BenGorFile package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Beñat Espiña <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * (c) Gorka Laucirica <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | namespace BenGorFile\FileBundle\DependencyInjection\Compiler\Application\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use BenGorFile\File\Application\Command\Upload\ByHashUploadFileCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use BenGorFile\File\Application\Command\Upload\ByHashUploadFileHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use BenGorFile\File\Application\Command\Upload\UploadFileCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use BenGorFile\File\Application\Command\Upload\UploadFileHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\DependencyInjection\Definition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Upload file command builder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @author Beñat Espiña <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | class UploadFileCommandBuilder extends CommandBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function register($file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->container->setDefinition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $this->definitionName($file), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             (new Definition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                 $this->handler(), [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                     $this->container->getDefinition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                         'bengor.file.infrastructure.domain.model.' . $file . '_filesystem' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                     ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                     $this->container->getDefinition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                         'bengor.file.infrastructure.persistence.' . $file . '_repository' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                     ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                     $this->container->getDefinition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                         'bengor.file.infrastructure.domain.model.' . $file . '_factory' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                     ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ))->addTag( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 'bengor_file_' . $file . '_command_bus_handler', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                     'handles' => $this->command(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     protected function definitionName($file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         return 'bengor.file.application.command.upload_' . $file; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     protected function aliasDefinitionName($file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return 'bengor_file.' . $file . '.upload'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * Gets the FQCN of command. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     private function command() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         return $this->configuration['upload_strategy'] === 'default' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             ? UploadFileCommand::class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             : ByHashUploadFileCommand::class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * Gets the FQCN of command handler. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 87 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |     private function handler() | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |         return $this->configuration['upload_strategy'] === 'default' | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |             ? UploadFileHandler::class | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |             : ByHashUploadFileHandler::class; | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 94 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |  |