function createParamTag(ParameterGenerator $parameter, $description) { $paramType = $parameter->getType(); $simpleTypes = ['array', 'bool', 'callable', 'int', 'mixed', 'string']; if (in_array(strtolower($paramType), $simpleTypes) == false) { $paramType = '\\' . $paramType; } $tag = new GenericTag('param', sprintf('%s $%s %s', $paramType, $parameter->getName(), $description)); return $tag; }
/** * */ function addConstructorMethod() { if (count($this->constructorParams)) { $methodGenerator = new MethodGenerator('__construct'); $body = ''; $params = []; //Every API needs the Amp\Artax\Client object to send requests $param = new ParameterGenerator('client', 'Amp\\Artax\\Client', null); $params[] = $param; $body .= '$this->client = $client;' . PHP_EOL; $param = new ParameterGenerator('reactor', 'Amp\\Reactor', null); $params[] = $param; $body .= '$this->reactor = $reactor;' . PHP_EOL; $param = new ParameterGenerator('responseCache', 'ArtaxServiceBuilder\\ResponseCache', null); $params[] = $param; $body .= '$this->responseCache = $responseCache;' . PHP_EOL; //Add the params foreach ($this->constructorParams as $constructorParam) { $param = new ParameterGenerator($constructorParam); $params[] = $param; $body .= sprintf('$this->%s = $%s;', $constructorParam, $constructorParam); $body .= PHP_EOL; } //Add an oauth signing service if the API needs one if ($this->requiresOauth1 == true) { $param = new ParameterGenerator('oauthService', 'ArtaxServiceBuilder\\Service\\Oauth1', null); $param->setDefaultValue(null); $params[] = $param; $body .= sprintf('$this->%s = $%s;', 'oauthService', 'oauthService'); $body .= PHP_EOL; } $methodGenerator->setBody($body); $methodGenerator->setParameters($params); $this->classGenerator->addMethodFromGenerator($methodGenerator); } }