/** * * @param unknown $className * @param unknown $nameSpace * @param unknown $value */ private function generateEntityFileClassFinder($className, $nameSpace, $value) { // Passing configuration to the constructor: $class = new \Zend\Code\Generator\ClassGenerator(); $class->setName($className . "Finder"); $class->setNamespaceName($nameSpace); $class->setExtendedClass(self::BASE_DB_FINDER); $class->addMethod('__construct', array(array("name" => "table")), \Zend\Code\Generator\MethodGenerator::FLAG_PUBLIC, 'parent::__construct ( $table );'); $file = new \Zend\Code\Generator\FileGenerator(array('classes' => array($class))); // Render the generated file $file->generate(); $classFile = DOC_ROOT . '/module/' . $this->params["directory_location"] . "/" . $value . 'Finder.php'; if (!file_exists($classFile)) { fopen($classFile, "w"); $returnFlag = file_put_contents($classFile, $file->generate()); } if ($returnFlag > 0) { echo "... <span class='glyphicon glyphicon-ok text text-success'></span>"; } else { echo "... <span class='glyphicon glyphicon-remove text text-danger'></span> (not written)"; } }
/** * Add property from PropertyGenerator * * @param Zend\Code\Generator\PropertyGenerator $property * @throws InvalidArgumentException * @return Magento_Di_Generator_CodeGenerator_Zend */ public function addPropertyFromGenerator(Zend\Code\Generator\PropertyGenerator $property) { if (!is_string($property->getName())) { throw new InvalidArgumentException('addPropertyFromGenerator() expects string for name'); } return parent::addPropertyFromGenerator($property); }
public function generate(PHPClass $type) { $class = new \Zend\Code\Generator\ClassGenerator(); $docblock = new DocBlockGenerator("Class representing " . $type->getName()); if ($type->getDoc()) { $docblock->setLongDescription($type->getDoc()); } $class->setNamespaceName($type->getNamespace() ?: NULL); $class->setName($type->getName()); $class->setDocblock($docblock); if ($extends = $type->getExtends()) { if ($p = $extends->isSimpleType()) { $this->handleProperty($class, $p); $this->handleValueMethod($class, $p, $extends); } else { $class->setExtendedClass($extends->getName()); if ($extends->getNamespace() != $type->getNamespace()) { if ($extends->getName() == $type->getName()) { $class->addUse($type->getExtends()->getFullName(), $extends->getName() . "Base"); $class->setExtendedClass($extends->getName() . "Base"); } else { $class->addUse($extends->getFullName()); } } } } if ($this->handleBody($class, $type)) { return $class; } }