This repository was archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathSegmentServiceProvider.php
More file actions
85 lines (73 loc) · 1.87 KB
/
SegmentServiceProvider.php
File metadata and controls
85 lines (73 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
/*
* This file is part of Alt Three Segment.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AltThree\Segment;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\ServiceProvider;
use Laravel\Lumen\Application as LumenApplication;
use Segment\Segment;
/**
* This is the segment service provider class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
class SegmentServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*
* @return void
*/
public function boot()
{
$this->setupConfig();
if ($writeKey = $this->app->config->get('segment.write_key')) {
Segment::init($writeKey, (array) $this->app->config->get('segment.init_options'));
}
$this->setupQueue();
}
/**
* Setup the config.
*
* @return void
*/
protected function setupConfig()
{
$source = realpath($raw = __DIR__.'/../config/segment.php') ?: $raw;
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
$this->publishes([$source => config_path('segment.php')]);
} elseif ($this->app instanceof LumenApplication) {
$this->app->configure('segment');
}
$this->mergeConfigFrom($source, 'segment');
}
/**
* Setup the queue.
*
* @return void
*/
protected function setupQueue()
{
if ($this->app->runningInConsole()) {
$this->app->queue->looping(function () {
Segment::flush();
});
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}