Reputation: 51
i'm creating an Api with Slimphp. I've generated the doc and Client+Server files with Swagger.io. Now i'm trying to use some routes and it is giving me an error
Catchable fatal error: Argument 1 passed to App\v1\Api\ContactApi::__construct() must be an instance of App\v1\lib\ApiClient, instance of Slim\Container given, called in C:\xampp\htdocs\DigitalMade\vendor\slim\slim\Slim\CallableResolver.php on line 64 and defined in C:\xampp\htdocs\DigitalMade\app\v1\Api\ContactApi.php on line 55
The route used:
$this->GET('', App\v1\Api\ContactApi::class.':getContactAsList');
Link to Classes - ApiClient: https://gist.github.com/miorac/d2232ca71a3feaa0500f9f992d0a7e87 - ContactApi: https://gist.github.com/miorac/c9373136ed2b694f59a2fbb0dfea3ebe
Does someone knows what am i doing wrong?
Upvotes: 0
Views: 290
Reputation: 12778
You need to register a factory with the Container which implements the ContactApi
Something like this:
$container = $app->getContainer();
$container[App\v1\Api\ContactApi::class] = function ($c) {
$apiClient = new App\v1\lib\ApiClient();
return new App\v1\Api\ContactApi($apiClient);
}
Slim will then use this factory to instantiate the ContactApi
object before routing.
Upvotes: 2