|
1
|
|
|
<?php namespace Mascame\Artificer\Extension; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Str; |
|
4
|
|
|
use Mascame\Extender\Booter\BooterInterface; |
|
5
|
|
|
use Symfony\Component\CssSelector\XPath\Extension\AbstractExtension; |
|
|
|
|
|
|
6
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
|
7
|
|
|
|
|
8
|
|
|
class Booter extends \Mascame\Extender\Booter\Booter implements BooterInterface { |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @var \Mascame\Artificer\Plugin\Manager|\Mascame\Artificer\Widget\Manager |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $manager; |
|
14
|
|
|
|
|
15
|
|
|
public function boot($instance, $name) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->beforeBooting($instance, $name); |
|
18
|
|
|
|
|
19
|
|
|
parent::boot($instance, $name); |
|
20
|
|
|
|
|
21
|
|
|
$this->afterBooting($instance, $name); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param $instance |
|
26
|
|
|
* @param $name |
|
27
|
|
|
*/ |
|
28
|
|
|
public function beforeBooting($instance, $name) { |
|
29
|
|
|
$instance->namespace = $name; |
|
30
|
|
|
|
|
31
|
|
|
if (! $instance->version) { |
|
32
|
|
|
$instance->version = $this->manager->getVersion($instance->namespace); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if (! $instance->name) $instance->name = $name; |
|
36
|
|
|
|
|
37
|
|
|
if (! $instance->slug) $instance->slug = Str::slug($name); |
|
38
|
|
|
|
|
39
|
|
|
$this->manager->setSlug($instance->slug, $instance->namespace); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param $instance \Mascame\Artificer\Extension\AbstractExtension |
|
44
|
|
|
* @param $name |
|
45
|
|
|
*/ |
|
46
|
|
|
public function afterBooting($instance, $name) { |
|
47
|
|
|
if (! $this->manager->isInstalled($instance->namespace)) return; |
|
48
|
|
|
|
|
49
|
|
|
// Todo: add assets |
|
50
|
|
|
//die('here!'); |
|
51
|
|
|
// \Assets::config([ |
|
52
|
|
|
// 'group1' => [ |
|
53
|
|
|
// |
|
54
|
|
|
// ], |
|
55
|
|
|
// ]); |
|
56
|
|
|
$package = $instance->namespace . '/' . $instance->slug; |
|
57
|
|
|
|
|
58
|
|
|
\Assets::config([ |
|
59
|
|
|
|
|
60
|
|
|
])->add(["$package:bar.css", "$package:foo.js"]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: