setDocBlock() публичный Метод

public setDocBlock ( Zend\Code\Generator\DocBlockGenerator $docBlock ) : self
$docBlock Zend\Code\Generator\DocBlockGenerator
Результат self
Пример #1
0
 /**
  * @param \Jungle\Syntax $syntax
  * @param \Jungle\SLR\Table $table
  *
  * @return \Zend\Code\Generator\ClassGenerator
  */
 public function build(Syntax $syntax, Table $table)
 {
     $this->class = new ClassGenerator('Test');
     $this->class->setDocBlock(new DocBlockGenerator('SLR parser', 'WARNING! THIS FILE AUTO GENERATED by JUNGLE. DO NOT EDIT IT!'));
     $this->class->addPropertyFromGenerator($this->getActionTableProperty($table));
     $this->class->addPropertyFromGenerator($this->getStackProperty());
     $this->buildParseMethod();
     $this->buildTokenizerMethod($syntax);
     $this->buildGetNextTokenMethod($syntax);
     $this->buildReduces($table->getReduces());
     return $this->class;
 }
Пример #2
0
 /**
  * Set class dock block
  *
  * @param array $docBlock
  * @return $this
  */
 public function setClassDocBlock(array $docBlock)
 {
     $docBlockObject = new \Zend\Code\Generator\DocBlockGenerator();
     $docBlockObject->setWordWrap(false);
     $this->_setDataToObject($docBlockObject, $docBlock, $this->_docBlockOptions);
     return parent::setDocBlock($docBlockObject);
 }
Пример #3
0
 /**
  * @param Tag $tagItem
  * @return ClassGenerator
  */
 protected function createClass(Tag $tagItem)
 {
     $className = ucfirst($this->stringToCamelCaseConverter->convert($tagItem->getName()));
     $class = new ClassGenerator();
     $class->setNamespaceName('Flex\\Code\\Html\\Tag');
     $class->setName($className);
     $class->addUse('Flex\\Code\\Html\\Tag\\Model\\AbstractTag');
     $class->setExtendedClass('AbstractTag');
     $implementedInterfaces = [];
     if ($tagItem->isGlobalAttributeAware()) {
         $implementedInterfaces[] = 'GlobalAttributeAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Attribute\\GlobalAttributeAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Attribute\\GlobalAttributeAwareTrait');
         $class->addTrait('GlobalAttributeAwareTrait');
     }
     if ($tagItem->isClipboardEventAware()) {
         $implementedInterfaces[] = 'ClipboardEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\ClipboardEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\ClipboardEventAwareTrait');
         $class->addTrait('ClipboardEventAwareTrait');
     }
     if ($tagItem->isFormEventAware()) {
         $implementedInterfaces[] = 'FormEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\FormEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\FormEventAwareTrait');
         $class->addTrait('FormEventAwareTrait');
     }
     if ($tagItem->isKeyboardEventAware()) {
         $implementedInterfaces[] = 'KeyboardEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\KeyboardEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\KeyboardEventAwareTrait');
         $class->addTrait('KeyboardEventAwareTrait');
     }
     if ($tagItem->isMediaEventAware()) {
         $implementedInterfaces[] = 'MediaEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MediaEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MediaEventAwareTrait');
         $class->addTrait('MediaEventAwareTrait');
     }
     if ($tagItem->isMiscEventAware()) {
         $implementedInterfaces[] = 'MiscEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MiscEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MiscEventAwareTrait');
         $class->addTrait('MiscEventAwareTrait');
     }
     if ($tagItem->isMouseEventAware()) {
         $implementedInterfaces[] = 'MouseEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MouseEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MouseEventAwareTrait');
         $class->addTrait('MouseEventAwareTrait');
     }
     if ($tagItem->isWindowEventAware()) {
         $implementedInterfaces[] = 'WindowEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\WindowEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\WindowEventAwareTrait');
         $class->addTrait('WindowEventAwareTrait');
     }
     $class->setImplementedInterfaces($implementedInterfaces);
     $docBlock = new DocBlockGenerator();
     $docBlock->setTag(new GenericTag('author', 'elnebuloso/flex-code-html-generator'));
     $docBlock->setTag(new GenericTag('link', $tagItem->getLink()));
     if (!is_null($tagItem->getShortDescription())) {
         $docBlock->setShortDescription($tagItem->getShortDescription());
     }
     if (!is_null($tagItem->getLongDescription())) {
         $docBlock->setLongDescription($tagItem->getLongDescription());
     }
     $class->setDocBlock($docBlock);
     return $class;
 }
