Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Dotenv\Parser;
6
 
7
use Dotenv\Util\Str;
8
 
9
final class Value
10
{
11
    /**
12
     * The string representation of the parsed value.
13
     *
14
     * @var string
15
     */
16
    private $chars;
17
 
18
    /**
19
     * The locations of the variables in the value.
20
     *
21
     * @var int[]
22
     */
23
    private $vars;
24
 
25
    /**
26
     * Internal constructor for a value.
27
     *
28
     * @param string $chars
29
     * @param int[]  $vars
30
     *
31
     * @return void
32
     */
33
    private function __construct(string $chars, array $vars)
34
    {
35
        $this->chars = $chars;
36
        $this->vars = $vars;
37
    }
38
 
39
    /**
40
     * Create an empty value instance.
41
     *
42
     * @return \Dotenv\Parser\Value
43
     */
44
    public static function blank()
45
    {
46
        return new self('', []);
47
    }
48
 
49
    /**
50
     * Create a new value instance, appending the characters.
51
     *
52
     * @param string $chars
53
     * @param bool   $var
54
     *
55
     * @return \Dotenv\Parser\Value
56
     */
57
    public function append(string $chars, bool $var)
58
    {
59
        return new self(
60
            $this->chars.$chars,
61
            $var ? \array_merge($this->vars, [Str::len($this->chars)]) : $this->vars
62
        );
63
    }
64
 
65
    /**
66
     * Get the string representation of the parsed value.
67
     *
68
     * @return string
69
     */
70
    public function getChars()
71
    {
72
        return $this->chars;
73
    }
74
 
75
    /**
76
     * Get the locations of the variables in the value.
77
     *
78
     * @return int[]
79
     */
80
    public function getVars()
81
    {
82
        $vars = $this->vars;
83
 
84
        \rsort($vars);
85
 
86
        return $vars;
87
    }
88
}