private function writeApiFile() { $file = $this->path . DIRECTORY_SEPARATOR . 'Api.php'; if (file_exists($file) && class_exists($this->namespace . '\\Api')) { $class = new ClassReflection($this->namespace . '\\Api'); $apiClass = ClassGenerator::fromReflection($class); } else { $apiClass = new ClassGenerator('Api', $this->namespace, null, 'OpenStack\\Common\\Api\\AbstractApi'); } if (!$apiClass->hasMethod('__construct')) { $apiClass->addProperty('params', null, PropertyGenerator::FLAG_PRIVATE); $apiClass->addMethod('__construct', [], MethodGenerator::FLAG_PUBLIC, '$this->params = new Params;'); } foreach ($this->operations as $operation) { $path = str_replace(['{', '}'], '', $operation['path']); $name = strtolower($operation['method']) . ucfirst(substr($path, strrpos($path, DIRECTORY_SEPARATOR) + 1)); if ($apiClass->hasMethod($name)) { continue; } foreach ($operation['params'] as $kName => $arr) { $operation['params'][$kName] = '$this->params->' . $kName . ucfirst($arr['location']) . '()'; } $body = sprintf("return %s;", $this->arrayEncoder->encode($operation, ['array.align' => true])); $body = str_replace("'\$", '$', $body); $body = str_replace("()'", '()', $body); $docblock = new DocBlockGenerator(sprintf("Returns information about %s %s HTTP operation", $operation['method'], $operation['path']), null, [new ReturnTag(['array'])]); $apiClass->addMethod($name, [], MethodGenerator::FLAG_PUBLIC, $body, $docblock); } $output = sprintf("<?php\n\n%s", $apiClass->generate()); file_put_contents($file, $output); }
/** * Dynamically scope an audit class */ public function loadClass($auditClassName, $type) { $foundClassName = false; foreach ($this->getAuditEntities() as $className => $classOptions) { if ($this->getAuditObjectManager()->getRepository('ZF\\Doctrine\\Audit\\Entity\\AuditEntity')->generateClassName($className) == $auditClassName) { $foundClassName = true; break; } } if (!$foundClassName) { return false; } // Get fields from target entity $metadataFactory = $this->getObjectManager()->getMetadataFactory(); $auditedClassMetadata = $metadataFactory->getMetadataFor($className); $fields = $auditedClassMetadata->getFieldNames(); $identifiers = $auditedClassMetadata->getFieldNames(); $auditClass = new ClassGenerator(); $auditClass->setNamespaceName("ZF\\Doctrine\\Audit\\RevisionEntity"); $auditClass->setName(str_replace('\\', '_', $className)); $auditClass->setExtendedClass('AbstractAudit'); // Add revision reference getter and setter $auditClass->addProperty('revisionEntity', null, PropertyGenerator::FLAG_PROTECTED); $auditClass->addMethod('getRevisionEntity', array(), MethodGenerator::FLAG_PUBLIC, " return \$this->revisionEntity;"); $auditClass->addMethod('setRevisionEntity', array('value'), MethodGenerator::FLAG_PUBLIC, " \$this->revisionEntity = \$value;\n\nreturn \$this;\n "); // Generate audit entity foreach ($fields as $field) { $auditClass->addProperty($field, null, PropertyGenerator::FLAG_PROTECTED); } foreach ($auditedClassMetadata->getAssociationNames() as $associationName) { $auditClass->addProperty($associationName, null, PropertyGenerator::FLAG_PROTECTED); $fields[] = $associationName; } $auditClass->addMethod('getAssociationMappings', array(), MethodGenerator::FLAG_PUBLIC, "return unserialize('" . serialize($auditedClassMetadata->getAssociationMappings()) . "');"); // Add exchange array method $setters = array(); foreach ($fields as $fieldName) { $setters[] = '$this->' . $fieldName . ' = (isset($data["' . $fieldName . '"])) ? $data["' . $fieldName . '"]: null;'; $arrayCopy[] = " \"{$fieldName}\"" . ' => $this->' . $fieldName; } $auditClass->addMethod('getArrayCopy', array(), MethodGenerator::FLAG_PUBLIC, "return array(\n" . implode(",\n", $arrayCopy) . "\n);"); $auditClass->addMethod('exchangeArray', array('data'), MethodGenerator::FLAG_PUBLIC, implode("\n", $setters)); // Add function to return the entity class this entity audits $auditClass->addMethod('getAuditedEntityClass', array(), MethodGenerator::FLAG_PUBLIC, " return '" . addslashes($className) . "';"); eval($auditClass->generate()); return true; }
public function generate() { $gen = new ClassGenerator($this->name); $fnGetter = $this->fnGetter; foreach ($this->options["properties"] as $prop => $type) { $c = ucfirst($prop); $gen->addProperty($prop, null, PropertyGenerator::FLAG_PRIVATE); $gen->addMethod("get" . $c, [], MethodGenerator::FLAG_PUBLIC, $fnGetter($prop, $type), "???"); } return $gen->generate(); }
/** * @group ZF-7361 */ public function testHasProperty() { $classGenerator = new ClassGenerator(); $classGenerator->addProperty('propertyOne'); $this->assertTrue($classGenerator->hasProperty('propertyOne')); }
/** * Dynamically scope an audit class * * @param string $className * @return false|string */ public function loadClass($className, $type) { $moduleOptions = \ZF\Doctrine\Audit\Module::getModuleOptions(); if (!$moduleOptions) { return; } $entityManager = $moduleOptions->getEntityManager(); $auditClass = new ClassGenerator(); // Build a discovered many to many join class $joinClasses = $moduleOptions->getJoinClasses(); if (in_array($className, array_keys($joinClasses))) { $auditClass->setNamespaceName("ZF\\Doctrine\\Audit\\Entity"); $auditClass->setName($className); $auditClass->setExtendedClass('AbstractAudit'); $auditClass->addProperty('id', null, PropertyGenerator::FLAG_PROTECTED); $auditClass->addProperty('targetRevisionEntity', null, PropertyGenerator::FLAG_PROTECTED); $auditClass->addProperty('sourceRevisionEntity', null, PropertyGenerator::FLAG_PROTECTED); $auditClass->addMethod('getTargetRevisionEntity', array(), MethodGenerator::FLAG_PUBLIC, 'return $this->targetRevisionEntity;'); $auditClass->addMethod('getSourceRevisionEntity', array(), MethodGenerator::FLAG_PUBLIC, 'return $this->sourceRevisionEntity;'); $auditClass->addMethod('getId', array(), MethodGenerator::FLAG_PUBLIC, 'return $this->id;'); $auditClass->addMethod('setTargetRevisionEntity', array(ParameterGenerator::fromArray(array('name' => 'value', 'type' => '\\ZF\\Doctrine\\Audit\\Entity\\RevisionEntity'))), MethodGenerator::FLAG_PUBLIC, '$this->targetRevisionEntity = $value;' . "\n" . 'return $this;'); $auditClass->addMethod('setSourceRevisionEntity', array(ParameterGenerator::fromArray(array('name' => 'value', 'type' => '\\ZF\\Doctrine\\Audit\\Entity\\RevisionEntity'))), MethodGenerator::FLAG_PUBLIC, '$this->sourceRevisionEntity = $value;' . "\n" . 'return $this;'); # print_r($auditClass->generate()); # die(); eval($auditClass->generate()); return; } // Add revision reference getter and setter $auditClass->addProperty($moduleOptions->getRevisionEntityFieldName(), null, PropertyGenerator::FLAG_PROTECTED); $auditClass->addMethod('get' . $moduleOptions->getRevisionEntityFieldName(), array(), MethodGenerator::FLAG_PUBLIC, " return \$this->" . $moduleOptions->getRevisionEntityFieldName() . ";"); $auditClass->addMethod('set' . $moduleOptions->getRevisionEntityFieldName(), array('value'), MethodGenerator::FLAG_PUBLIC, " \$this->" . $moduleOptions->getRevisionEntityFieldName() . " = \$value;\nreturn \$this;\r\n "); // Verify this autoloader is used for target class #FIXME: why is this sent work outside the set namespace? foreach ($moduleOptions->getAuditedClassNames() as $targetClass => $targetClassOptions) { $auditClassName = 'ZF\\Doctrine\\Audit\\Entity\\' . str_replace('\\', '_', $targetClass); if ($auditClassName == $className) { $currentClass = $targetClass; } $autoloadClasses[] = $auditClassName; } if (!in_array($className, $autoloadClasses)) { return; } // Get fields from target entity $metadataFactory = $entityManager->getMetadataFactory(); $auditedClassMetadata = $metadataFactory->getMetadataFor($currentClass); $fields = $auditedClassMetadata->getFieldNames(); $identifiers = $auditedClassMetadata->getFieldNames(); $service = \ZF\Doctrine\Audit\Module::getModuleOptions()->getAuditService(); // Generate audit entity foreach ($fields as $field) { $auditClass->addProperty($field, null, PropertyGenerator::FLAG_PROTECTED); } foreach ($auditedClassMetadata->getAssociationNames() as $associationName) { $auditClass->addProperty($associationName, null, PropertyGenerator::FLAG_PROTECTED); $fields[] = $associationName; } $auditClass->addMethod('getAssociationMappings', array(), MethodGenerator::FLAG_PUBLIC, "return unserialize('" . serialize($auditedClassMetadata->getAssociationMappings()) . "');"); // Add exchange array method $setters = array(); foreach ($fields as $fieldName) { $setters[] = '$this->' . $fieldName . ' = (isset($data["' . $fieldName . '"])) ? $data["' . $fieldName . '"]: null;'; $arrayCopy[] = " \"{$fieldName}\"" . ' => $this->' . $fieldName; } $auditClass->addMethod('getArrayCopy', array(), MethodGenerator::FLAG_PUBLIC, "return array(\n" . implode(",\n", $arrayCopy) . "\n);"); $auditClass->addMethod('exchangeArray', array('data'), MethodGenerator::FLAG_PUBLIC, implode("\n", $setters)); // Add function to return the entity class this entity audits $auditClass->addMethod('getAuditedEntityClass', array(), MethodGenerator::FLAG_PUBLIC, " return '" . addslashes($currentClass) . "';"); $auditClass->setNamespaceName("ZF\\Doctrine\\Audit\\Entity"); $auditClass->setName(str_replace('\\', '_', $currentClass)); $auditClass->setExtendedClass('AbstractAudit'); # $auditedClassMetadata = $metadataFactory->getMetadataFor($currentClass); $auditedClassMetadata = $metadataFactory->getMetadataFor($currentClass); foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) { if (isset($mapping['joinTable']['name'])) { $auditJoinTableClassName = "ZF\\Doctrine\\Audit\\Entity\\" . str_replace('\\', '_', $mapping['joinTable']['name']); $auditEntities[] = $auditJoinTableClassName; $moduleOptions->addJoinClass($auditJoinTableClassName, $mapping); } } # if ($auditClass->getName() == 'AppleConnect_Entity_UserAuthenticationLog') { # echo '<pre>'; # echo($auditClass->generate()); # die(); # } eval($auditClass->generate()); # die(); return true; }
/** * 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; }
/** * @param string $sourceFile * @return string */ protected function generateClass($sourceFile) { $sourceContent = json_decode(file_get_contents($sourceFile)); $class = new ClassGenerator(); $className = null; $mappingClasses = array(); $propNameMap = $this->setPropNameMap($sourceContent); $isCollection = false; foreach ($sourceContent as $property => $value) { $ourPropertyName = array_search($property, $propNameMap); if ($ourPropertyName) { $property = $ourPropertyName; } if ($property === '@name') { //Class name $className = $value; if ($this->namespace) { $class->setNamespaceName($this->namespace); } $class->setName($value); } elseif ($property === '@type') { continue; } elseif ($value === 'number' || $value === 'int' || $value === 'integer') { //Create property type number $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED); $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, 'int')), MethodGenerator::fromArray($this->generateSetMethod($property, 'int')))); } elseif ($value === 'float' || $value === 'double' || $value === 'real') { //Create property type number $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED); $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, $value)), MethodGenerator::fromArray($this->generateSetMethod($property, $value)))); } elseif ($value === 'string') { //Create property type string $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED); $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, $value)), MethodGenerator::fromArray($this->generateSetMethod($property, $value)))); } elseif ($value === 'date') { //Create property type date $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED); $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, 'string')), MethodGenerator::fromArray($this->generateSetMethod($property, 'string')))); } elseif ($value === 'array') { //Create property type date $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED); $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, 'array')), MethodGenerator::fromArray($this->generateSetMethod($property, 'array')))); } elseif ($value === 'boolean' || $value === 'bool') { //Create property type boolean $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED); $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, $value)), MethodGenerator::fromArray($this->generateSetMethod($property, $value)))); } elseif ($property === "@model") { if ($this->namespace) { $class->addUse($this->namespace . '\\' . ucfirst($value)); } } elseif ($property === "@collection") { $isCollection = true; $class->addProperty('collection', array(), PropertyGenerator::FLAG_PROTECTED); $class->addMethods($this->getMethodsForCollection($value->model)); } elseif ($property === "@parent") { //"@parent": "\\Classes\\Items", $class->setExtendedClass($value); } elseif (strpos($value, '@') === 0) { if ($className !== ucfirst(substr($value, 1))) { if ($this->namespace) { $class->addUse($this->namespace . '\\' . ucfirst(substr($value, 1))); } } if ($this->namespace) { $mappingClasses[$property] = $this->namespace . '\\' . ucfirst(substr($value, 1)); } else { $mappingClasses[$property] = ucfirst(substr($value, 1)); } //Create property type Class $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED); $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, ucfirst(substr($value, 1)))), MethodGenerator::fromArray($this->generateSetMethod($property, ucfirst(substr($value, 1)))))); } else { var_dump($value, $property); exit; } } if ($isCollection === true) { if ($this->rootClassNameForCollection) { $class->setExtendedClass($this->rootClassNameForCollection); $class->addUse($this->rootClassForCollectionNamespace); } } else { if ($this->rootClassName) { $class->setExtendedClass($this->rootClassName); $class->addUse($this->rootClassNamespace); } } $class->addProperty($this->mappingClassesPropertyName, $mappingClasses, PropertyGenerator::FLAG_PROTECTED); $class->addProperty($this->mappingPropertyName, $propNameMap, PropertyGenerator::FLAG_PROTECTED); $file = new FileGenerator(array('classes' => array($class))); $code = $file->generate(); $path = realpath($this->destinationDir) . '/' . ucfirst($className) . '.php'; $code = str_replace("\n\n}\n", '}', $code); file_put_contents($path, $code); return $path; }
private function buildProxyClass(string $entityInterfaceName, string $proxyNamespace, string $proxyClassName) : string { $reflectionClass = new ReflectionClass($entityInterfaceName); if (!$reflectionClass->isInterface()) { throw InvalidInterfaceException::fromInvalidInterface($entityInterfaceName); } $classGenerator = new ClassGenerator(); $classGenerator->setNamespaceName($proxyNamespace); $classGenerator->setName($proxyClassName); $classGenerator->setImplementedInterfaces([$entityInterfaceName, ProxyInterface::class]); $classGenerator->addProperty('initializer', null, PropertyGenerator::FLAG_PRIVATE); $classGenerator->addProperty('relationId', null, PropertyGenerator::FLAG_PRIVATE); $classGenerator->addProperty('realEntity', null, PropertyGenerator::FLAG_PRIVATE); $constructorGenerator = new MethodGenerator('__construct', [['name' => 'initializer', 'type' => 'callable'], ['name' => 'relationId']]); $constructorGenerator->setBody(' $this->initializer = $initializer; $this->relationId = $relationId; '); $classGenerator->addMethodFromGenerator($constructorGenerator); $getRelationIdGenerator = new MethodGenerator('__getRelationId'); $getRelationIdGenerator->setBody(' return $this->relationId; '); $classGenerator->addMethodFromGenerator($getRelationIdGenerator); $getRealEntityGenerator = new MethodGenerator('__getRealEntity'); $getRealEntityGenerator->setBody(' if (null === $this->realEntity) { $this->realEntity = ($this->initializer)(); \\Assert\\Assertion::isInstanceOf($this->realEntity, \\' . $entityInterfaceName . '::class); }; return $this->realEntity; '); $classGenerator->addMethodFromGenerator($getRealEntityGenerator); foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $reflectionMethod) { $parameters = []; $parameterGenerators = []; $returnType = $reflectionMethod->getReturnType(); foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $parameterGenerator = new ParameterGenerator($reflectionParameter->getName(), $reflectionParameter->getType(), $reflectionParameter->isDefaultValueAvailable() ? $reflectionParameter->getDefaultValue() : null); $parameterGenerator->setVariadic($reflectionParameter->isVariadic()); $parameterGenerators[] = $parameterGenerator; if ($reflectionParameter->isVariadic()) { $parameters[] = '...$' . $reflectionParameter->getName(); } else { $parameters[] = '$' . $reflectionParameter->getName(); } } $methodGenerator = new MethodGenerator(); $methodGenerator->setName($reflectionMethod->getName()); $methodGenerator->setVisibility(MethodGenerator::VISIBILITY_PUBLIC); $methodGenerator->setParameters($parameterGenerators); $methodGenerator->setReturnType($returnType); $body = ' if (null === $this->realEntity) { $this->realEntity = ($this->initializer)(); \\Assert\\Assertion::isInstanceOf($this->realEntity, \\' . $entityInterfaceName . '::class); }; '; if ('void' !== $returnType) { $body .= 'return '; } $body .= '$this->realEntity->' . $reflectionMethod->getName() . '(' . implode(', ', $parameters) . ');'; $methodGenerator->setBody($body); $classGenerator->addMethodFromGenerator($methodGenerator); } $fileGenerator = new FileGenerator(); $fileGenerator->setClass($classGenerator); $filename = null === $this->proxyFolder ? tempnam(sys_get_temp_dir(), $proxyClassName) : sprintf('%s/%s.php', $this->proxyFolder, $proxyClassName); $fileGenerator->setFilename($filename); $fileGenerator->write(); return $filename; }