Skip to content
Snippets Groups Projects
Select Git revision
  • a2e1f94c4d32fdec4ea211525dfcdc9ad20ba34c
  • master default protected
  • main
  • update_github_actions
  • 144_rocky8_support
  • 195-update-pdk-to-300
  • 144-rocky8
  • add_test_github_test_workflow
  • pdk_2.4.0
  • fix_unclosed_let_block_in_defines_client_spec
  • validation_fixes
  • freeradius_3_0_21_config_updates
  • data_types
  • PrepareBuster
  • travis
  • 4.0.1
  • 4.0.0
  • 3.9.2
  • 3.9.1
  • 3.9.0
  • 3.8.2
  • 3.8.1
  • 3.8.0
  • 3.7.0
  • 3.6.0
  • 3.5.0
  • 3.4.3
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.3.1
35 results

control_socket.pp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    SymfonyStyleLogger.php 1.98 KiB
    <?php
    
    namespace Unicaen\BddAdmin\Logger;
    
    
    use Symfony\Component\Console\Style\SymfonyStyle;
    
    class SymfonyStyleLogger implements LoggerInterface
    {
        protected ?string $lastMessage = null;
    
        protected bool $lastRewrite = false;
        
        protected SymfonyStyle $symfonyStyle;
    
    
    
        public function __construct(SymfonyStyle $symfonyStyle)
        {
            $this->symfonyStyle = $symfonyStyle;
        }
    
    
    
        public function print($text, $color = null, $bgColor = null)
        {
            $this->symfonyStyle->write($text);
        }
    
    
    
        public function println($text, $color = null, $bgColor = null)
        {
            $this->symfonyStyle->writeln($text);
        }
    
    
    
        public function msg($message, bool $rewrite = false)
        {
            if ($rewrite) {
                if ($this->lastMessage) {
                    $m = $message . str_pad('', strlen($this->lastMessage) - strlen($message) + 2) . "\r";
                } else {
                    $m = $message . "\r";
                }
                $this->print($m);
            } else {
                $this->println($message);
            }
            $this->lastMessage = $message;
            $this->lastRewrite = $rewrite;
        }
    
    
    
        public function error(Throwable|string $e)
        {
            if ($e instanceof \Throwable) {
                $e = $e->getMessage();
            }
            if ($this->lastRewrite) $this->println('');
            $this->symfonyStyle->error($e);
        }
    
    
    
        public function begin(string $title)
        {
            if ($this->lastMessage) {
                $title .= str_pad('', strlen($this->lastMessage) - strlen($title) + 2);
            }
            $this->lastRewrite = false;
            $this->lastMessage = null;
            $this->symfonyStyle->title($title);
        }
    
    
    
        public function end(?string $msg = null): void
        {
            if ($this->lastMessage && $this->lastRewrite) {
                $msg .= str_pad('', strlen($this->lastMessage) - strlen($msg ?? '') + 2);
            }
            if (trim($msg)) {
                $this->symfonyStyle->comment($msg);
            } else {
                $this->println('');
            }
        }
    
    }