Пример #4
0
 /**
  * Create view helper factory
  *
  * @return bool
  */
 public function createViewHelperFactory()
 {
     // get needed options to shorten code
     $moduleName = $this->requestOptions->getModuleName();
     $viewHelperClass = $this->requestOptions->getViewHelperClass();
     $viewHelperPath = $this->requestOptions->getViewHelperPath();
     $factoryClass = $viewHelperClass . 'Factory';
     $factoryFile = $factoryClass . '.php';
     $factoryFilePath = $viewHelperPath . $factoryFile;
     // check for factory class
     if (file_exists($factoryFilePath)) {
         throw new GeneratorException('The factory for this view helper exists already.');
     }
     // create controller class with class generator
     $code = new ClassGenerator();
     $code->setNamespaceName($moduleName . '\\View\\Helper');
     $code->addUse('Zend\\ServiceManager\\FactoryInterface');
     $code->addUse('Zend\\ServiceManager\\ServiceLocatorInterface');
     $code->setName($factoryClass);
     $code->setImplementedInterfaces(array('FactoryInterface'));
     $code->addMethodFromGenerator($this->generateCreateServiceMethod($viewHelperClass, 'viewHelperManager', 'viewHelper'));
     // add optional doc block
     if ($this->flagCreateApiDocs) {
         $code->setDocBlock(new DocBlockGenerator('Factory for ' . $viewHelperClass, 'Please add a proper description for the ' . $viewHelperClass . ' factory', array($this->generatePackageTag($moduleName))));
     }
     // create file with file generator
     $file = new FileGenerator();
     $file->setClass($code);
     // add optional doc block
     if ($this->flagCreateApiDocs) {
         $file->setDocBlock(new DocBlockGenerator('This file was generated by FrilleZFTool.', null, array($this->generatePackageTag($moduleName), $this->generateSeeTag())));
     }
     // write controller class
     if (!file_put_contents($factoryFilePath, $file->generate())) {
         return false;
     }
     return true;
 }
Пример #5
0
 private function getServiceCode()
 {
     $code = new ClassGenerator($this->service->getName(), $this->namespace, null, '\\SoapClient');
     $doc = $this->service->getDoc();
     if ($doc) {
         $docBlock = new DocBlockGenerator($doc);
         $code->setDocBlock($docBlock);
     }
     foreach ($this->service->getFunctions() as $function) {
         $method = new MethodGenerator($function->getMethod());
         $docBlock = new DocBlockGenerator($function->getDoc());
         foreach ($function->getParams() as $param) {
             $methodParam = new ParameterGenerator($param->getName());
             if (false === $param->isPrimitive()) {
                 $methodParam->setType('\\' . $this->getFullNamespace($param->getType()));
             }
             $method->setParameter($methodParam);
             $tag = new Tag();
             $tag->setName('property');
             $type = $param->getType();
             if (false === $param->isPrimitive()) {
                 $type = '\\' . $this->getFullNamespace($param->getType());
             }
             $tag->setDescription(sprintf('%s $%s', $type, $param->getName()));
             $docBlock->setTag($tag);
         }
         $tag = new Tag();
         $tag->setName('returns');
         $tag->setDescription("\\" . $this->getFullNamespace($function->getReturns()));
         $docBlock->setTag($tag);
         $method->setBody(sprintf('return $this->__soapCall("%s", func_get_args());', $function->getName()));
         $method->setDocBlock($docBlock);
         $code->addMethodFromGenerator($method);
     }
     return $code;
 }
 /**
  * creates Module class
  */
 protected function createModuleClass()
 {
     $moduleClassFilePath = $this->moduleRoot() . '/Module.php';
     if (!file_exists($moduleClassFilePath)) {
         $this->console('creating Module Class');
         $moduleClassFile = new FileGenerator();
         $moduleClassFile->setNamespace($this->params->getParam('moduleName'));
         $moduleClass = new ClassGenerator();
         $moduleClass->setDocBlock($this->getFileDocBlock())->getDocBlock()->setShortDescription($this->codeLibrary()->get('module.moduleClassDescription'));
         $moduleClass->setName('Module');
         // onbootstrap
         $onBootstrapMethod = new MethodGenerator();
         $onBootstrapMethod->setName('onBootstrap')->setBody($this->codeLibrary()->get('module.onBootstrap.body'));
         $onBootstrapMethod->setDocBlock(new DocBlockGenerator($this->codeLibrary()->get('module.onBootstrap.shortdescription'), $this->codeLibrary()->get('module.onBootstrap.longdescription'), array(new ParamTag('e', '\\Zend\\Mvc\\MvcEvent'))));
         $eventParam = new ParameterGenerator('e', '\\Zend\\Mvc\\MvcEvent');
         $onBootstrapMethod->setParameter($eventParam);
         $moduleClass->addMethodFromGenerator($onBootstrapMethod);
         // config
         $configMethod = new MethodGenerator('getConfig', array(), MethodGenerator::FLAG_PUBLIC, $this->codeLibrary()->get('module.config.body'), new DocBlockGenerator($this->codeLibrary()->get('module.config.shortdescription'), $this->codeLibrary()->get('module.config.longdescription'), array()));
         $moduleClass->addMethodFromGenerator($configMethod);
         // getAutoloaderConfig
         $getAutoloaderConfigMethod = new MethodGenerator('getAutoloaderConfig', array(), MethodGenerator::FLAG_PUBLIC, $this->codeLibrary()->get('module.getAutoloaderConfig.body'), new DocBlockGenerator($this->codeLibrary()->get('module.getAutoloaderConfig.shortdescription'), $this->codeLibrary()->get('module.getAutoloaderConfig.longdescription'), array()));
         $moduleClass->addMethodFromGenerator($getAutoloaderConfigMethod);
         // adding class method and generating file
         $moduleClassFile->setClass($moduleClass);
         file_put_contents($moduleClassFilePath, $moduleClassFile->generate());
     }
 }
