/** * */ function generate() { $this->classGenerator->addUse('Amp\\Artax\\Request'); $this->classGenerator->addUse('Amp\\Artax\\Response'); $this->classGenerator->addUse('Amp\\Reactor'); $this->sanityCheck(); $this->addProperties([]); $this->addConstructorMethod(); $this->addSignMethod(); $this->generateMethods(); $this->addAPIParameterAccessMethod(); if (count($this->interfaces)) { $this->classGenerator->setImplementedInterfaces($this->interfaces); } $this->classGenerator->addUse('ArtaxServiceBuilder\\ResponseCache'); $this->classGenerator->setAbstract(true); $this->generateExceptionClass(); $this->addExecMethod(); $this->addExecAsyncMethod(); $this->addShouldResponseBeProcessedMethod(); $this->addShouldResponseBeCachedMethod(); $this->addShouldUseCachedResponseMethod(); $this->addAbstractInstantiateResultMethod(); //$this->addIsErrorResponseMethod(); $this->addtranslateResponseToExceptionMethod(); $text = $this->classGenerator->generate(); saveFile($this->outputPath, $this->fqcn, $text); }
/** * Generate the complete operation class and save it to the filesystem. * @throws \ArtaxServiceBuilder\APIBuilderException */ function generate() { if ($this->namespace) { $fqcn = $this->namespace . '\\' . $this->className; } else { $fqcn = $this->className; } $this->addProperties(); $this->addConstructorMethod(); $this->addSetAPIMethod(); $this->addSetParameterMethod(); $this->addCheckScopeMethod(); $this->addAccessorMethods(); $this->addFilteredParameterMethod(); $this->addCreateRequestMethod(); $this->addCreateAndExecuteMethod(); $this->addCallMethod(); $this->addExecuteMethod(); $this->addExecuteAsyncMethod(); $this->addDispatchMethod(); $this->addDispatchAsyncMethod(); $this->addProcessResponseMethod(); //$this->addIsErrorResponseMethod(); $this->addShouldResponseBeProcessedMethod(); $this->addTranslateResponseToExceptionMethod(); $this->addShouldUseCachedResponseMethod(); $this->addShouldResponseBeCachedMethod(); $this->addSetOriginalResponseMethod(); $this->addGetOriginalResponseMethod(); $this->addGetResultInstantiationInfoMethod(); $this->classGenerator->setImplementedInterfaces(['ArtaxServiceBuilder\\Operation']); $this->classGenerator->setFQCN($fqcn); $text = $this->classGenerator->generate(); saveFile($this->outputPath, $fqcn, $text); }
/** * @param AnalyzedClass $class */ function saveClass(AnalyzedClass $class, $namespace, $outputDirectory) { static $count = 0; $count++; $classGen = new ClassGenerator($class->className); $classGen->setExtendedClass('GithubService\\Model\\DataMapper'); $dataMapEntries = []; foreach ($class->properties as $property) { /** @var $property \Property */ $propertyGen = new PropertyGenerator(); $propertyGen->setName(lcfirst($property->name)); if ($property->multiple == true) { $propertyGen->setDefaultValue([]); } if ($property instanceof AnalyzedClass) { $propertyGen->setStandardDocBlock($namespace . '\\' . $property->realClassName); } $classGen->addPropertyFromGenerator($propertyGen); $dataMapEntries[] = $property->getDataMapEntry(); } $methodGenerator = new MethodGenerator(); $methodGenerator->setVisibility(MethodGenerator::VISIBILITY_PROTECTED); $methodGenerator->setName('getDataMap'); $bodyTest = "\$dataMap = [\n"; foreach ($dataMapEntries as $dataMapEntry) { $line = " ["; $separator = ''; foreach ($dataMapEntry as $key => $value) { $line .= $separator; if (is_numeric($key) == true) { $line .= var_export($value, true); } else { $line .= var_export($key, true) . " => " . var_export($value, true); } $separator = ', '; } $line .= "],"; $bodyTest .= $line . "\n"; } $bodyTest .= "];\n\n"; $bodyTest .= "return \$dataMap;\n"; $methodGenerator->setBody($bodyTest); $classGen->addMethodFromGenerator($methodGenerator); $classString = $classGen->generate(); $output = "<?php \n\nnamespace {$namespace};\n\n"; $output .= $classString; $filename = sprintf($outputDirectory . "/%s.php", $class->className); file_put_contents($filename, $output); }