dcarbone/php-consul-api-bundle

Bundle to enable usage of dcarbone/php-consul-api inside of a Symfony 3 project

0.6.1 2018-10-09 17:16 UTC

This package is auto-updated.

Last update: 2024-10-17 09:20:58 UTC


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