From 01d9cd400b8824fcb865549a94212eaaaab61520 Mon Sep 17 00:00:00 2001 From: marioperezesteso Date: Wed, 21 Feb 2018 12:56:19 +0000 Subject: [PATCH 1/8] feat(consumer): add possibility to specify Segment consumer --- src/SegmentServiceProvider.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SegmentServiceProvider.php b/src/SegmentServiceProvider.php index 5791264..8156856 100644 --- a/src/SegmentServiceProvider.php +++ b/src/SegmentServiceProvider.php @@ -35,7 +35,15 @@ public function boot() $this->setupConfig(); if ($writeKey = $this->app->config->get('segment.write_key')) { - Segment::init($writeKey); + $options = [ + 'consumer' => $this->app->config->get('segment.consumer') ?? null, + ]; + + if ($fileName = $this->app->config->get('segment.filename')) { + $options['filename'] = $fileName; + } + + Segment::init($writeKey, $options); } } From 8940fe47164fdf0f14fde6a2cc3127d7eaddf13f Mon Sep 17 00:00:00 2001 From: marioperezesteso Date: Wed, 21 Feb 2018 16:26:05 +0000 Subject: [PATCH 2/8] Add environment variables for consumer and filename --- config/segment.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/segment.php b/config/segment.php index 1e4e1f3..6cd329a 100644 --- a/config/segment.php +++ b/config/segment.php @@ -25,5 +25,6 @@ */ 'write_key' => '', - + 'consumer' => null, + 'filename' => null, ]; From ebe82e811cac370fcfe230be4c8675d7aefd13c2 Mon Sep 17 00:00:00 2001 From: marioperezesteso Date: Wed, 21 Feb 2018 16:32:21 +0000 Subject: [PATCH 3/8] Load filename in options --- src/SegmentServiceProvider.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/SegmentServiceProvider.php b/src/SegmentServiceProvider.php index 8156856..794224e 100644 --- a/src/SegmentServiceProvider.php +++ b/src/SegmentServiceProvider.php @@ -37,12 +37,9 @@ public function boot() if ($writeKey = $this->app->config->get('segment.write_key')) { $options = [ 'consumer' => $this->app->config->get('segment.consumer') ?? null, + 'filename' => $this->app->config->get('segment.filename') ?? null, ]; - if ($fileName = $this->app->config->get('segment.filename')) { - $options['filename'] = $fileName; - } - Segment::init($writeKey, $options); } } From a1cae93690e59d2a6ab67b46fd5f8b143a4ead9c Mon Sep 17 00:00:00 2001 From: marioperezesteso Date: Wed, 21 Feb 2018 16:43:47 +0000 Subject: [PATCH 4/8] Remove coalesce operator when getting config --- src/SegmentServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SegmentServiceProvider.php b/src/SegmentServiceProvider.php index 794224e..2b00ae9 100644 --- a/src/SegmentServiceProvider.php +++ b/src/SegmentServiceProvider.php @@ -36,8 +36,8 @@ public function boot() if ($writeKey = $this->app->config->get('segment.write_key')) { $options = [ - 'consumer' => $this->app->config->get('segment.consumer') ?? null, - 'filename' => $this->app->config->get('segment.filename') ?? null, + 'consumer' => $this->app->config->get('segment.consumer'), + 'filename' => $this->app->config->get('segment.filename'), ]; Segment::init($writeKey, $options); From cc792046da95aa8a513c242f9b4900393a2370f2 Mon Sep 17 00:00:00 2001 From: marioperezesteso Date: Wed, 21 Feb 2018 17:50:10 +0000 Subject: [PATCH 5/8] Add init_options to configuration --- config/segment.php | 16 ++++++++++++++-- src/SegmentServiceProvider.php | 7 +------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config/segment.php b/config/segment.php index 6cd329a..3ee7c2f 100644 --- a/config/segment.php +++ b/config/segment.php @@ -19,12 +19,24 @@ |-------------------------------------------------------------------------- | | This option specifies key which enables you to write to Segment's API. + | These init options are specified in Segment Docs: https://segment.com/docs/sources/server/php/#configuration | | Default: '' | */ 'write_key' => '', - 'consumer' => null, - 'filename' => null, + + /* + |-------------------------------------------------------------------------- + | Segment Init Options + |-------------------------------------------------------------------------- + | + | This option specifies an array of options to initialize Segment. + | + | Default: [] + | + */ + + 'init_options' => [], ]; diff --git a/src/SegmentServiceProvider.php b/src/SegmentServiceProvider.php index 2b00ae9..33db9f4 100644 --- a/src/SegmentServiceProvider.php +++ b/src/SegmentServiceProvider.php @@ -35,12 +35,7 @@ public function boot() $this->setupConfig(); if ($writeKey = $this->app->config->get('segment.write_key')) { - $options = [ - 'consumer' => $this->app->config->get('segment.consumer'), - 'filename' => $this->app->config->get('segment.filename'), - ]; - - Segment::init($writeKey, $options); + Segment::init($writeKey, $this->app->config->get('segment.init_options')); } } From 7bb35f004e179d8edfd802cd2753bb5487467e13 Mon Sep 17 00:00:00 2001 From: marioperezesteso Date: Wed, 21 Feb 2018 18:00:57 +0000 Subject: [PATCH 6/8] Change comment position --- config/segment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/segment.php b/config/segment.php index 3ee7c2f..d879844 100644 --- a/config/segment.php +++ b/config/segment.php @@ -19,7 +19,6 @@ |-------------------------------------------------------------------------- | | This option specifies key which enables you to write to Segment's API. - | These init options are specified in Segment Docs: https://segment.com/docs/sources/server/php/#configuration | | Default: '' | @@ -33,6 +32,7 @@ |-------------------------------------------------------------------------- | | This option specifies an array of options to initialize Segment. + | These init options are specified in Segment Docs: https://segment.com/docs/sources/server/php/#configuration | | Default: [] | From a4fd12947482a2c695cde62d6dc9760e29b7cc2a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 3 Mar 2018 21:32:29 +0000 Subject: [PATCH 7/8] Fixed config comment --- config/segment.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/segment.php b/config/segment.php index d879844..2b48de1 100644 --- a/config/segment.php +++ b/config/segment.php @@ -32,7 +32,8 @@ |-------------------------------------------------------------------------- | | This option specifies an array of options to initialize Segment. - | These init options are specified in Segment Docs: https://segment.com/docs/sources/server/php/#configuration + | + | See: https://segment.com/docs/sources/server/php/#configuration. | | Default: [] | From 8dea96bcde0a2c17bb9b9d555b8b51dbd9a67518 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 3 Mar 2018 21:33:01 +0000 Subject: [PATCH 8/8] Fix backwards compatability with old config files --- src/SegmentServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SegmentServiceProvider.php b/src/SegmentServiceProvider.php index 33db9f4..8a53e20 100644 --- a/src/SegmentServiceProvider.php +++ b/src/SegmentServiceProvider.php @@ -35,7 +35,7 @@ public function boot() $this->setupConfig(); if ($writeKey = $this->app->config->get('segment.write_key')) { - Segment::init($writeKey, $this->app->config->get('segment.init_options')); + Segment::init($writeKey, (array) $this->app->config->get('segment.init_options')); } }