Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceArgumentsReader.php
Go to the documentation of this file.
1 <?php
7 
9 {
15  const NS_SEPARATOR = '\\';
16 
20  private $namespaceResolver;
21 
25  public function __construct(NamespaceResolver $namespaceResolver = null)
26  {
27  $this->namespaceResolver = $namespaceResolver ?: new NamespaceResolver();
28  }
29 
40  public function getConstructorArgumentTypes(
41  \ReflectionClass $class,
42  $inherited = false
43  ) {
44  $output = [null];
45  if (!$class->getFileName() || false == $class->hasMethod(
46  '__construct'
47  ) || !$inherited && $class->getConstructor()->class !== $class->getName()
48  ) {
49  return $output;
50  }
51 
52  //Reading parameters' types.
53  $params = $class->getConstructor()->getParameters();
55  $types = [];
56  foreach ($params as $param) {
57  //For the sake of backward compatibility.
58  $typeName = '';
59  if ($param->isArray()) {
60  //For the sake of backward compatibility.
61  $typeName = 'array';
62  } else {
63  try {
64  $paramClass = $param->getClass();
65  if ($paramClass) {
66  $typeName = '\\' .$paramClass->getName();
67  }
68  } catch (\ReflectionException $exception) {
69  //If there's a problem loading a class then ignore it and
70  //just return it's name.
71  $typeName = '\\' .$param->getType()->getName();
72  }
73  }
74  $types[] = $typeName;
75  }
76  if (!$types) {
77  //For the sake of backward compatibility.
78  $types = [null];
79  }
80 
81  return $types;
82  }
83 
93  protected function resolveNamespaces($argument, $availableNamespaces)
94  {
95  return $this->namespaceResolver->resolveNamespace($argument, $availableNamespaces);
96  }
97 
107  protected function removeToken($argument, $token)
108  {
109  $position = strpos($argument, $token);
110  if (is_numeric($position)) {
111  return substr($argument, 0, $position);
112  }
113  return $argument;
114  }
115 
124  protected function getImportedNamespaces(array $file)
125  {
126  return $this->namespaceResolver->getImportedNamespaces($file);
127  }
128 }
$_option $_optionId $class
Definition: date.phtml:13
__construct(NamespaceResolver $namespaceResolver=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18