Completed
Push — master ( dd414d...cbbb05 )
by Ryan
07:19
created

MergeStreamConfig::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php namespace Anomaly\Streams\Platform\Stream\Command;
2
3
use Anomaly\Streams\Platform\Addon\AddonCollection;
4
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface;
5
use Illuminate\Contracts\Bus\SelfHandling;
6
use Illuminate\Contracts\Config\Repository;
7
8
/**
9
 * Class MergeStreamConfig
10
 *
11
 * @link          http://pyrocms.com/
12
 * @author        PyroCMS, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 * @package       Anomaly\Streams\Platform\Stream\Command
15
 */
16
class MergeStreamConfig implements SelfHandling
17
{
18
19
    /**
20
     * The stream instance.
21
     *
22
     * @var StreamInterface
23
     */
24
    protected $stream;
25
26
    /**
27
     * Create a new MergeStreamConfig instance.
28
     *
29
     * @param StreamInterface $stream
30
     */
31
    public function __construct(StreamInterface $stream)
32
    {
33
        $this->stream = $stream;
34
    }
35
36
    /**
37
     * Handle the command.
38
     *
39
     * @param AddonCollection $addons
40
     * @param Repository      $repository
41
     */
42
    public function handle(AddonCollection $addons, Repository $repository)
43
    {
44
        $slug      = $this->stream->getSlug();
45
        $namespace = $this->stream->getNamespace();
46
47
        foreach ($addons->withConfig("streams.{$namespace}.{$slug}") as $config) {
48
            $this->stream->mergeConfig($config);
49
        }
50
51
        $this->stream->mergeConfig($repository->get("streams::streams.{$namespace}.{$slug}", []));
52
    }
53
}
54