/** * generates file with target grid (if not exists yet) * * @param DataSetDescriptorInterface $dataSet * @param string $extends * base class for grid * @return string full name of generated class */ protected function generateGrid(DataSetDescriptorInterface $dataSet, $extends) { $name = $dataSet->getName(); $className = $this->underscoreToCamelCase->filter($name) . "Grid"; $namespace = $this->params->getParam("moduleName") . "\\Grid"; $fullClassName = '\\' . $namespace . '\\' . $className; $gridClassFilePath = $this->moduleRoot() . "/src/" . $this->params->getParam("moduleName") . "/Grid/" . $className . ".php"; if (file_exists($gridClassFilePath)) { 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('grid.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'))); $file->setClass($class)->setDocBlock($docBlock); file_put_contents($gridClassFilePath, $file->generate()); return $fullClassName; }
/** * generates code for base filter and saves in file (overrides file if exists) * * @param DataSetDescriptorInterface $dataSet */ protected function generateBaseFilter(DataSetDescriptorInterface $dataSet) { $name = $dataSet->getName(); $className = "Base" . $this->underscoreToCamelCase->filter($name) . "Filter"; $namespace = $this->params->getParam("moduleName") . "\\Filter\\BaseFilter"; $fullClassName = '\\' . $namespace . '\\' . $className; $class = new ClassGenerator(); $class->setName($className); $class->setNamespaceName($namespace); $class->setExtendedClass($this->baseFilterParent); foreach ($this->baseFilterUses as $use) { $class->addUse($use); } $this->generateConstructor($class, $dataSet); $file = new FileGenerator(); $docBlock = new \Zend\Code\Generator\DocblockGenerator(sprintf($this->codeLibrary()->get('filter.generatedConfigDescription'), $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'))); $file->setClass($class)->setDocBlock($docBlock); $modelClassFilePath = $this->moduleRoot() . "/src/" . $this->params->getParam("moduleName") . "/Filter/BaseFilter/" . $className . ".php"; file_put_contents($modelClassFilePath, $file->generate()); return $fullClassName; }
/** * creates property for given field * * @param FieldDescriptorInterface $column * @param string $name * @return \Zend\Code\Generator\PropertyGenerator */ protected function createProperty(FieldDescriptorInterface $column, $name) { $type = $this->getFieldType($column); $docblock = new \Zend\Code\Generator\DocblockGenerator('Column: ' . $column->getName()); $docblock->setTag(array("name" => "var", "description" => $type)); if ($column instanceof ReferenceFieldInterface) { if ($column->referencedFieldName()) { $docblock->setLongDescription("Reference to " . $column->referencedDataSetName() . "." . $column->referencedFieldName()); } } $property = new \Zend\Code\Generator\PropertyGenerator(); $property->addFlag(\Zend\Code\Generator\PropertyGenerator::FLAG_PUBLIC); $property->setName(lcfirst($name)); $property->setDocBlock($docblock); return $property; }
/** * 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; }