Skip to content
Snippets Groups Projects
Select Git revision
  • 1de0ce9286a6559f1e9cf15ac863e72959b86dcb
  • main default protected
  • register-logging-channel
  • expr-lang
  • ci-82
  • attr-events
  • locale-wip
  • custom-routes
  • v0.1.85
  • v0.1.84
  • v0.1.83
  • v0.1.82
  • v0.1.81
  • v0.1.80
  • v0.1.79
  • v0.1.78
  • v0.1.77
  • v0.1.76
  • v0.1.75
  • v0.1.74
  • v0.1.73
  • v0.1.72
  • v0.1.71
  • v0.1.70
  • v0.1.69
  • v0.1.68
  • v0.1.67
  • v0.1.65
28 results

DebugCommand.php

Blame
  • Christoph Reiter's avatar
    Reiter, Christoph authored
    One event for changing the global attribute list and one for changing
    the result for existing attributes and/or introducing new attributes.
    1de0ce92
    History
    DebugCommand.php 1.79 KiB
    <?php
    
    declare(strict_types=1);
    
    namespace Dbp\Relay\CoreBundle\Authorization;
    
    use Psr\Log\LoggerAwareInterface;
    use Psr\Log\LoggerAwareTrait;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class DebugCommand extends Command implements LoggerAwareInterface
    {
        use LoggerAwareTrait;
    
        protected static $defaultName = 'dbp:relay:core:auth-debug';
    
        /**
         * @var AuthorizationDataMuxer
         */
        private $mux;
    
        public function __construct(AuthorizationDataMuxer $mux)
        {
            parent::__construct();
            $this->mux = $mux;
        }
    
        protected function configure()
        {
            $this->setDescription('Shows various information about the authorization providers');
            $this->addArgument('username', InputArgument::OPTIONAL, 'username');
        }
    
        protected function execute(InputInterface $input, OutputInterface $output): int
        {
            $username = $input->getArgument('username');
    
            $attrs = $this->mux->getAvailableAttributes();
            $all = [];
            $default = new \stdClass();
            sort($attrs, SORT_STRING | SORT_FLAG_CASE);
            foreach ($attrs as $attr) {
                $all[$attr] = $this->mux->getAttribute($username, $attr, $default);
            }
    
            // Now print them out
            $output->writeln('<fg=blue;options=bold>[Authorization attributes]</>');
            foreach ($all as $attr => $value) {
                if ($value === $default) {
                    $output->writeln('<fg=green;options=bold>'.$attr.'</> = <fg=magenta;options=bold>\<N/A\></>');
                } else {
                    $output->writeln('<fg=green;options=bold>'.$attr.'</> = '.json_encode($value));
                }
            }
    
            return 0;
        }
    }