| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright Copyright (C) eZ Systems AS. All rights reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license For full copyright and license information view LICENSE file distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | namespace eZ\Bundle\EzPublishCoreBundle\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use eZ\Publish\Core\MVC\ConfigResolverInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use eZ\Publish\Core\MVC\Symfony\SiteAccess; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Component\Console\Command\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\VarDumper\Cloner\VarCloner; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\VarDumper\Dumper\CliDumper; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | class DebugConfigResolverCommand extends Command | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * @var \eZ\Publish\Core\MVC\ConfigResolverInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     private $configResolver; | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * @var \eZ\Publish\Core\MVC\Symfony\SiteAccess | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     private $siteAccess; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         ConfigResolverInterface $configResolver, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         SiteAccess $siteAccess | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->configResolver = $configResolver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->siteAccess = $siteAccess; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         parent::__construct(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * {@inheritdoc}. | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->setName('ezplatform:debug:config-resolver'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->setAliases(['ezplatform:debug:config']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->setDescription('Debug / Retrive parameter from Config Resolver'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->addArgument( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'parameter', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             InputArgument::REQUIRED, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             'The configuration resolver parameter to return, for instance "languages" or "http_cache.purge_servers"' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             'json', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             InputOption::VALUE_NONE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             'Only return value, for automation / testing use on a single line in json format.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             'scope', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             InputOption::VALUE_REQUIRED, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             'Set another scope (siteaccess) to use, alternative to using the global --siteaccess[=SITEACCESS] option.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             'namespace', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             InputOption::VALUE_REQUIRED, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             'Set another namespace than default "ezsettings" used by siteaccess settings.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->setHelp(<<<EOM | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | Outputs a given config resolver parameter, more commonly known as a SiteAccess setting. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | By default it will give value depending on global <comment>--siteaccess[=SITEACCESS]</comment> (default siteaccess is used if not set). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | However you can also manually set <comment>--scope[=NAME]</comment> yourself if you don't want to affect the siteaccess | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | set by the system. You can also override namespace to get something else than default "ezsettings" namespace using | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | <comment>--namespace[=NS]</comment> option. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | NOTE: To rather see *all* compiled siteaccess settings, use: <comment>debug:config ezpublish [system.default]</comment> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | EOM | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |      * {@inheritdoc}. | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $parameter = $input->getArgument('parameter'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $namespace = $input->getOption('namespace'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $scope = $input->getOption('scope'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $parameterData = $this->configResolver->getParameter($parameter, $namespace, $scope); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         // In case of json output return early with no newlines and only the parameter data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         if ($input->getOption('json')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             $output->write(json_encode($parameterData)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $output->writeln('<comment>SiteAccess name:</comment> ' . $this->siteAccess->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $output->writeln('<comment>Parameter:</comment>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $cloner = new VarCloner(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $dumper = new CliDumper(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $output->write( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             $dumper->dump( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                 $cloner->cloneVar($parameterData), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                 true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 115 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 116 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |  | 
            
                        
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.