targito / targito-api-bundle
Targito API implementation for Symfony
Installs: 2 689
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.2|^8.0
- symfony/framework-bundle: ^4.4|^5.0
- symfony/yaml: ^4.4|^5.0
- targito/targito-api: ^1.3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpstan/phpstan: ^0.12.18
This package is auto-updated.
Last update: 2025-06-07 23:43:33 UTC
README
To see description of the api methods, see the library description
Installation
composer require targito/targito-api-bundle
If you use Symfony Flex the bundle should be enabled automatically.
If you're not using it, add Targito\Bundle\Api\TargitoApiBundle
to your config/bundles.php
file:
<?php return [ // ... Targito\Bundle\Api\TargitoApiBundle::class => ['all' => true], ];
If you want to change any of the default settings, create a file targito_api.yaml
in your config/packages
directory
with key targito_api
:
Note: You can let Symfony generate the default config for you like this:
./bin/console config:dump targito_api > config/packages/targito_api.yaml
targito_api: # your config goes here
Usage
Simply use the provided services (with autowiring support):
Targito\Api\TargitoApi
Targito\Api\Endpoint\TargitoContactEndpoint
Targito\Api\Endpoint\TargitoTransactEndpoint
Examples
Get the whole api service:
<?php use Targito\Api\TargitoApi; class MyService { public function __construct(TargitoApi $targitoApi) { $targitoApi->contacts()->addContact([ //... ]); $targitoApi->transact()->sendEmail([ //... ]); } }
Get specific api module:
<?php use Targito\Api\Endpoint\TargitoContactEndpoint; use Targito\Api\Endpoint\TargitoTransactEndpoint; class MyService { public function __construct(TargitoContactEndpoint $contactEndpoint, TargitoTransactEndpoint $transactEndpoint) { $contactEndpoint->addContact([]); $transactEndpoint->sendEmail([]); } }
Configuring credentials
By default, the bundle takes the credentials from environment variables TARGITO_ACCOUNT_ID
and TARGITO_API_PASSWORD
.
If you want to provide the credentials other way, read on, otherwise you can skip this section.
There are two built-in options for specifying credentials: via environment variables or explicitly. You can also specify your own credentials service.
Explicit
When using explicit mode, the credentials must be also specified inside the config.
targito_api: credentials: type: explicit account_id: my-account-id api_password: my-api-password
Environment variables
When using environment variables, you can optionally specify the environment variable names.
targito_api: credentials: type: environment # the type key can also be omitted as 'environment' is the default value account_id_env_name: MY_ACCOUNT_ID_ENV_VAR # optional, default is TARGITO_ACCOUNT_ID api_password_env_name: MY_API_PASSWORD_ENV_VAR # optional, default is TARGITO_API_PASSWORD
Custom service
You can specify your own service which implements the Targito\Api\Credentials\CredentialsInterface
interface.
targito_api: credentials: type: App\MyCredentialsService
Configuring http request service
By default, this bundle (and underlying library) choose automatically between curl and stream based implementations.
You can provide your own (or use the curl/stream library regardless of curl support on the PHP level).
The service must implement Targito\Api\Http\HttpRequestInterface
.
targito_api: http_request: targito_api.http.curl
or
targito_api: http_request: targito_api.http.stream
or
targito_api: http_request: App\MyCustomHttpRequest
Full configuration reference (autogenerated)
# Default configuration for extension with alias: "targito_api" targito_api: credentials: # Can be 'environment', 'explicit' or any service implementing Targito\Api\Credentials\CredentialsInterface type: environment # The account id that is used when type is 'explicit' account_id: null # The api password that is used when type is 'explicit' api_password: null # The account id environment variable name when type is 'environment' account_id_env_name: TARGITO_ACCOUNT_ID # The api password environment variable name when type is 'environment' api_password_env_name: TARGITO_API_PASSWORD # The service that will be used as the http request (must implement Targito\Api\Http\HttpRequestInterface). # Defaults to null which means autodetect between default curl and stream based implementations. http_request: null # The api url (including version) to issue requests to. Can be null which means to use default. api_url: null