Reputation: 1167
I'm using the Google Analytics API to get some info to my app. It's a PHP class that I can instantiate and use to pull data from GA.
My first thought was to put it in a new folder (app/lib), and then autoload it from composer:
"autoload": {
"classmap": [
"app/lib/google/api"
]
}
I can then instantiate in my controller and use as I wish: $ga = new Google\Api\gapi(ga_email, ga_password);
However, since it's a data access layer for my application, I also tried putting it in a model and instantiating it that way. Both work, I'm just trying to follow some best-practices. Or is there another place I should be putting it, like the vendor folder.
Upvotes: 0
Views: 1459
Reputation: 320
Personally I'd want it to be a package under the vendor
folder which is managed by composer. There's a number of people who have packaged up the GAPI
library on Packagist, saving you the work of creating a location, autoloading it, keeping it updated, etc.
https://packagist.org/search/?q=gapi
Just add the requirement to your composer.json:
"require": {
"dandydev/gapi-php": "dev-master"
}
Then in the command line in that folder run
composer update
Upvotes: 3