Class luya\admin\openapi\phpdoc\PhpDocType
| Inheritance | luya\admin\openapi\phpdoc\PhpDocType | 
|---|---|
| Available since version | 3.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
| 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 Properties
| Property | Type | Description | Defined By | 
|---|---|---|---|
| $phpDocParser | luya\admin\openapi\phpdoc\PhpDocParser | luya\admin\openapi\phpdoc\PhpDocType | 
Public Methods
Protected Methods
| Method | Description | Defined By | 
|---|---|---|
| testValidClassName() | luya\admin\openapi\phpdoc\PhpDocType | 
Property Details
Contains the type like integer, string, noramlized as lowercase value.
Method Details
| 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;
}
            
        
| 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;
}
            
        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;
}
            
        
| public void getIsArray ( ) | 
                public function getIsArray()
{
    return StringHelper::contains('[]', $this->rawName) || in_array($this->name, [
        'array',
        'iterable',
    ]);
}
            
        
| public void getIsEmpty ( ) | 
                public function getIsEmpty()
{
    return empty($this->name) || $this->name == 'void';
}
            
        
| public void getIsObject ( ) | 
                public function getIsObject()
{
    return in_array($this->name, [
        'object',
        'resource',
    ]);
}
            
        
| public void getIsScalar ( ) | 
                public function getIsScalar()
{
    return in_array($this->rawName, [
        'bool',
        'boolean',
        'string',
        'int',
        'integer',
        'float',
        'double',
        'mixed',
    ]);
}
            
        
| public void getNoramlizeName ( ) | 
                public function getNoramlizeName()
{
    return $this->phpDocParser->typesTotype($this->name);
}
            
        
| 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;
}