Comments (5)
Hi Matt, have you run a cache clear to generate the client yet? Does the class exist at that path?
from retrofit-php-bundle.
I've tried without the bundle with the standalone retrofi-php library using the command. It generates the retrofit classes to the cache folder but they are not usable and aren't picked up when running the code, still resulting the error above :(
from retrofit-php-bundle.
Using the bundle, they should be in an environment directory (e.g. dev). I'm trying to reproduce on a fresh symfony 3.2 install.
from retrofit-php-bundle.
This is working for me.
I'm just using AppBundle, and make a few other small changes to make testing quicker, but otherwise it should be the same. I ran a composer install and a cache clear, both completed without errors.
<?php
namespace AppBundle\RestAdapter;
use Tebru\Retrofit\Annotation\GET;
use Tebru\Retrofit\Annotation\QueryMap;
interface GoogleTokenAdapter
{
const BASE_URL = 'https://accounts.google.com';
/**
* @GET("/o/oauth2/token")
* @QueryMap("params")
*/
public function getToken(array $params);
}
<?php
namespace AppBundle\RestAdapter;
use Tebru\Retrofit\Adapter\Rest\RestAdapter;
class GoogleTokenProvider
{
public function get()
{
return RestAdapter::builder()
->setBaseUrl(GoogleTokenAdapter::BASE_URL)
->build();
}
}
services:
foobar_rest_adapter:
class: '%tebru_retrofit.rest_adapter.class%'
factory: ['AppBundle\RestAdapter\GoogleTokenProvider', 'get']
foo_service:
class: 'AppBundle\RestAdapter\GoogleTokenAdapter'
factory: ['@foobar_rest_adapter', 'create']
arguments: ['AppBundle\RestAdapter\GoogleTokenAdapter']
tags:
- { name: tebru_retrofit.register }
I'm making this call in a controller
$this->get('foo_service')->getToken([]);
This is the generated class
<?php
namespace Tebru\Retrofit\Generated\AppBundle\RestAdapter;
class GoogleTokenAdapter implements \AppBundle\RestAdapter\GoogleTokenAdapter
{
private $baseUrl = null;
private $client = null;
private $serializer = null;
private $eventDispatcher = null;
public function __construct($baseUrl, \Tebru\Retrofit\Adapter\HttpClientAdapter $client, \JMS\Serializer\Serializer $serializer, \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher)
{
$this->baseUrl = $baseUrl;
$this->client = $client;
$this->serializer = $serializer;
$this->eventDispatcher = $eventDispatcher;
}
public function getToken(array $params)
{
$queryArray = \Tebru\Retrofit\Generation\Manipulator\QueryManipulator::boolToString($params);
$queryString = http_build_query($queryArray);
$requestUrl = $this->baseUrl . '/o/oauth2/token?' . $queryString;
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
$body = null;
$request = new \GuzzleHttp\Psr7\Request('GET', $requestUrl, $headers, $body);
$beforeSendEvent = new \Tebru\Retrofit\Event\BeforeSendEvent($request);
$this->eventDispatcher->dispatch('retrofit.beforeSend', $beforeSendEvent);
$request = $beforeSendEvent->getRequest();
try {
$response = $this->client->send($request);
} catch (\Exception $exception) {
$apiExceptionEvent = new \Tebru\Retrofit\Event\ApiExceptionEvent($exception, $request);
$this->eventDispatcher->dispatch('retrofit.apiException', $apiExceptionEvent);
$exception = $apiExceptionEvent->getException();
throw new \Tebru\Retrofit\Exception\RetrofitApiException(get_class($this), $exception->getMessage(), $exception->getCode(), $exception);
}
$afterSendEvent = new \Tebru\Retrofit\Event\AfterSendEvent($request, $response);
$this->eventDispatcher->dispatch('retrofit.afterSend', $afterSendEvent);
$response = $afterSendEvent->getResponse();
$retrofitResponse = new \Tebru\Retrofit\Http\Response($response, 'array', $this->serializer, array());
$return = $retrofitResponse->body();
$returnEvent = new \Tebru\Retrofit\Event\ReturnEvent($return);
$this->eventDispatcher->dispatch('retrofit.return', $returnEvent);
return $returnEvent->getReturn();
}
}
Available at var/cache/dev/retrofit/AppBundle/RestAdapter/GoogleTokenAdapter.php
from retrofit-php-bundle.
@MatthewBooth does that work for you or are you still getting the error? Feel free to close if it works.
from retrofit-php-bundle.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from retrofit-php-bundle.