Download the PHP package emanuilnikolov/igdb-api-bundle without Composer
On this page you can find all versions of the php package emanuilnikolov/igdb-api-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emanuilnikolov/igdb-api-bundle
More information about emanuilnikolov/igdb-api-bundle
Files in emanuilnikolov/igdb-api-bundle
Package igdb-api-bundle
Short Description Symfony Wrapper for IGDB.com API.
License MIT
Informations about the package igdb-api-bundle
IgdbApiBundle
This bundle provides an easy way to communicate with the Internet Game Database API. You can contribute to the project via a pull request.
Installation
Prerequisites
- An account and a key from IGDB. Sign up.
- PHP 7.1.3 or above
- Symfony 3.4 or above. Only 3 core bundles are required (not the whole framework):
symfony/config: ^3.4|^4.0
symfony/dependency-injection: ^3.4|^4.0
symfony/http-kernel: ^3.4|^4.0
)
- Guzzle 6.3 or above
The Symfony bundles and Guzzle are automatically included by composer.
Composer
To get the latest version of the bundle through Composer, run the command:
Configuration
Without Symfony Flex
Enable the bundle in app/AppKernel.php
:
copy the following in your app/config/config.yml
file:
and update your .env
file:
With Symfony Flex
This bundle has a Flex recipe that will automatically add en_igdb_api.yaml
in your config/packages
directory and update your .env
file accordingly.
Using your credentials
Assign YOUR_BASE_URL
and YOUR_API_KEY
in the .env file your own credentials,
which can be found at the IGDB API's homepage (you have to be logged in).
If you do not wish to use environment variables (highly recommended), you can replace the '%env(YOUR_BASE_URL)%'
and '%env(YOUR_API_KEY)%'
.
Usage
Available Services
- Wrapper
- Service ID -
en_igdb_api.wrapper
- Aliases
IgdbWrapper
IgdbWrapperInterface
- Service ID -
- Parameter Builder
- Service ID -
en_igdb_api.parameter.builder
- Aliases
ParameterBuilder
ParameterBuilderInterface
- Service ID -
- Parameter Collection
- Service ID -
en_igdb_api.parameter.collection
- Aliases
AbstractParameterCollection
Initiating
The services are initiated like any other Symfony service - through injection in the constructor, controller's action method etc.
Example
- Service ID -
To achieve greater flexibility, it is advised to type hint the desired service's interface instead of the actual implementation.
Parameter Builder
The builder is used to form the query string that will be sent to the API. It utilizes method chaining to gather the parameters' values. Upon calling the buildQueryString()
method (done automatically in the wrapper), they are combined into a query string.
The available parameters are listed here. They are available as methods in the ParameterBuilder and can be chained as follows:
Example
Hints
- If not explicitly defined, the default value of the
fields
parameter is '*'. - Use the
setIds()
method to set multiple comma-separated id's:setIds("1,2,3")
. - The
buildQueryString()
method will combine all the parameters previously set in the builder into a query string. When executed on the above example,1?fields=*&limit=33&offset=22
will be returned.Parameter Collection
Extending the AbstractParameterCollection provides a way to store frequently used configurations of the ParameterBuilder and thus decouples it from the rest of the logic.
Example
Create your custom collection and extend the AbstractParameterCollection:
Then, the IgdbWrapper can be used to fetch the desired collection:
Wrapper
Endpoints
The endpoints described in the API's documentation are available as methods in the IgdbWrapper. All of them accept an instance of the ParameterBuilder and return a PHP associative array with the data. The bundle utilizes the PSR-7 Standard
Example
Private Endpoints
These will be introduced in the next release of the bundle.
Scroll API
This is a functionality provided by the IGDB API that provides a simpler and faster way to paginate your results. You can read more about it here.
Example
Search
Searching is done by using the IgdbWrapper's search()
method or through setting the ParameterBuilder's setSearch()
method.
Other useful methods
All the methods below (except fetchDataAsJson()
) are used internally by the endpoints' methods.
fetchData()
This method is behind each one of the endpoints' methods and can be used independently.
fetchDataAsJson()
Same as fetchData()
, but the native JSON response of the API is returned as a string, instead of a PHP associative array.
sendRequest()
Send an HTTP Request to a given URL. This method assigns the $response property of the IgdbWrapper.
Modifies behaviour of Guzzle's request()
method by adhering to the good practice of still returning a response and not throwing an exception when a 4xx or a 5xx error occurs.
You can read more about the available methods for the $response here
processResponse()
Decode the provided response's body to a PHP associative array, using the json_decode()
function.
If the API returns an unsupported by json_decode()
type of data, it is still included into an array.
getEndpoint()
Combine the base URL and the endpoint.
All versions of igdb-api-bundle with dependencies
symfony/config Version ^3.4|^4.0
symfony/dependency-injection Version ^3.4|^4.0
symfony/http-kernel Version ^3.4|^4.0
guzzlehttp/guzzle Version ^6.3
ext-json Version *