Пример #7
0
 /**
  * Função geradora das entidades dos schemas e tabelas do banco de dados
  * 
  * @return \Cityware\Generator\Adapter\ModelAdapter
  */
 private function generatorClassEntity()
 {
     /* Lista os schemas do banco de dados */
     foreach ($this->oMetadata->getSchemas() as $valueSchema) {
         $tableNames = $this->oMetadata->getTableNames($valueSchema);
         $namespaceSchema = 'Orm\\' . $this->toCamelCase($valueSchema) . '\\Entities';
         /* Lista as tabelas do banco de dados */
         foreach ($tableNames as $tableName) {
             $multiPk = $primaryKey = $bodyExchangeArray = null;
             $class = new ClassGenerator();
             $class->setNamespaceName($namespaceSchema);
             $docBlockClass = DocBlockGenerator::fromArray(array('shortDescription' => 'Classe tipo model da tabela ' . $tableName . ' dentro do schema ' . $valueSchema, 'longDescription' => null));
             $class->setDocBlock($docBlockClass);
             $class->setName($this->toCamelCase($tableName));
             $class->addProperty('DBSCHEMA', $valueSchema, PropertyGenerator::FLAG_STATIC);
             $class->addProperty('DBTABLE', $tableName, PropertyGenerator::FLAG_STATIC);
             foreach ($this->oMetadata->getConstraints($tableName, $valueSchema) as $constraint) {
                 if (!$constraint->hasColumns()) {
                     continue;
                 }
                 if ($constraint->isPrimaryKey()) {
                     $columns = $constraint->getColumns();
                     if (count($columns) > 1) {
                         $multiPk = true;
                         $primaryKey = implode(', ', $columns);
                     } else {
                         $multiPk = false;
                         $primaryKey = $columns[0];
                     }
                     $class->addProperty('MULTIPK', $multiPk, PropertyGenerator::FLAG_STATIC);
                     $class->addProperty('PKCOLUMN', $primaryKey, PropertyGenerator::FLAG_STATIC);
                 }
             }
             /* Cria os metodos setter/getter e as variáveis das colunas da tabela */
             $table = $this->oMetadata->getTable($tableName, $valueSchema);
             /* Lista as colunas da tabela do banco de dados */
             foreach ($table->getColumns() as $column) {
                 $varName = $this->camelCase($column->getName());
                 $class->addProperty($varName, null, PropertyGenerator::FLAG_PRIVATE);
                 $methodGet = 'get' . $this->toCamelCase($column->getName());
                 $methodSet = 'set' . $this->toCamelCase($column->getName());
                 $docBlockSet = DocBlockGenerator::fromArray(array('shortDescription' => 'Setter da coluna ' . $column->getName(), 'longDescription' => null, 'tags' => array(new Tag\ParamTag($varName, $this->prepareSqlTypeDocBlock($column->getDataType())))));
                 $docBlockGet = DocBlockGenerator::fromArray(array('shortDescription' => 'Getter da coluna ' . $column->getName(), 'longDescription' => null, 'tags' => array(new Tag\ReturnTag(array('datatype' => $this->prepareSqlTypeDocBlock($column->getDataType()))))));
                 $bodyGet = 'return $this->' . $varName . ';';
                 $bodySet = '$this->' . $varName . ' = $' . $this->camelCase($column->getName()) . ';';
                 $class->addMethod($methodSet, array($this->camelCase($column->getName())), MethodGenerator::FLAG_PUBLIC, $bodySet, $docBlockSet);
                 $class->addMethod($methodGet, array(), MethodGenerator::FLAG_PUBLIC, $bodyGet, $docBlockGet);
                 $bodyExchangeArray .= '$this->' . $varName . ' = (isset($data["' . $column->getName() . '"])) ? $data["' . $column->getName() . '"] : null;' . "\n\n";
             }
             $docBlockExchangeArray = DocBlockGenerator::fromArray(array('shortDescription' => 'Função para settar todos os objetos por meio de array', 'longDescription' => null, 'tags' => array(new Tag\ParamTag('data', 'array'))));
             $class->addMethod('exchangeArray', array('data'), MethodGenerator::FLAG_PUBLIC, $bodyExchangeArray, $docBlockExchangeArray);
             $docBlockGetArrayCopy = DocBlockGenerator::fromArray(array('shortDescription' => 'Função para retornar os valores por meio de array dos objetos da classe', 'longDescription' => null, 'tags' => array(new Tag\ReturnTag(array('datatype' => 'mixed')))));
             $class->addMethod('getArrayCopy', array(), MethodGenerator::FLAG_PUBLIC, 'return get_object_vars($this);', $docBlockGetArrayCopy);
             $classCode = "<?php" . PHP_EOL;
             $classCode .= $class->generate();
             /*
              $idxConstraint = 0;
              foreach ($this->oMetadata->getConstraints($tableName, $valueSchema) as $constraint) {
             
              $typeConstraint = ($constraint->isPrimaryKey()) ? 'pk' : (($constraint->isForeignKey()) ? 'fk' : null);
              if (!empty($typeConstraint)) {
             
              $consName = $constraint->getName();
              $contraintObj = $this->oMetadata->getConstraint($consName, $tableName, $valueSchema);
             
              $constraintColumns = $contraintObj->getColumns();
              if (count($constraintColumns) > 1) {
              foreach ($constraintColumns as $valueConsColumns) {
              $this->aDatabase[$valueSchema][$tableName][$valueConsColumns]['constraints']['type'] = $typeConstraint;
              if ($typeConstraint === 'fk') {
              $this->aDatabase[$valueSchema][$tableName][$valueConsColumns]['constraints']['schemaRef'] = $contraintObj->getReferencedTableSchema();
              $this->aDatabase[$valueSchema][$tableName][$valueConsColumns]['constraints']['tableRef'] = $contraintObj->getReferencedTableName();
              $this->aDatabase[$valueSchema][$tableName][$valueConsColumns]['constraints']['columnsRef'] = $contraintObj->getReferencedColumns();
              }
              }
              } else {
              $this->aDatabase[$valueSchema][$tableName][$constraintColumns[0]]['constraints']['type'] = $typeConstraint;
              if ($typeConstraint === 'fk') {
              $this->aDatabase[$valueSchema][$tableName][$constraintColumns[0]]['constraints']['schemaRef'] = $contraintObj->getReferencedTableSchema();
              $this->aDatabase[$valueSchema][$tableName][$constraintColumns[0]]['constraints']['tableRef'] = $contraintObj->getReferencedTableName();
              $this->aDatabase[$valueSchema][$tableName][$constraintColumns[0]]['constraints']['columnsRef'] = $contraintObj->getReferencedColumns();
              }
              }
              }
             
              $idxConstraint++;
              }
             * 
             */
             file_put_contents($this->ormFolder . $this->toCamelCase($valueSchema) . DS . 'Entities' . DS . $this->toCamelCase($tableName) . '.php', $classCode);
             chmod($this->ormFolder . $this->toCamelCase($valueSchema) . DS . 'Entities' . DS . $this->toCamelCase($tableName) . '.php', 0644);
             $this->generatorClassEntityTable($valueSchema, $tableName);
         }
         //gera arquivo por tabela
     }
     return $this;
 }
 /**
  * generates file with target model (if not exists yet)
  *
  * @param DataSetDescriptorInterface $dataSet
  * @param string $extends
  *            base class for model
  * @return string name of generated class
  */
 protected function generateModel(DataSetDescriptorInterface $dataSet, $extends)
 {
     $name = $dataSet->getName();
     $className = $this->underscoreToCamelCase->filter($name);
     $namespace = $this->params->getParam("moduleName") . "\\Model";
     $fullClassName = '\\' . $namespace . '\\' . $className;
     $modelClassFilePath = $this->moduleRoot() . "/src/" . $this->params->getParam("moduleName") . "/Model/" . $className . ".php";
     if (file_exists($modelClassFilePath)) {
         return $fullClassName;
     }
     $class = new ClassGenerator();
     $class->setName($className);
     $class->setNamespaceName($namespace);
     $class->setExtendedClass($extends);
     $file = new FileGenerator();
     $docBlock = new \Zend\Code\Generator\DocblockGenerator(sprintf($this->codeLibrary()->get('model.standardConfigDescription'), $name));
     $docBlock->setTag(new GenericTag('author', $this->params->getParam('author')))->setTag(new GenericTag('project', $this->params->getParam('project')))->setTag(new GenericTag('license', $this->params->getParam('license')))->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
     $class->setDocBlock($docBlock);
     $file->setClass($class);
     file_put_contents($modelClassFilePath, $file->generate());
     return $fullClassName;
 }
Пример #9
0
    /**
     * Recurse the expose parameters - pass the entities full class name (including namespace)
     * @param array  $expose
     * @param string $fullClassName
     */
    protected function recurseParams(array $expose, $fullClassName)
    {
        // get ORM metadata for the current class
        $ormClassMetaData = $this->em->getClassMetadata($fullClassName);
        if (isset($this->classes[$fullClassName])) {
            $cg = $this->classes[$fullClassName];
        } else {
            $cg = new Generator\ClassGenerator();
            $cg->setName($fullClassName);
            $short = 'This class was generated by the drest-client tool, and should be treated as a plain data object';
            $long = <<<EOT
ANY ALTERATIONS WILL BE OVERWRITTEN if the classes are regenerated
The variables declared are exposed by the rest endpoint provided when generating these classes.
However depending on the operation (GET/POST/PUT etc) used some of these may not be populated / operational.
EOT;
            $docBlock = new Generator\DocBlockGenerator($short, $long);
            $cg->setDocBlock($docBlock);
            $cg->addMethods(array($this->getStaticCreateMethod($this->getTargetType($fullClassName))));
        }
        foreach ($expose as $key => $value) {
            if (is_array($value)) {
                if ($ormClassMetaData->hasAssociation($key)) {
                    $this->handleAssocProperty($key, $cg, $ormClassMetaData);
                    $assocMapping = $ormClassMetaData->getAssociationMapping($key);
                    $this->recurseParams($value, $assocMapping['targetEntity']);
                }
            } else {
                if ($ormClassMetaData->hasAssociation($value)) {
                    // This is an association field with no explicit include fields,
                    // include add data field (no relations)
                    $this->handleAssocProperty($value, $cg, $ormClassMetaData);
                    $assocMapping = $ormClassMetaData->getAssociationMapping($value);
                    $teCmd = $this->em->getClassMetadata($assocMapping['targetEntity']);
                    $this->recurseParams($teCmd->getColumnNames(), $assocMapping['targetEntity']);
                } else {
                    $this->handleNonAssocProperty($value, $cg);
                }
            }
        }
        // If the class is already set, overwrite it with it additional expose fields
        $this->classes[$fullClassName] = $cg;
    }
 /**
  * @param $className
  * @param $nameSpace
  * @return ClassGenerator
  */
 private function initClass($className, $nameSpace)
 {
     $user = $this->getCurrentStaff()->getStaffName();
     $date = date('Y-m-d H:i:s', time());
     $class = new ClassGenerator($className);
     $class->setDocBlock(DocBlockGenerator::fromArray(array('shortDescription' => 'System Generated Code', 'longDescription' => "User : {$user}\nDate : {$date}", 'tags' => array(array('name' => 'package', 'description' => $nameSpace)))));
     $class->setNamespaceName($nameSpace);
     return $class;
 }
 /**
  * generates base controller for given dataSet
  *
  * @param DataSetDescriptorInterface $dataSet
  * @return string generated controller full class name
  */
 protected function generateBaseController(DataSetDescriptorInterface $dataSet)
 {
     $name = $dataSet->getName();
     $className = 'Base' . $this->underscoreToCamelCase->filter($name) . 'Controller';
     $namespace = $this->params->getParam("moduleName") . '\\Controller\\Base';
     $fullClassName = '\\' . $namespace . '\\' . $className;
     $moduleName = $this->params->getParam("moduleName");
     $fileBase = new FileGenerator();
     $fileBase->setFilename($className);
     $fileBase->setNamespace($namespace);
     $class = new ClassGenerator();
     $class->setName($className)->setExtendedClass('\\' . $this->extendedController);
     $docBlock = new \Zend\Code\Generator\DocblockGenerator(sprintf($this->codeLibrary()->get('controller.standardBaseControllerDescription'), $name));
     $docBlock->setTag(new GenericTag('author', $this->params->getParam('author')))->setTag(new GenericTag('project', $this->params->getParam('project')))->setTag(new GenericTag('license', $this->params->getParam('license')))->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
     $class->setDocBlock($docBlock);
     $this->addControllerMethods($class, $dataSet);
     $fileBase->setClass($class);
     $modelClassFilePath = $this->moduleRoot() . "/src/" . $this->params->getParam("moduleName") . "/Controller/Base/" . $className . ".php";
     file_put_contents($modelClassFilePath, $fileBase->generate());
     return $fullClassName;
 }
