Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Console\Formatter;
13
 
14
use Symfony\Component\Console\Color;
15
 
16
/**
17
 * Formatter style class for defining styles.
18
 *
19
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
20
 */
21
class OutputFormatterStyle implements OutputFormatterStyleInterface
22
{
23
    private Color $color;
24
    private string $foreground;
25
    private string $background;
26
    private array $options;
27
    private ?string $href = null;
28
    private bool $handlesHrefGracefully;
29
 
30
    /**
31
     * Initializes output formatter style.
32
     *
33
     * @param string|null $foreground The style foreground color name
34
     * @param string|null $background The style background color name
35
     */
36
    public function __construct(string $foreground = null, string $background = null, array $options = [])
37
    {
38
        $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options);
39
    }
40
 
41
    public function setForeground(string $color = null)
42
    {
43
        if (1 > \func_num_args()) {
44
            trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
45
        }
46
        $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options);
47
    }
48
 
49
    public function setBackground(string $color = null)
50
    {
51
        if (1 > \func_num_args()) {
52
            trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
53
        }
54
        $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options);
55
    }
56
 
57
    public function setHref(string $url): void
58
    {
59
        $this->href = $url;
60
    }
61
 
62
    public function setOption(string $option)
63
    {
64
        $this->options[] = $option;
65
        $this->color = new Color($this->foreground, $this->background, $this->options);
66
    }
67
 
68
    public function unsetOption(string $option)
69
    {
70
        $pos = array_search($option, $this->options);
71
        if (false !== $pos) {
72
            unset($this->options[$pos]);
73
        }
74
 
75
        $this->color = new Color($this->foreground, $this->background, $this->options);
76
    }
77
 
78
    public function setOptions(array $options)
79
    {
80
        $this->color = new Color($this->foreground, $this->background, $this->options = $options);
81
    }
82
 
83
    public function apply(string $text): string
84
    {
85
        $this->handlesHrefGracefully ??= 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
991 lars 86
            && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100)
87
            && !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
148 lars 88
 
89
        if (null !== $this->href && $this->handlesHrefGracefully) {
90
            $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\";
91
        }
92
 
93
        return $this->color->apply($text);
94
    }
95
}