/** * Create wait method * * @param ClassModel $classModel * @return null */ private function addWait(ClassModel $classModel) { $reflectionClass = new \ReflectionClass($classModel->getInterface()); if (!in_array('Tebru\\Retrofit\\Http\\AsyncAware', $reflectionClass->getInterfaceNames(), true)) { return null; } $methodModel = new MethodModel($classModel, 'wait'); $methodModel->setBody('$this->client->wait();'); $classModel->addMethod($methodModel); }
/** * Get the callback method parameter * * @return null|ParameterModel * @throws RetrofitException */ private function getCallbackParameter() { $parameters = array_reverse($this->methodModel->getParameters()); $callback = null; /** @var ParameterModel $parameter */ foreach ($parameters as $parameter) { if ('\\Tebru\\Retrofit\\Http\\Callback' === $parameter->getTypeHint()) { $callback = $parameter; } } if (null === $callback) { return null; } $reflectionClass = new ReflectionClass($this->methodModel->getClassModel()->getInterface()); if (!in_array('Tebru\\Retrofit\\Http\\AsyncAware', $reflectionClass->getInterfaceNames(), true)) { throw new RetrofitException('Interfaces using async methods must implement the "AsyncAware" class'); } return $callback; }
/** * Create constructor * * @param ClassModel $classModel */ private function addConstructor(ClassModel $classModel) { $methodModel = new MethodModel($classModel, '__construct'); $baseUrl = new ParameterModel($methodModel, 'baseUrl', false); $client = new ParameterModel($methodModel, 'client', false); $client->setTypeHint('\\Tebru\\Retrofit\\Adapter\\HttpClientAdapter'); $serializer = new ParameterModel($methodModel, 'serializer', false); $serializer->setTypeHint('\\JMS\\Serializer\\SerializerInterface'); $eventDispatcher = new ParameterModel($methodModel, 'eventDispatcher', false); $eventDispatcher->setTypeHint('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $methodModel->addParameter($baseUrl); $methodModel->addParameter($client); $methodModel->addParameter($serializer); $methodModel->addParameter($eventDispatcher); $methodBody = ['$this->baseUrl = $baseUrl;', '$this->client = $client;', '$this->serializer = $serializer;', '$this->eventDispatcher = $eventDispatcher;']; $methodModel->setBody(implode($methodBody)); $classModel->addMethod($methodModel); }
public function testIsCallbackOptional() { $method = new MethodModel(new ClassModel('Foo', 'FooClass', ApiClient::class), 'fooMethod'); $parameter = new ParameterModel($method, 'callback', true); $parameter->setTypeHint('\\' . Callback::class); $method->addParameter($parameter); $collection = new AnnotationCollection(); $provider = new AnnotationProvider($collection, $method); $callbackOptional = $provider->isCallbackOptional(); $this->assertTrue($callbackOptional); }
/** * Remove a method from class * * @param MethodModel $methodModel * @return $this */ public function removeMethod(MethodModel $methodModel) { $this->methods->remove($methodModel->getName()); return $this; }