Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rstgroup/php-consul-kv-array-getter
https://github.com/rstgroup/php-consul-kv-array-getter
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rstgroup/php-consul-kv-array-getter
- Owner: rstgroup
- License: mit
- Created: 2017-07-24T12:11:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-26T10:29:54.000Z (over 7 years ago)
- Last Synced: 2024-04-13T19:29:39.921Z (8 months ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 0
- Watchers: 15
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Consul KV Array Getter
[![Build Status](https://travis-ci.org/rstgroup/php-consul-kv-array-getter.svg?branch=master)](https://travis-ci.org/rstgroup/php-consul-kv-array-getter)
## 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.## How to install it?
Require the package by Composer:
```bash
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:```php
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:
```
application/db/host => 'some host'
application/cache/prefix => 'abcd.prefix'
application/name => 'app'
```If we fetch config with prefix `'application'` we will receive:
```php
$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:```php
$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:
```php
$consulArrayGetter->getByPrefix('application/db') == [
'db' => [ 'host' => 'some host' ]
]
```