Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Uses.php
Go to the documentation of this file.
1 <?php
7 
12 class Uses implements ParserInterface
13 {
19  protected $parseUse = false;
20 
26  protected $uses = [];
27 
33  public function hasUses()
34  {
35  return !empty($this->uses);
36  }
37 
41  protected function createEmptyItem()
42  {
43  $this->uses[] = '';
44  }
45 
53  {
54  if (preg_match('#^\\\\#', $class)) {
55  return $class;
56  }
57 
58  preg_match('#^([A-Za-z0-9_]+)(.*)$#', $class, $match);
59  foreach ($this->uses as $use) {
60  if (preg_match('#^([A-Za-z0-9_\\\\]+)\s+as\s+(.*)$#', $use, $useMatch) && $useMatch[2] == $match[1]) {
61  $class = $useMatch[1] . $match[2];
62  break;
63  }
64  $packages = explode('\\', $use);
65  end($packages);
66  $lastPackageKey = key($packages);
67  if ($packages[$lastPackageKey] == $match[1]) {
68  $class = $use . $match[2];
69  }
70  }
71  return $class;
72  }
73 
79  protected function appendToLast($value)
80  {
81  end($this->uses);
82  $this->uses[key($this->uses)] = ltrim($this->uses[key($this->uses)] . $value);
83  }
84 
90  protected function isParseInProgress()
91  {
92  return $this->parseUse;
93  }
94 
98  protected function stopParse()
99  {
100  $this->parseUse = false;
101  }
102 
106  protected function startParse()
107  {
108  $this->parseUse = true;
109  }
110 
114  public function parse($token, $key)
115  {
116  if (is_array($token)) {
117  if ($this->isParseInProgress()) {
118  $this->appendToLast($token[1]);
119  }
120  if (T_USE == $token[0]) {
121  $this->startParse();
122  $this->createEmptyItem();
123  }
124  } else {
125  if ($this->isParseInProgress()) {
126  if ($token == ';') {
127  $this->stopParse();
128  }
129  if ($token == ',') {
130  $this->createEmptyItem();
131  }
132  }
133  }
134  }
135 }
$_option $_optionId $class
Definition: date.phtml:13
$value
Definition: gender.phtml:16