initial commit
This commit is contained in:
commit
bf1a4e1879
17 changed files with 822 additions and 0 deletions
61
src/StorageAdapterFactory.php
Normal file
61
src/StorageAdapterFactory.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Superbalist\LaravelPrometheusExporter;
|
||||
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use InvalidArgumentException;
|
||||
use Prometheus\Storage\Adapter;
|
||||
use Prometheus\Storage\APC;
|
||||
use Prometheus\Storage\InMemory;
|
||||
use Prometheus\Storage\Redis;
|
||||
|
||||
class StorageAdapterFactory
|
||||
{
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @param Container $container
|
||||
*/
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory a storage adapter.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param array $config
|
||||
* @return Adapter
|
||||
*/
|
||||
public function make($driver, array $config = [])
|
||||
{
|
||||
switch ($driver) {
|
||||
case 'memory':
|
||||
return new InMemory();
|
||||
case 'redis':
|
||||
return $this->makeRedisAdapter($config);
|
||||
case 'apc':
|
||||
return new APC();
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('The driver [%s] is not supported.', $driver));
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory a redis storage adapter.
|
||||
*
|
||||
* @param array $config
|
||||
* @return Redis
|
||||
*/
|
||||
protected function makeRedisAdapter(array $config)
|
||||
{
|
||||
if (isset($config['prefix'])) {
|
||||
Redis::setPrefix($config['prefix']);
|
||||
}
|
||||
return new Redis($config);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue