/**
  * Add the properties to the Operation that are always present.
  */
 function addProperties()
 {
     $requiredProperties = ['api' => '\\' . $this->apiClassname, 'parameters' => 'array', 'response' => '\\Amp\\Artax\\Response', 'originalResponse' => '\\Amp\\Artax\\Response'];
     //TODO - deal with clashes between this and bits of the actual api
     foreach ($requiredProperties as $propertyName => $typehint) {
         $propertyGenerator = new PropertyGenerator($propertyName, null);
         $docBlock = new DocBlockGenerator('@var ' . $typehint);
         $propertyGenerator->setDocBlock($docBlock);
         $this->classGenerator->addPropertyFromGenerator($propertyGenerator);
     }
     //We have to allow access to the last response for crappy APIs
     //that return information in the response headers.
     $docBlock = new DocBlockGenerator('Get the last response.');
     $body = 'return $this->response;';
     $methodGenerator = $this->createMethodGenerator('getResponse', $body, $docBlock, [], '\\Amp\\Artax\\Response');
     $this->classGenerator->addMethodFromGenerator($methodGenerator);
     $docBlock = new DocBlockGenerator('Set the last response. This should only be used by the API class when the operation has been dispatched. Storing the response is required as some APIs store out-of-bound information in the headers e.g. rate-limit info, pagination that is not really part of the operation.');
     $body = '$this->response = $response;';
     $methodGenerator = $this->createMethodGenerator('setResponse', $body, $docBlock, [['response', 'Amp\\Artax\\Response']]);
     $this->classGenerator->addMethodFromGenerator($methodGenerator);
 }
 /**
  * 
  */
 private function addProperties(array $nativeProperties)
 {
     if ($this->requiresOauth1 == true) {
         $nativeProperties['oauthService'] = 'ArtaxServiceBuilder\\Service\\Oauth1';
     }
     $nativeProperties['responseCache'] = 'ArtaxServiceBuilder\\ResponseCache';
     $nativeProperties['reactor'] = 'Amp\\Reactor';
     $allProperties = [$this->apiParameters, $nativeProperties];
     foreach ($allProperties as $properties) {
         foreach ($properties as $property => $type) {
             $propGenerator = new PropertyGenerator($property);
             $propGenerator->setStandardDocBlock($type);
             $this->classGenerator->addPropertyFromGenerator($propGenerator);
         }
     }
 }
Beispiel #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);
 }