-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endpoint Default Connection Name 'App' #87
Comments
2020-02-22 18:17:41 Error: [Cake\Datasource\Exception\MissingDatasourceConfigException] The datasource configuration "app" was not found. in /home/bil/projects/freshserviceinventory/vendor/cakephp/cakephp/src/Datasource/ConnectionManager.php on line 203
Request URL: /Tickets So my implementation is very basic at the moment. I've got a TicketsController with an index function that only does this: I've created a src/Webservice/Driver/Freshservice.php driver which extends AbstractDriver and calls setClient in its initialize function. I've created a Model/Endpoint/TicketsEndpoint that extends Endpoint and has nothing else in it. `protected function _executeReadQuery(Query $query, array $options = [])
So for some reason my setup is trying to look in config/app.php for datasource -> app. If I add this to my datasources: debug_kit shows that Muffin\Webservice\Model\EndpointLocator->get is being passed: Cake\Datasource\ConnectionManager::get is being passed As I mentioned earlier, I tracked down this 'app' argument to the defaultConnectionName(): string which is taking my class name 'App\Model\Endpoint\TicketsEndpoint', splitting by '\', reversing it, then array_split with 3, 2... which is just getting the word 'app'. ` public static function defaultConnectionName(): string
I'm probably just doing something wrong or I need to add some sort of config somewhere but I can't figure out how to fix it. |
Have you made Refer to the Github webservice for example https://github.com/cvo-technologies/cakephp-github |
So the application api I am pulling from is called "Freshservice". Thanks for the help on understanding the need for a FreshserviceWebservice that is then extended by things like the TicketsWebservice. However, this didn't correct the issue. The plugin is still trying to find a datasource called 'app' Just to be clear, I am using the 3.0.0 beta of your plugin as I am in CakePHP 4. So I replicated the example GitHub webservice and updated all of the functions and namespaces. Still, the app is trying to find a datasource called 'app' instead of 'Freshservice'. Here is my setup: use Cake\Http\Client; class Freshservice extends AbstractDriver Freshservice Webservice located in src\Webservice\FreshserviceWebservice.php: use Muffin\Webservice\Datasource\Query; class FreshserviceWebservice extends Webservice Tickets Webservice located in src\Webservice\TicketsWebservice.php use Muffin\Webservice\Datasource\Query; class TicketsWebservice extends FreshserviceWebservice Tickets Endpoint located in src\Model\Endpoint\TicketsEndpoint.php use Muffin\Webservice\Model\Endpoint; class TicketsEndpoint extends Endpoint So, with these files in place, shouldn't it be looking for a datasource called 'freshservice'? Instead I'm getting the error: 'The datasource configuration app was not found in config/app.php.' |
I thought I'd take another look and try to figure this out.
One endpoint I am using has the following static::class "App\Model\Endpoint\AssetsEndpoint" So, this function makes sense if I were to create a plugin... but I'm using it directly in my project to perform API calls. Is that not intended? |
So I spent today learning how to put together a plugin... getting that working... then learning how to split it into its own repository... then submitting it to packagelist. I now have a working freshservice API plugin requiring your plugin. It is now looking for the proper config name 'freshservice' instead of 'app'. https://bitbucket.org/matt_henry_ops/freshservice It is still very much a work in progress but this is working so far! Sorry for any confusion on my part. I thought I could just use the webservice plugin directly in my regular application... If I should be able to do this then the above code should either account for this or documentation on how to set the proper config name would be good. Thanks! |
Thanks for providing the detailed analysis and congrats on learning all the new stuff related to plugin development and publishing, that will definitely help you in future 🙂. So when loading an endpoint class we don't have any info about which webservice it's related to and what connection it should use. Hence we have to resort to guess work based on the FQCN to get the connection name. We could try to improve the connection name guessing or just clarify that users should override the Given all the various classes needed for a webservice I would recommend organizing them using a plugin regardless. One can make an "app plugin" and doesn't necessarily need to publish it to packagist. |
Closed by #88 |
A driver with a class of 'App\Webservice\Driver\FreshService' ends up trying to load a datasource named 'app' instead of something like Webservice\FreshService pr Driver\FreshService. I've tracked down the issue to Webservice/src/Model/Endpoint.php function defaultConnectionName(): string
I'm new to this framework however the default behavior of looking for Datasource > app didn't seem quite right.
The text was updated successfully, but these errors were encountered: