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) { |
|
|
|
|
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
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.