Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 150
Zeile 3... Zeile 3...
3
namespace Egulias\EmailValidator;
3
namespace Egulias\EmailValidator;
Zeile 4... Zeile 4...
4
 
4
 
5
use Doctrine\Common\Lexer\AbstractLexer;
5
use Doctrine\Common\Lexer\AbstractLexer;
Zeile 6... Zeile -...
6
use Doctrine\Common\Lexer\Token;
-
 
7
 
6
use Doctrine\Common\Lexer\Token;
8
/**
-
 
9
 * @extends AbstractLexer<int, string>
7
 
10
 */
8
/** @extends AbstractLexer<int, string> */
11
class EmailLexer extends AbstractLexer
9
class EmailLexer extends AbstractLexer
12
{
10
{
13
    //ASCII values
11
    //ASCII values
14
    public const S_EMPTY            = null;
12
    public const S_EMPTY            = -1;
15
    public const C_NUL              = 0;
13
    public const C_NUL              = 0;
16
    public const S_HTAB             = 9;
14
    public const S_HTAB             = 9;
17
    public const S_LF               = 10;
15
    public const S_LF               = 10;
Zeile 48... Zeile 46...
48
    public const S_OPENCURLYBRACES  = 123;
46
    public const S_OPENCURLYBRACES  = 123;
49
    public const S_PIPE             = 124;
47
    public const S_PIPE             = 124;
50
    public const S_CLOSECURLYBRACES = 125;
48
    public const S_CLOSECURLYBRACES = 125;
51
    public const S_TILDE            = 126;
49
    public const S_TILDE            = 126;
52
    public const C_DEL              = 127;
50
    public const C_DEL              = 127;
53
    public const INVERT_QUESTIONMARK= 168;
51
    public const INVERT_QUESTIONMARK = 168;
54
    public const INVERT_EXCLAMATION = 173;
52
    public const INVERT_EXCLAMATION = 173;
55
    public const GENERIC            = 300;
53
    public const GENERIC            = 300;
56
    public const S_IPV6TAG          = 301;
54
    public const S_IPV6TAG          = 301;
57
    public const INVALID            = 302;
55
    public const INVALID            = 302;
58
    public const CRLF               = 1310;
56
    public const CRLF               = 1310;
Zeile 133... Zeile 131...
133
 
131
 
134
    /** @var bool */
132
    /** @var bool */
Zeile 135... Zeile 133...
135
    protected $hasInvalidTokens = false;
133
    protected $hasInvalidTokens = false;
136
 
134
 
137
    /**
-
 
138
     * @var array
-
 
139
     *
135
    /**
140
     * @psalm-var array{value:string, type:null|int, position:int}|array<empty, empty>
136
     * @var Token<int, string>
Zeile 141... Zeile 137...
141
     */
137
     */
142
    protected $previous = [];
138
    protected Token $previous;
143
 
139
 
144
    /**
140
    /**
145
     * The last matched/seen token.
-
 
146
     *
-
 
147
     * @var array|Token
-
 
148
     *
141
     * The last matched/seen token.
149
     * @psalm-suppress NonInvariantDocblockPropertyType
142
     *
Zeile 150... Zeile 143...
150
     * @psalm-var array{value:string, type:null|int, position:int}|Token<int, string>
143
     * @var Token<int, string>
151
     */
144
     */
152
    public $token;
-
 
153
 
-
 
154
    /**
-
 
155
     * The next token in the input.
-
 
156
     *
-
 
157
     * @var array|Token|null
145
    public Token $current;
158
     *
-
 
159
     * @psalm-suppress NonInvariantDocblockPropertyType
-
 
160
     * @psalm-var array{position: int, type: int|null|string, value: int|string}|Token<int, string>|null
-
 
161
     */
146
 
162
    public $lookahead;
-
 
163
 
-
 
164
    /** @psalm-var array{value:'', type:null, position:0} */
-
 
165
    private static $nullToken = [
-
 
Zeile 166... Zeile 147...
166
        'value' => '',
147
    /**
167
        'type' => null,
148
     * @var Token<int, string>
Zeile 168... Zeile 149...
168
        'position' => 0,
149
     */
169
    ];
150
    private Token $nullToken;
Zeile 170... Zeile 151...
170
 
151
 
171
    /** @var string */
152
    /** @var string */
-
 
153
    private $accumulator = '';
-
 
154
 
-
 
155
    /** @var bool */
-
 
156
    private $hasToRecord = false;
172
    private $accumulator = '';
157
 
173
 
158
    public function __construct()
174
    /** @var bool */
159
    {
Zeile 175... Zeile 160...
175
    private $hasToRecord = false;
160
        /** @var Token<int, string> $nullToken */
176
 
161
        $nullToken = new Token('', self::S_EMPTY, 0);
177
    public function __construct()
162
        $this->nullToken = $nullToken;
178
    {
163
 
179
        $this->previous = $this->token = self::$nullToken;
164
        $this->current = $this->previous = $this->nullToken;
180
        $this->lookahead = null;
165
        $this->lookahead = null;
Zeile 181... Zeile 166...
181
    }
166
    }
182
 
167
 
183
    public function reset() : void
168
    public function reset(): void
184
    {
169
    {
185
        $this->hasInvalidTokens = false;
170
        $this->hasInvalidTokens = false;
186
        parent::reset();
171
        parent::reset();
187
        $this->previous = $this->token = self::$nullToken;
172
        $this->current = $this->previous = $this->nullToken;
188
    }
173
    }
189
 
174
 
190
    /**
175
    /**
191
     * @param int $type
176
     * @param int $type
Zeile 192... Zeile 177...
192
     * @throws \UnexpectedValueException
177
     * @throws \UnexpectedValueException
Zeile 208... Zeile 193...
208
    /**
193
    /**
209
     * moveNext
194
     * moveNext
210
     *
195
     *
211
     * @return boolean
196
     * @return boolean
212
     */
197
     */
213
    public function moveNext() : bool
198
    public function moveNext(): bool
214
    {
199
    {
215
        if ($this->hasToRecord && $this->previous === self::$nullToken) {
200
        if ($this->hasToRecord && $this->previous === $this->nullToken) {
216
            $this->accumulator .= $this->token['value'];
201
            $this->accumulator .= $this->current->value;
217
        }
202
        }
Zeile 218... Zeile 203...
218
 
203
 
219
        $this->previous = $this->token instanceof Token
-
 
220
            ? ['value' => $this->token->value, 'type' => $this->token->type, 'position' => $this->token->position]
-
 
221
            : $this->token;
204
        $this->previous = $this->current;
222
        
205
 
223
        if($this->lookahead === null) {
206
        if ($this->lookahead === null) {
224
            $this->lookahead = self::$nullToken;
207
            $this->lookahead = $this->nullToken;
Zeile 225... Zeile 208...
225
        }
208
        }
-
 
209
 
Zeile 226... Zeile 210...
226
 
210
        $hasNext = parent::moveNext();
227
        $hasNext = parent::moveNext();
211
        $this->current = $this->token ?? $this->nullToken;
228
 
212
 
Zeile 229... Zeile 213...
229
        if ($this->hasToRecord) {
213
        if ($this->hasToRecord) {
230
            $this->accumulator .= $this->token['value'];
214
            $this->accumulator .= $this->current->value;
Zeile 238... Zeile 222...
238
     *
222
     *
239
     * @param string $value
223
     * @param string $value
240
     * @throws \InvalidArgumentException
224
     * @throws \InvalidArgumentException
241
     * @return integer
225
     * @return integer
242
     */
226
     */
243
    protected function getType(&$value)
227
    protected function getType(&$value): int
244
    {
228
    {
245
        $encoded = $value;
229
        $encoded = $value;
Zeile 246... Zeile 230...
246
 
230
 
247
        if (mb_detect_encoding($value, 'auto', true) !== 'UTF-8') {
231
        if (mb_detect_encoding($value, 'auto', true) !== 'UTF-8') {
Zeile 259... Zeile 243...
259
        if ($this->isInvalidChar($encoded)) {
243
        if ($this->isInvalidChar($encoded)) {
260
            $this->hasInvalidTokens = true;
244
            $this->hasInvalidTokens = true;
261
            return self::INVALID;
245
            return self::INVALID;
262
        }
246
        }
Zeile 263... Zeile -...
263
 
-
 
264
 
247
 
265
        return  self::GENERIC;
248
        return self::GENERIC;
Zeile 266... Zeile 249...
266
    }
249
    }
267
 
250
 
268
    protected function isValid(string $value) : bool
251
    protected function isValid(string $value): bool
269
    {
252
    {
Zeile 270... Zeile 253...
270
        return isset($this->charValue[$value]);
253
        return isset($this->charValue[$value]);
271
    }
254
    }
272
 
255
 
273
    protected function isNullType(string $value) : bool
256
    protected function isNullType(string $value): bool
Zeile 274... Zeile 257...
274
    {
257
    {
275
        return $value === "\0";
258
        return $value === "\0";
276
    }
259
    }
277
 
260
 
Zeile 278... Zeile 261...
278
    protected function isInvalidChar(string $value) : bool
261
    protected function isInvalidChar(string $value): bool
279
    {
262
    {
280
        return !preg_match(self::INVALID_CHARS_REGEX, $value);
263
        return !preg_match(self::INVALID_CHARS_REGEX, $value);
281
    }
264
    }
Zeile 282... Zeile 265...
282
 
265
 
283
    protected function isUTF8Invalid(string $value) : bool
266
    protected function isUTF8Invalid(string $value): bool
284
    {
267
    {
285
        return preg_match(self::VALID_UTF8_REGEX, $value) !== false;
268
        return preg_match(self::VALID_UTF8_REGEX, $value) !== false;
Zeile 286... Zeile 269...
286
    }
269
    }
287
 
270
 
288
    public function hasInvalidTokens() : bool
271
    public function hasInvalidTokens(): bool
289
    {
272
    {
290
        return $this->hasInvalidTokens;
273
        return $this->hasInvalidTokens;
291
    }
274
    }
292
 
275
 
293
    /**
276
    /**
294
     * getPrevious
277
     * getPrevious
Zeile 295... Zeile 278...
295
     *
278
     *
296
     * @return array
279
     * @return Token<int, string>
297
     */
280
     */
298
    public function getPrevious() : array
281
    public function getPrevious(): Token
299
    {
282
    {
300
        return $this->previous;
283
        return $this->previous;
301
    }
284
    }
302
 
285
 
303
    /**
286
    /**
Zeile 304... Zeile 287...
304
     * Lexical catchable patterns.
287
     * Lexical catchable patterns.
305
     *
288
     *
306
     * @return string[]
289
     * @return string[]
307
     */
290
     */
308
    protected function getCatchablePatterns() : array
291
    protected function getCatchablePatterns(): array
309
    {
292
    {
310
        return self::CATCHABLE_PATTERNS;
293
        return self::CATCHABLE_PATTERNS;
311
    }
294
    }
312
 
295
 
Zeile 313... Zeile 296...
313
    /**
296
    /**
314
     * Lexical non-catchable patterns.
297
     * Lexical non-catchable patterns.
315
     *
298
     *
316
     * @return string[]
299
     * @return string[]
Zeile 317... Zeile 300...
317
     */
300
     */
318
    protected function getNonCatchablePatterns() : array
301
    protected function getNonCatchablePatterns(): array
319
    {
302
    {
320
        return self::NON_CATCHABLE_PATTERNS;
303
        return self::NON_CATCHABLE_PATTERNS;
Zeile 321... Zeile 304...
321
    }
304
    }
322
 
305
 
323
    protected function getModifiers() : string
306
    protected function getModifiers(): string
324
    {
307
    {
Zeile 325... Zeile 308...
325
        return self::MODIFIERS;
308
        return self::MODIFIERS;
326
    }
309
    }
327
 
310
 
328
    public function getAccumulatedValues() : string
311
    public function getAccumulatedValues(): string
Zeile 329... Zeile 312...
329
    {
312
    {
330
        return $this->accumulator;
313
        return $this->accumulator;
331
    }
314
    }
332
 
315
 
333
    public function startRecording() : void
316
    public function startRecording(): void