LaravelRUS /
SleepingOwlAdmin
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SleepingOwl\Admin\Traits; |
||
| 4 | |||
| 5 | use KodiCMS\Assets\Facades\PackageManager; |
||
| 6 | |||
| 7 | trait Assets |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var \KodiCMS\Assets\Package |
||
| 11 | */ |
||
| 12 | protected $package; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param string $handle |
||
| 16 | * @param string $script |
||
| 17 | * @param array $dependency |
||
| 18 | * |
||
| 19 | * @return $this |
||
| 20 | */ |
||
| 21 | public function addScript($handle, $script, array $dependency = []) |
||
| 22 | { |
||
| 23 | if (is_null($handle)) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 24 | $handle = $script; |
||
| 25 | } |
||
| 26 | |||
| 27 | $this->package->js($handle, $script, $dependency, true); |
||
| 28 | |||
| 29 | return $this; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param string $handle |
||
| 34 | * @param string $style |
||
| 35 | * @param array $attributes |
||
| 36 | * |
||
| 37 | * @return $this |
||
| 38 | */ |
||
| 39 | public function addStyle($handle, $style, array $attributes = []) |
||
| 40 | { |
||
| 41 | if (is_null($handle)) { |
||
|
0 ignored issues
–
show
|
|||
| 42 | $handle = $style; |
||
| 43 | } |
||
| 44 | |||
| 45 | $this->package->css($handle, $style, $attributes); |
||
| 46 | |||
| 47 | return $this; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string ... $package |
||
| 52 | * |
||
| 53 | * @return $this |
||
| 54 | */ |
||
| 55 | public function withPackage($packages) |
||
| 56 | { |
||
| 57 | $packages = is_array($packages) |
||
| 58 | ? $packages |
||
| 59 | : func_get_args(); |
||
| 60 | |||
| 61 | $this->package->with($packages); |
||
| 62 | |||
| 63 | return $this; |
||
| 64 | } |
||
| 65 | |||
| 66 | protected function initializePackage() |
||
| 67 | 168 | { |
|
| 68 | if (is_null($this->package = PackageManager::load(get_called_class()))) { |
||
| 69 | 168 | $this->package = PackageManager::add(get_called_class()); |
|
| 70 | 168 | } |
|
| 71 | 168 | } |
|
| 72 | 168 | ||
| 73 | protected function includePackage() |
||
| 74 | 11 | { |
|
| 75 | app('sleeping_owl.meta')->loadPackage($this->package->getName()); |
||
| 76 | 11 | } |
|
| 77 | } |
||
| 78 |