|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / vendor / magento / framework / Code / Reader / |
Filename | /home/dev2.destoffenstraat.com/vendor/magento/framework/Code/Reader/SourceArgumentsReader.php |
Size | 3.66 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 07-Jan-2021 21:08 |
Last accessed | 22-Aug-2025 20:57 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Code\Reader;
class SourceArgumentsReader
{
/**
* Namespace separator
* @deprecated
* @see \Magento\Framework\Code\Reader\NamespaceResolver::NS_SEPARATOR
*/
const NS_SEPARATOR = '\\';
/**
* @var NamespaceResolver
*/
private $namespaceResolver;
/**
* @param NamespaceResolver|null $namespaceResolver
*/
public function __construct(NamespaceResolver $namespaceResolver = null)
{
$this->namespaceResolver = $namespaceResolver ?: new NamespaceResolver();
}
/**
* Read constructor argument types from source code and perform namespace resolution if required.
*
* @param \ReflectionClass $class
* @param bool $inherited
* @return array List of constructor argument types.
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function getConstructorArgumentTypes(
\ReflectionClass $class,
$inherited = false
) {
$output = [null];
if (!$class->getFileName() || false == $class->hasMethod(
'__construct'
) || !$inherited && $class->getConstructor()->class !== $class->getName()
) {
return $output;
}
//Reading parameters' types.
$params = $class->getConstructor()->getParameters();
/** @var string[] $types */
$types = [];
foreach ($params as $param) {
//For the sake of backward compatibility.
$typeName = '';
if ($param->isArray()) {
//For the sake of backward compatibility.
$typeName = 'array';
} else {
try {
$paramClass = $param->getClass();
if ($paramClass) {
$typeName = '\\' .$paramClass->getName();
}
} catch (\ReflectionException $exception) {
//If there's a problem loading a class then ignore it and
//just return it's name.
$typeName = '\\' .$param->getType()->getName();
}
}
$types[] = $typeName;
}
if (!$types) {
//For the sake of backward compatibility.
$types = [null];
}
return $types;
}
/**
* Perform namespace resolution if required and return fully qualified name.
*
* @param string $argument
* @param array $availableNamespaces
* @return string
* @deprecated 101.0.0
* @see getConstructorArgumentTypes
*/
protected function resolveNamespaces($argument, $availableNamespaces)
{
return $this->namespaceResolver->resolveNamespace($argument, $availableNamespaces);
}
/**
* Remove default value from argument.
*
* @param string $argument
* @param string $token
* @return string
*
* @deprecated 102.0.0 Not used anymore.
*/
protected function removeToken($argument, $token)
{
$position = strpos($argument, $token);
if (is_numeric($position)) {
return substr($argument, 0, $position);
}
return $argument;
}
/**
* Get all imported namespaces.
*
* @param array $file
* @return array
* @deprecated 101.0.0
* @see getConstructorArgumentTypes
*/
protected function getImportedNamespaces(array $file)
{
return $this->namespaceResolver->getImportedNamespaces($file);
}
}
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Code\Reader;
class SourceArgumentsReader
{
/**
* Namespace separator
* @deprecated
* @see \Magento\Framework\Code\Reader\NamespaceResolver::NS_SEPARATOR
*/
const NS_SEPARATOR = '\\';
/**
* @var NamespaceResolver
*/
private $namespaceResolver;
/**
* @param NamespaceResolver|null $namespaceResolver
*/
public function __construct(NamespaceResolver $namespaceResolver = null)
{
$this->namespaceResolver = $namespaceResolver ?: new NamespaceResolver();
}
/**
* Read constructor argument types from source code and perform namespace resolution if required.
*
* @param \ReflectionClass $class
* @param bool $inherited
* @return array List of constructor argument types.
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function getConstructorArgumentTypes(
\ReflectionClass $class,
$inherited = false
) {
$output = [null];
if (!$class->getFileName() || false == $class->hasMethod(
'__construct'
) || !$inherited && $class->getConstructor()->class !== $class->getName()
) {
return $output;
}
//Reading parameters' types.
$params = $class->getConstructor()->getParameters();
/** @var string[] $types */
$types = [];
foreach ($params as $param) {
//For the sake of backward compatibility.
$typeName = '';
if ($param->isArray()) {
//For the sake of backward compatibility.
$typeName = 'array';
} else {
try {
$paramClass = $param->getClass();
if ($paramClass) {
$typeName = '\\' .$paramClass->getName();
}
} catch (\ReflectionException $exception) {
//If there's a problem loading a class then ignore it and
//just return it's name.
$typeName = '\\' .$param->getType()->getName();
}
}
$types[] = $typeName;
}
if (!$types) {
//For the sake of backward compatibility.
$types = [null];
}
return $types;
}
/**
* Perform namespace resolution if required and return fully qualified name.
*
* @param string $argument
* @param array $availableNamespaces
* @return string
* @deprecated 101.0.0
* @see getConstructorArgumentTypes
*/
protected function resolveNamespaces($argument, $availableNamespaces)
{
return $this->namespaceResolver->resolveNamespace($argument, $availableNamespaces);
}
/**
* Remove default value from argument.
*
* @param string $argument
* @param string $token
* @return string
*
* @deprecated 102.0.0 Not used anymore.
*/
protected function removeToken($argument, $token)
{
$position = strpos($argument, $token);
if (is_numeric($position)) {
return substr($argument, 0, $position);
}
return $argument;
}
/**
* Get all imported namespaces.
*
* @param array $file
* @return array
* @deprecated 101.0.0
* @see getConstructorArgumentTypes
*/
protected function getImportedNamespaces(array $file)
{
return $this->namespaceResolver->getImportedNamespaces($file);
}
}