Skip to content
Snippets Groups Projects
Select Git revision
  • 54a8806e249770b902aa0c1c49e8199bfe800f28
  • master default protected
  • release_1.4.0
  • release_1.3.0
  • release_1.2.0
  • 8.4
  • release_1.1.0
  • release_1.0.6
  • release_1.0.5
  • release_1.0.4
  • 1.2.3
  • 1.2.2
  • 1.2.1
  • 1.2.0
  • 1.1.0
  • 1.0.7
  • 1.0.6
  • 1.0.5
  • 1.0.4
  • 1.0.3
  • 1.0.2
21 results

indicateurs.md

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