adback / adback-sdk-php-symfony
A bundle to use the AdBack ApiClient
Installs: 10 607
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- adback/adback-sdk-php: ~2.5
- symfony/framework-bundle: ~2.3|~3.0|^4.0
- twig/twig: *
Requires (Dev)
- doctrine/orm: ^2.5
- phake/phake: ~2.3
- phpunit/phpunit: ~5.4.0
Suggests
- dekalee/nightly-task-bundle: Allows you to run all your nightly task with one entry command
- doctrine/orm: Allows you to use doctrine to store the cache
- symfony/config: Allows you to use the file cache
README
This bundle will use the library to call the AdBack api.
See the AdBack website for more informations.
Installation
Launch the composer command :
composer require adback/adback-sdk-php-symfony
If you are using a version of symfony >= 4, it should automatically activate the bundle.
If you are using a version of symfony < 4, you have to add the bundle to your AppKernel.php
file :
new Adback\ApiClientBundle\Adback\ApiClientBundle(),
Configuration
Symfony 4
In your .env
file, the following lines should have been added :
ADBACK_API_CLIENT_ACCESS_TOKEN=adback-access-token
Modify it with the token provided by the AdBack team.
Then follow the paragraph linked to the type of cache you have choosen :
Redis
In the config/packages/adback_sdk_php.yaml
you should add the following configuration :
cache_type: redis cache_service: redis_service
redis_service
is the name of the redis connection you are using to store the data.
Doctrine
In the config/packages/adback_sdk_php.yaml
you should add the following configuration :
cache_type: doctrine entity_manager: doctrine.orm.entity_manager
doctrine.orm.entity_manager
is the name of the doctrine connection you are using to store the data.
Do not forget to create the table linked to the AdBack sdk.
Custom
If you want to write your own cache driver, you should create a class that implements
Adback\ApiClient\Driver\ScriptCacheInterface
and name this service adback_api_client.script_cache
.
In the config/packages/adback_sdk_php.yaml
you should add the following configuration :
cache_type: custom
If the service is missing, an error will be issued by the Symfony DIC when the service is being used.
Symfony < 4
In your app/config/config.yml
file, you should add the following lines :
adback_api_client: access_token: "your-access-token"
Modify it with the token provided by the AdBack team.
Then follow the paragraph linked to the type of cache you have choosen :
Redis
In the app/config/config.yml
you should add the following configuration :
adback_api_client: cache_type: redis cache_service: redis_service
redis_service
is the name of the redis connection you are using to store the data.
Doctrine
In the app/config/config.yml
you should add the following configuration :
adback_api_client: cache_type: doctrine entity_manager: doctrine.orm.entity_manager
doctrine.orm.entity_manager
is the name of the doctrine connection you are using to store the data.
Do not forget to create the table linked to the AdBack sdk.
Custom
If you want to write your own cache driver, you should create a class that implements
Adback\ApiClient\Driver\ScriptCacheInterface
and name this service adback_api_client.script_cache
.
In the app/config/config.yml
you should add the following configuration :
adback_api_client: cache_type: custom
If the service is missing, an error will be issued by the Symfony DIC when the service is being used
Script Type
There is two possibilities for the script you could get.
Small scripts
This configuration will only load the AdBack script from an external url.
This usage is good for a quick start.
Full scripts
This configuration will load our full script or bootscrap script.
This will allow us to deliver a script which is more flexible when the blocking in place are harder.
This solution is recommanded for an advanced usage.
Usage
Refresh command
In order to have the AdBack script always up-to-date you should launch the command adback:api-client:refresh-tag
periodically (at least once a day).
This command will call our api and store the response in the cache type you have chosen
Add the script to your pages
At the bottom of your webpages, you should add the script twig generation function :
{{ adback_generate_scripts() }}
Full configuration description
adback_api_client: access_token: ~ # Required, Your personnal access token api_url: 'https://adback.co/api' # The base url for the api script_url: script/me # The api url used to get the script cache_type: redis # The cache type you are using generator_type: script # The type of script you are generating cache_service: redis # The service used for the caching entity_manager: doctrine.orm.entity_manager # The entity manager used (only if you use the doctrine cache # This key is used if multiple website access the same database key_prefix: ''