Completed
Push — dev ( 9ff19d...9155f2 )
by Marc
03:27
created

Booter::beforeBooting()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 1
Metric Value
c 6
b 0
f 1
dl 0
loc 15
rs 8.8571
cc 6
eloc 9
nc 24
nop 2
1
<?php namespace Mascame\Artificer\Extension;
2
3
use Illuminate\Support\Str;
4
use Mascame\Artificer\Artificer;
5
use Mascame\Extender\Booter\BooterInterface;
6
7
class Booter extends \Mascame\Extender\Booter\Booter implements BooterInterface {
8
9
    /**
10
     * @var \Mascame\Artificer\Plugin\Manager|\Mascame\Artificer\Widget\Manager
11
     */
12
    protected $manager;
13
14
    public function boot($instance, $name)
15
    {
16
        $this->beforeBooting($instance, $name);
17
18
        parent::boot($instance, $name);
19
20
        $this->afterBooting($instance, $name);
21
    }
22
23
    /**
24
     * @param $instance
25
     * @param $name
26
     */
27
    protected function beforeBooting($instance, $name) {
28
        if (! $instance->namespace) $instance->namespace = $name;
29
        if (! $instance->name) $instance->name = $name;
30
        if (property_exists($instance, 'assetsPath')) {
31
            if (! $instance->assetsPath) $instance->assetsPath = 'packages/' . $instance->package . '/';
32
        }
33
34
        if (! $instance->slug) {
35
            // For slug readability
36
            $name = str_replace('\\', '-', $name);
37
            $instance->slug = Str::slug($name);
38
        }
39
40
        $this->manager->setSlug($instance->slug, $instance->namespace);
41
    }
42
    
43
    /**
44
     * @param $instance \Mascame\Artificer\Extension\AbstractExtension
45
     * @param $name
46
     */
47
    protected function afterBooting($instance, $name) {
48
        if (! $this->manager->isInstalled($instance->namespace)) return;
49
50
        $this->addAssets($instance);
51
    }
52
53
    /**
54
     * @param $instance
55
     */
56
    protected function addAssets($instance) {
0 ignored issues
show
Unused Code introduced by
The parameter $instance is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
        // Todo: only add assets by default if its a plugin (widgets will load only when necessary)
58
//        $instance->assets(Artificer::assetManager());
59
    }
60
}
61