Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen 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 Doctrine\Common\Lexer;
6
 
7
use ArrayAccess;
8
use Doctrine\Deprecations\Deprecation;
9
use ReturnTypeWillChange;
10
use UnitEnum;
11
 
12
use function in_array;
13
 
14
/**
15
 * @template T of UnitEnum|string|int
16
 * @template V of string|int
17
 * @implements ArrayAccess<string,mixed>
18
 */
19
final class Token implements ArrayAccess
20
{
21
    /**
22
     * The string value of the token in the input string
23
     *
24
     * @readonly
25
     * @var V
26
     */
27
    public $value;
28
 
29
    /**
30
     * The type of the token (identifier, numeric, string, input parameter, none)
31
     *
32
     * @readonly
33
     * @var T|null
34
     */
35
    public $type;
36
 
37
    /**
38
     * The position of the token in the input string
39
     *
40
     * @readonly
41
     * @var int
42
     */
43
    public $position;
44
 
45
    /**
46
     * @param V      $value
47
     * @param T|null $type
48
     */
49
    public function __construct($value, $type, int $position)
50
    {
51
        $this->value    = $value;
52
        $this->type     = $type;
53
        $this->position = $position;
54
    }
55
 
56
    /** @param T ...$types */
57
    public function isA(...$types): bool
58
    {
59
        return in_array($this->type, $types, true);
60
    }
61
 
62
    /**
63
     * @deprecated Use the value, type or position property instead
64
     * {@inheritDoc}
65
     */
66
    public function offsetExists($offset): bool
67
    {
68
        Deprecation::trigger(
69
            'doctrine/lexer',
70
            'https://github.com/doctrine/lexer/pull/79',
71
            'Accessing %s properties via ArrayAccess is deprecated, use the value, type or position property instead',
72
            self::class
73
        );
74
 
75
        return in_array($offset, ['value', 'type', 'position'], true);
76
    }
77
 
78
    /**
79
     * @deprecated Use the value, type or position property instead
80
     * {@inheritDoc}
81
     *
82
     * @param O $offset
83
     *
84
     * @return mixed
85
     * @psalm-return (
86
     *     O is 'value'
87
     *     ? V
88
     *     : (
89
     *         O is 'type'
90
     *         ? T|null
91
     *         : (
92
     *             O is 'position'
93
     *             ? int
94
     *             : mixed
95
     *         )
96
     *     )
97
     * )
98
     *
99
     * @template O of array-key
100
     */
101
    #[ReturnTypeWillChange]
102
    public function offsetGet($offset)
103
    {
104
        Deprecation::trigger(
105
            'doctrine/lexer',
106
            'https://github.com/doctrine/lexer/pull/79',
107
            'Accessing %s properties via ArrayAccess is deprecated, use the value, type or position property instead',
108
            self::class
109
        );
110
 
111
        return $this->$offset;
112
    }
113
 
114
    /**
115
     * @deprecated no replacement planned
116
     * {@inheritDoc}
117
     */
118
    public function offsetSet($offset, $value): void
119
    {
120
        Deprecation::trigger(
121
            'doctrine/lexer',
122
            'https://github.com/doctrine/lexer/pull/79',
123
            'Setting %s properties via ArrayAccess is deprecated',
124
            self::class
125
        );
126
 
127
        $this->$offset = $value;
128
    }
129
 
130
    /**
131
     * @deprecated no replacement planned
132
     * {@inheritDoc}
133
     */
134
    public function offsetUnset($offset): void
135
    {
136
        Deprecation::trigger(
137
            'doctrine/lexer',
138
            'https://github.com/doctrine/lexer/pull/79',
139
            'Setting %s properties via ArrayAccess is deprecated',
140
            self::class
141
        );
142
 
143
        $this->$offset = null;
144
    }
145
}