Bundle to enable usage of dcarbone/php-consul-api inside of a Symfony 3 project
In your composer.json
file:
{
"require": {
"dcarbone/php-consul-api-bundle": "0.6.*"
}
}
In your AppKernel.php
file:
public function registerBundles()
{
$bundles = [
// --
new \DCarbone\PHPConsulAPIBundle\PHPConsulAPIBundle(),
// --
];
// --
return $bundles;
}
There will always be at least one registered Consul service using the standard Consul
environment variables. If you wish to use this, at the very least CONSUL_HTTP_ADDR
should be defined.
The service can be accessed using the consul_api.local
service. This is also the default target of the
consul_api.default
alias.
You may optionally override the default configuration with one of the named configurations you have specified as such:
consul_api:
default_configuration: nifty_name
If you wish to connect to multiple Consul agents, or just want to have things named differently, you may optionally
configure them under the consul_api
configuration namespace.
The available configuration parameters are:
- addr
- scheme
- datacenter
- wait_time
- http_auth
- token
- ca_file
- client_cert
- client_key
- insecure_skip_verify
- token_in_header
- http_client
As an example:
consul_api:
named_configurations:
nifty_name:
addr: hostname.domain.woot
scheme: https
insecure_skip_verify: false
http_client: ~ # Enter service name of GuzzleHttp\ClientInterface compatible http client you wish to use
This will create a new service named consul_api.nifty_name
with the specified configuration options.
If you are using Twig and TwigBundle in your Symfony app, there are a few functions exposed to you. You can see the full list here: PHPConsulAPIExtension.
If you have multiple named configurations present and want to be able to access them all, one possible way is to
utilize the ConsulBag service. It is defined as consul_api.bag