-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathParameter.php
78 lines (72 loc) · 1.85 KB
/
Parameter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);
namespace Magento2\Helpers\Tokenizer;
/**
* Template constructions parameters tokenizer
*/
class Parameter extends AbstractTokenizer
{
/**
* Tokenize string and return getted parameters
*
* @return array
*/
public function tokenize()
{
$parameters = [];
$parameterName = '';
do {
if ($this->isWhiteSpace()) {
continue;
}
if ($this->char() !== '=') {
$parameterName .= $this->char();
} else {
$parameters[$parameterName] = $this->getValue();
$parameterName = '';
}
} while ($this->next());
return $parameters;
}
/**
* Get string value in parameters through tokenize
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getValue()
{
$this->next();
$value = '';
if ($this->isWhiteSpace()) {
return $value;
}
$quoteStart = $this->char() == "'" || $this->char() == '"';
if ($quoteStart) {
$breakSymbol = $this->char();
} else {
$breakSymbol = false;
$value .= $this->char();
}
while ($this->next()) {
if (!$breakSymbol && $this->isWhiteSpace()) {
break;
} elseif ($breakSymbol && $this->char() == $breakSymbol) {
break;
} elseif ($this->char() == '\\') {
$this->next();
if ($this->char() != '\\') {
$value .= '\\';
}
$value .= $this->char();
} else {
$value .= $this->char();
}
}
return $value;
}
}