Skip to content
Snippets Groups Projects
Select Git revision
  • d17bc60e71bc12c3f067a7a0140206a32c36bb71
  • main default protected
  • php84
  • 5x
  • 6.1.6
  • 6.1.5
  • 6.1.4
  • 6.1.3
  • 6.1.2
  • 6.1.1
  • 6.1.0
  • 6.0.3
  • 6.0.2
  • 6.0.1
  • 6.0.0
  • 5.0.3
  • 5.0.2
  • 5.0.1
  • 4.0.1
  • 5.0.0
  • 4.0.0
21 results

101_privilege.sql

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('');
            }
        }
    
    }