Completed
Pull Request — master (#11)
by
unknown
02:46
created

MakeEchoServerConfig::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace MadWeb\Initializer\Jobs;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Foundation\Bus\Dispatchable;
7
8
class MakeEchoServerConfig
9
{
10
    use Dispatchable, Queueable;
11
12
    /**
13
     * Config for overriding default echo server values.
14
     */
15
    protected $config;
16
17
    public function __construct(array $config = [])
18
    {
19
        $this->config = $config;
20
    }
21
22
    /**
23
     * Execute the job.
24
     *
25
     * @return string
26
     */
27
    public function handle()
28
    {
29
        $path = base_path('laravel-echo-server.json');
30
        file_put_contents(
31
            $path,
32
            json_encode(array_replace_recursive([
33
                'authHost' => url('/'),
34
                'authEndpoint' => '/broadcasting/auth',
35
                'database' => 'redis',
36
                'databaseConfig' => [
37
                    'redis' => [
38
                        'host' => config('database.redis.default.host'),
39
                        'port' => config('database.redis.default.port'),
40
                    ],
41
                    'sqlite' => [
42
                        'databasePath' => '/storage/laravel-echo-server.sqlite',
43
                    ],
44
                ],
45
                'devMode' => config('app.debug'),
46
                'host' => parse_url(url('/'), PHP_URL_HOST),
47
                'port' => 6001,
48
                'protocol' => 'http',
49
                'socketio' => [],
50
                'sslCertPath' => '',
51
                'sslKeyPath' => '',
52
                'sslCertChainPath' => '',
53
                'sslPassphrase' => '',
54
                'apiOriginAllow' => [
55
                    'allowCors' => false,
56
                    'allowOrigin' => '',
57
                    'allowMethods' => '',
58
                    'allowHeaders' => '',
59
                ],
60
            ], $this->config), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
61
        );
62
63
        return 'Config file for web-socket server created. File: '.$path;
64
    }
65
}
66