dcarbone / php-consul-api-bundle
Bundle to enable usage of dcarbone/php-consul-api inside of a Symfony 3 project
Installs: 315
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
- dcarbone/php-consul-api: 0.6.*
- symfony/console: ~3.0
- symfony/framework-bundle: ~3.0
- symfony/yaml: ^3.0
Requires (Dev)
- symfony/twig-bundle: ~3.0
README
Bundle to enable usage of dcarbone/php-consul-api inside of a Symfony 3 project
Installation
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; }
Local Configuration
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.
Default Configuration
You may optionally override the default configuration with one of the named configurations you have specified as such:
consul_api: default_configuration: nifty_name
Named Configurations
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.
Twig Integration
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.
ConsulBag
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