Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StaticCalls.php
Go to the documentation of this file.
1 <?php
7 
13 {
17  protected $tokens;
18 
24  protected $staticCalls = [];
25 
31  protected $dependencies = [];
32 
36  public function __construct(Tokens $tokens)
37  {
38  $this->tokens = $tokens;
39  }
40 
47  protected function isTokenClass($token)
48  {
49  return is_array(
50  $token
51  ) && !(in_array(
52  $token[1],
53  ['static', 'self', 'parent']
54  ) || preg_match(
55  '#^\$#',
56  $token[1]
57  ));
58  }
59 
63  public function parse($token, $key)
64  {
65  if (is_array(
66  $token
67  ) && $token[0] == T_PAAMAYIM_NEKUDOTAYIM && $this->isTokenClass(
68  $this->tokens->getPreviousToken($key)
69  )
70  ) {
71  $this->staticCalls[] = $key;
72  }
73  }
74 
81  protected function getClassByStaticCall($staticCall)
82  {
83  $step = 1;
84  $staticClassParts = [];
85  while ($this->tokens->getTokenCodeByKey(
86  $staticCall - $step
87  ) == T_STRING || $this->tokens->getTokenCodeByKey(
88  $staticCall - $step
89  ) == T_NS_SEPARATOR) {
90  $staticClassParts[] = $this->tokens->getTokenValueByKey($staticCall - $step);
91  $step++;
92  }
93  return implode(array_reverse($staticClassParts));
94  }
95 
99  public function getDependencies(Uses $uses)
100  {
101  foreach ($this->staticCalls as $staticCall) {
102  $class = $this->getClassByStaticCall($staticCall);
103  if ($uses->hasUses()) {
105  }
106  $this->dependencies[] = $class;
107  }
108 
109  return $this->dependencies;
110  }
111 }
$_option $_optionId $class
Definition: date.phtml:13