Zephir\ClassDefinition::getType PHP Method

getType() public method

Returns the class type
public getType ( ) : string
return string
    public function getType()
    {
        return $this->type;
    }

Usage Example

Exemplo n.º 1
0
    /**
     * Build class
     *
     * @param ClassDefinition $class
     * @param string $indent
     * @return string
     */
    protected function buildClass(ClassDefinition $class, $indent)
    {
        $source = <<<EOF
<?php

namespace {$class->getNamespace()};


EOF;
        $source .= new DocBlock($class->getDocBlock(), '') . "\n";
        if ($class->isFinal()) {
            $source .= 'final ';
        } elseif ($class->isAbstract()) {
            $source .= 'abstract ';
        }
        $source .= $class->getType() . ' ' . $class->getName();
        if ($class->getExtendsClass()) {
            $extendsClassDefinition = $class->getExtendsClassDefinition();
            if (!$extendsClassDefinition) {
                throw new \RuntimeException('Class "' . $class->getName() . '" does not have a extendsClassDefinition');
            }
            $source .= ' extends ' . ($extendsClassDefinition->isBundled() ? '' : '\\') . $extendsClassDefinition->getCompleteName();
        }
        if ($implementedInterfaces = $class->getImplementedInterfaces()) {
            $interfaces = array_map(function ($val) {
                return '\\' . $val;
            }, $implementedInterfaces);
            $keyword = $class->getType() == 'interface' ? ' extends ' : ' implements ';
            $source .= $keyword . join(', ', $interfaces);
        }
        $source .= PHP_EOL . '{' . PHP_EOL;
        foreach ($class->getConstants() as $constant) {
            $source .= $this->buildConstant($constant, $indent) . PHP_EOL . PHP_EOL;
        }
        foreach ($class->getProperties() as $property) {
            $source .= $this->buildProperty($property, $indent) . PHP_EOL . PHP_EOL;
        }
        $source .= PHP_EOL;
        foreach ($class->getMethods() as $method) {
            if ($method->isInternal()) {
                continue;
            }
            $source .= $this->buildMethod($method, $class->getType() === 'interface', $indent) . "\n\n";
        }
        return $source . '}' . PHP_EOL;
    }
All Usage Examples Of Zephir\ClassDefinition::getType