/**
  * Add a method to determine whether the response should be processed into a hydrated
  * response class. By default it delegates that decision to the main api class - override this method
  * to have a per operation decision.
  */
 public function addTranslateResponseToExceptionMethod()
 {
     $body = 'return $this->api->translateResponseToException($response);';
     $docBlock = new DocBlockGenerator('Determine whether the response is an error. Override this method to have a per-operation decision, otherwise the function from the API class will be used.', null);
     $methodGenerator = $this->createMethodGenerator('translateResponseToException', $body, $docBlock, [['response', 'Amp\\Artax\\Response']], ['null', '\\ArtaxServiceBuilder\\BadResponseException']);
     $this->classGenerator->addMethodFromGenerator($methodGenerator);
 }
 /**
  * 
  */
 function addAPIParameterAccessMethod()
 {
     foreach ($this->apiParameters as $apiParameter => $type) {
         $translatedParam = ucfirst($this->translateParameter($apiParameter));
         $methodGenerator = new MethodGenerator('get' . $translatedParam);
         $body = 'return $this->' . $apiParameter . ';' . PHP_EOL;
         $methodGenerator->setBody($body);
         $methodGenerator->setDocBlock("@return {$type}");
         $this->classGenerator->addMethodFromGenerator($methodGenerator);
         $methodGenerator = new MethodGenerator('set' . $translatedParam);
         $body = '$this->' . $apiParameter . ' = $value;' . PHP_EOL;
         $parameterParameter = new ParameterGenerator('value');
         $methodGenerator->setParameter($parameterParameter);
         $methodGenerator->setBody($body);
         $this->classGenerator->addMethodFromGenerator($methodGenerator);
     }
 }
示例#3
0
 /**
  * @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);
 }