Пример #12
0
 /**
  * Copied from ClassGenerator::fromReflection and tweaked slightly
  * @param ClassReflection $classReflection
  *
  * @return ClassGenerator
  */
 public function getGeneratorFromReflection(ClassReflection $classReflection)
 {
     // class generator
     $cg = new ClassGenerator($classReflection->getName());
     $cg->setSourceContent($cg->getSourceContent());
     $cg->setSourceDirty(false);
     if ($classReflection->getDocComment() != '') {
         $docblock = DocBlockGenerator::fromReflection($classReflection->getDocBlock());
         $docblock->setIndentation(Generator::$indentation);
         $cg->setDocBlock($docblock);
     }
     $cg->setAbstract($classReflection->isAbstract());
     // set the namespace
     if ($classReflection->inNamespace()) {
         $cg->setNamespaceName($classReflection->getNamespaceName());
     }
     /* @var \Zend\Code\Reflection\ClassReflection $parentClass */
     $parentClass = $classReflection->getParentClass();
     if ($parentClass) {
         $cg->setExtendedClass('\\' . ltrim($parentClass->getName(), '\\'));
         $interfaces = array_diff($classReflection->getInterfaces(), $parentClass->getInterfaces());
     } else {
         $interfaces = $classReflection->getInterfaces();
     }
     $interfaceNames = array();
     foreach ($interfaces as $interface) {
         /* @var \Zend\Code\Reflection\ClassReflection $interface */
         $interfaceNames[] = $interface->getName();
     }
     $cg->setImplementedInterfaces($interfaceNames);
     $properties = array();
     foreach ($classReflection->getProperties() as $reflectionProperty) {
         if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
             $property = PropertyGenerator::fromReflection($reflectionProperty);
             $property->setIndentation(Generator::$indentation);
             $properties[] = $property;
         }
     }
     $cg->addProperties($properties);
     $methods = array();
     foreach ($classReflection->getMethods() as $reflectionMethod) {
         $className = $cg->getNamespaceName() ? $cg->getNamespaceName() . "\\" . $cg->getName() : $cg->getName();
         if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
             $method = MethodGenerator::fromReflection($reflectionMethod);
             $method->setBody(preg_replace("/^\\s+/m", '', $method->getBody()));
             $method->setIndentation(Generator::$indentation);
             $methods[] = $method;
         }
     }
     $cg->addMethods($methods);
     return $cg;
 }
Пример #13
0
 /**
  * Create a skeleton class from the given XML type
  *
  * @param Type $type
  * @return \Zend\Code\Generator\ClassGenerator
  */
 protected function createClassFromType(Type $type)
 {
     $targetNamespace = $type->getSchema()->getTargetNamespace();
     $namespace = $this->namespaceInflector->inflectNamespace($type);
     // create the class
     $class = new ClassGenerator();
     $class->setName($type->getName());
     if ($namespace) {
         $class->setNamespaceName($namespace);
     }
     // set the class documentation
     $docDescription = new Html2Text($type->getDoc());
     $doc = new DocBlockGenerator($docDescription->getText());
     $doc->setTag(new GenericTag('xmlns', $targetNamespace));
     $class->setDocBlock($doc);
     return $class;
 }