Class luya\admin\openapi\phpdoc\PhpDocType

Inheritanceluya\admin\openapi\phpdoc\PhpDocType
Available since version3.2.0
Source Code https://github.com/luyadev/luya-module-admin/blob/master/src/openapi/phpdoc/PhpDocType.php

A Type Object whether for Return or Param.

Public Properties

Hide inherited properties

Property Type Description Defined By
$name string Contains the type like integer, string, noramlized as lowercase value. luya\admin\openapi\phpdoc\PhpDocType
$rawName string Contains the original raw name. luya\admin\openapi\phpdoc\PhpDocType

Protected Methods

Hide inherited methods

Method Description Defined By
testValidClassName() luya\admin\openapi\phpdoc\PhpDocType

Property Details

Hide inherited properties

$name public property

Contains the type like integer, string, noramlized as lowercase value.

public string $name null
$phpDocParser protected property
$rawName public property

Contains the original raw name.

public string $rawName null

Method Details

Hide inherited methods

__construct() public method

public void __construct ( luya\admin\openapi\phpdoc\PhpDocParser $phpDocParser, $type )
$phpDocParser
$type

                public function __construct(PhpDocParser $phpDocParser, $type)
{
    $this->rawName = (string) $type;
    $this->name = $phpDocParser->normalizeTypes($type);
    $this->phpDocParser = $phpDocParser;
}

            
getClassName() public method

public void getClassName ( )

                public function getClassName()
{
    if ($this->_className !== null) {
        return $this->_className;
    }
    if ($this->getIsScalar() || $this->getIsEmpty()) {
        $this->_className = false;
        return false;
    }
    // array notation like Users[]
    if (StringHelper::contains('[]', $this->rawName)) {
        $className = str_replace("[]", '', $this->rawName);
        if (($class = $this->testValidClassName($className))) {
            $this->_className = $class;
            return $class;
        }
    }
    if (($class = $this->testValidClassName($this->rawName))) {
        $this->_className = $class;
        return $class;
    }
    if (($class = $this->testValidClassName($this->name))) {
        $this->_className = $class;
        return $class;
    }
    $this->_className = false;
    return false;
}

            
getClassPhpDocParser() public method

Get PhpDocParser from className definition.

public luya\admin\openapi\phpdoc\PhpDocParser getClassPhpDocParser ( )

                public function getClassPhpDocParser()
{
    if ($this->_phpDocParser === null) {
        $this->_phpDocParser = new PhpDocParser(new ReflectionClass($this->getClassName()));
    }
    return $this->_phpDocParser;
}

            
getIsArray() public method

public void getIsArray ( )

                public function getIsArray()
{
    return StringHelper::contains('[]', $this->rawName) || in_array($this->name, [
        'array',
        'iterable',
    ]);
}

            
getIsClass() public method

public void getIsClass ( )

                public function getIsClass()
{
    return !empty($this->getClassName());
}

            
getIsEmpty() public method

public void getIsEmpty ( )

                public function getIsEmpty()
{
    return empty($this->name) || $this->name == 'void';
}

            
getIsObject() public method

public void getIsObject ( )

                public function getIsObject()
{
    return in_array($this->name, [
        'object',
        'resource',
    ]);
}

            
getIsScalar() public method

public void getIsScalar ( )

                public function getIsScalar()
{
    return in_array($this->rawName, [
        'bool',
        'boolean',
        'string',
        'int',
        'integer',
        'float',
        'double',
        'mixed',
    ]);
}

            
getIsVoid() public method

public void getIsVoid ( )

                public function getIsVoid()
{
    return $this->name == 'void';
}

            
getNoramlizeName() public method

public void getNoramlizeName ( )

                public function getNoramlizeName()
{
    return $this->phpDocParser->typesTotype($this->name);
}

            
testValidClassName() protected method

protected void testValidClassName ( $className )
$className

                protected function testValidClassName($className)
{
    if (class_exists($className)) {
        return $className;
    }
    // test relative classNames when objects are in the same namespace
    $absoluteClassName = $this->phpDocParser->reflection->getNamespaceName() . '\\' . $className;
    if (class_exists($absoluteClassName)) {
        return $absoluteClassName;
    }
    // Find alias definition `XYZ as ABC`
    $ensureClassName = $this->phpDocParser->ensureClassName($className);
    if ($ensureClassName && class_exists($ensureClassName)) {
        return $ensureClassName;
    }
    return false;
}