diff --git a/README.md b/README.md index ade7ccb..b3edf0d 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,29 @@ A minimal service provider to set up and use InfluxDB SDK in Laravel 5 ### Installation -- Add a line to *require* section of `composer.json` and execute `$ composer install` +- Add a line to the *require* section of `composer.json` and execute `$ composer install` ```js "require": { // ... "pdffiller/laravel-influx-provider": "^1.2" } ``` -- Add a line to `config/app.php` +- Add these lines to `config/app.php` ```php 'providers' => [ // ... Pdffiller\LaravelInfluxProvider\InfluxDBServiceProvider::class, ] + + +'aliases' => [ +// ... + 'Influx' => Pdffiller\LaravelInfluxProvider\InfluxDBFacade::class, +] + ``` + + - Define env variables to connect to InfluxDB ``` LARAVEL_INFLUX_PROVIDER_PROTOCOL=http @@ -27,6 +36,11 @@ LARAVEL_INFLUX_PROVIDER_DATABASE=database_name ``` ### How to use +```php +$client = new \Influx; +$data = $client::query('SELECT * from "data" ORDER BY time DESC LIMIT 1'); +``` + ```php $point = [ new \InfluxDB\Point( diff --git a/composer.json b/composer.json index e3975d5..f4aa532 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=5.6", - "illuminate/log": "5.2.*|5.3.*", - "illuminate/support": "5.2.*|5.3.*", + "illuminate/log": "5.2.*|5.3.*|5.4.*", + "illuminate/support": "5.2.*|5.3.*|5.4.*", "influxdb/influxdb-php": "^1.4", "monolog/monolog": "^1.19" }, diff --git a/src/InfluxDBServiceProvider.php b/src/InfluxDBServiceProvider.php index c2365b6..8d483f9 100644 --- a/src/InfluxDBServiceProvider.php +++ b/src/InfluxDBServiceProvider.php @@ -14,8 +14,10 @@ class InfluxDBServiceProvider extends ServiceProvider public function boot() { $this->publishes([ - __DIR__ . '/config/InfluxDB.php' => config_path('influxdb.php') + $this->configPath() => config_path('influxdb.php') ]); + + $this->mergeConfigFrom($this->configPath(), 'influxdb'); if (config('influxdb.use_monolog_handler') === 'true') { $handler = new InfluxDBMonologHandler($this->getLoggingLevel()); @@ -32,6 +34,7 @@ public function boot() public function register() { $this->app->singleton('InfluxDB\Client', function($app) { + $protocol = 'influxdb'; if (in_array(config('influxdb.protocol'), ['https', 'udp'])) { $protocol = config('influxdb.protocol') . '+' . $protocol; @@ -67,4 +70,9 @@ private function getLoggingLevel() 'EMERGENCY' ]) ? config('influxdb.logging_level') : Logger::NOTICE; } + + protected function configPath() + { + return __DIR__ . '/config/InfluxDB.php'; + } }