2017 © Pedro Peláez
 

library php-consul-kv-array-getter

This library allows you to receive the consul's KV Store's keys as a structured array.

image

rstgroup/php-consul-kv-array-getter

This library allows you to receive the consul's KV Store's keys as a structured array.

  • Wednesday, July 26, 2017
  • by rstgroup
  • Repository
  • 14 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Consul KV Array Getter

Build Status, (*1)

What does this library do?

The library allows you to retrieve whole tree of properties from Consul's KV store. Retrieved data is grouped into nested arrays., (*2)

How to install it?

Require the package by Composer:, (*3)

composer require rstgroup/php-consul-kv-array-getter

How to use the library?

All you need is instance of SensioLabs\Consul\Services\KVInterface and pass it to the RstGroup\PhpConsulKVArrayGetter\Consul\ConsulArrayGetter constructor:, (*4)

use SensioLabs\Consul\ServiceFactory;
use SensioLabs\Consul\Services\KVInterface;
use RstGroup\PhpConsulKVArrayGetter\Consul\ConsulArrayGetter;

// your consul options:
$consulParams = [
    'base_uri' => 'http://consul-domain:8500'
];

// prepare service that talks to Consul KV
$consulServicesFactory = new ServiceFactory($consulParams);
$kvService = $consulServicesFactory->get(KVInterface::class);

// create getter instance
$consulArrayGetter = new ConsulArrayGetter(
    $kvService
);

// get the keys as structure
$result = $consulArrayGetter->getByPrefix('prefix');

How keys are mapped to return structure?

Let's assume we have list of keys present in KV Store:, (*5)

application/db/host      => 'some host'
application/cache/prefix => 'abcd.prefix'
application/name         => 'app'

If we fetch config with prefix 'application' we will receive:, (*6)

$consulArrayGetter->getByPrefix('application') == [
    'application' => [
        'db' => [ 'host' => 'some host' ],
        'cache' => [ 'prefix' => 'abcd.prefix' ],
        'name' => 'app'
    ]
]

If you add slash at the end, the result array will be created relative to application key:, (*7)

$consulArrayGetter->getByPrefix('application/') == [
    'db' => [ 'host' => 'some host' ],
    'cache' => [ 'prefix' => 'abcd.prefix' ],
    'name' => 'app'
]

Adding another key part after slash will return only those keys that match given prefix:, (*8)

$consulArrayGetter->getByPrefix('application/db') == [
    'db' => [ 'host' => 'some host' ]
]

The Versions

26/07 2017

dev-master

9999999-dev

This library allows you to receive the consul's KV Store's keys as a structured array.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artur Wolny

26/07 2017

1.0

1.0.0.0

This library allows you to receive the consul's KV Store's keys as a structured array.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artur Wolny