Zend\Code\Generator\ClassGenerator::generate PHP Method

generate() public method

public generate ( )
    public function generate()
    {
        if (!$this->isSourceDirty()) {
            $output = $this->getSourceContent();
            if (!empty($output)) {
                return $output;
            }
        }
        $indent = $this->getIndentation();
        $output = '';
        if (null !== ($namespace = $this->getNamespaceName())) {
            $output .= 'namespace ' . $namespace . ';' . self::LINE_FEED . self::LINE_FEED;
        }
        $uses = $this->getUses();
        if (!empty($uses)) {
            foreach ($uses as $use) {
                $output .= 'use ' . $use . ';' . self::LINE_FEED;
            }
            $output .= self::LINE_FEED;
        }
        if (null !== ($docBlock = $this->getDocBlock())) {
            $docBlock->setIndentation('');
            $output .= $docBlock->generate();
        }
        if ($this->isAbstract()) {
            $output .= 'abstract ';
        } elseif ($this->isFinal()) {
            $output .= 'final ';
        }
        $output .= static::OBJECT_TYPE . ' ' . $this->getName();
        if (!empty($this->extendedClass)) {
            $output .= ' extends ' . $this->generateShortOrCompleteClassname($this->extendedClass);
        }
        $implemented = $this->getImplementedInterfaces();
        if (!empty($implemented)) {
            $implemented = array_map([$this, 'generateShortOrCompleteClassname'], $implemented);
            $output .= ' ' . static::IMPLEMENTS_KEYWORD . ' ' . implode(', ', $implemented);
        }
        $output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED;
        $output .= $this->traitUsageGenerator->generate();
        $constants = $this->getConstants();
        foreach ($constants as $constant) {
            $output .= $constant->generate() . self::LINE_FEED . self::LINE_FEED;
        }
        $properties = $this->getProperties();
        foreach ($properties as $property) {
            $output .= $property->generate() . self::LINE_FEED . self::LINE_FEED;
        }
        $methods = $this->getMethods();
        foreach ($methods as $method) {
            $output .= $method->generate() . self::LINE_FEED;
        }
        $output .= self::LINE_FEED . '}' . self::LINE_FEED;
        return $output;
    }

Usage Example

 /**
  * @param $version
  * @param $api
  *
  * @return string
  */
 private function generateFileContent($version, $api)
 {
     $docBlock = new DocBlockGenerator('SellerCenter SDK Version Class', 'This file is auto generated, please do not edit it manually!!!');
     $properties = [new PropertyGenerator('VERSION_NUMBER', $version, PropertyGenerator::FLAG_CONSTANT), new PropertyGenerator('API', $api, PropertyGenerator::FLAG_CONSTANT)];
     $class = new ClassGenerator('Version', 'SellerCenter\\SDK', null, null, [], $properties, [], $docBlock);
     return $class->generate();
 }
All Usage Examples Of Zend\Code\Generator\ClassGenerator::generate