Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 408fe64

Browse files
committed
replace autoreg with cmnd
1 parent f093676 commit 408fe64

File tree

3 files changed

+79
-55
lines changed

3 files changed

+79
-55
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Create menus & pages that support (multiLocale "title, url, body, ...", nesting,
1515

1616
- `composer require ctf0/simple-menu`
1717

18-
- after installation, package will auto-add
18+
- after installation, run php artisan `sm:setup` to add
1919
+ package routes to `routes/web.php`
2020
+ package assets compiling to `webpack.mix.js`
2121

@@ -61,7 +61,7 @@ return [
6161
'listClasses' => [
6262
'ul' => 'menu-list',
6363
'li' => 'list-item',
64-
'a' => 'is-active',
64+
'a' => 'is-active',
6565
],
6666
6767
/*
@@ -144,12 +144,12 @@ return [
144144
* ex. "class ExampleController extends PagesController"
145145
*/
146146
'controllers'=> [
147-
'admin' => '\ctf0\SimpleMenu\Controllers\Admin\AdminController@index',
148-
'users' => '\ctf0\SimpleMenu\Controllers\Admin\UsersController',
149-
'pages' => '\ctf0\SimpleMenu\Controllers\Admin\PagesController',
150-
'roles' => '\ctf0\SimpleMenu\Controllers\Admin\RolesController',
151147
'permissions' => '\ctf0\SimpleMenu\Controllers\Admin\PermissionsController',
152-
'menus' => '\ctf0\SimpleMenu\Controllers\Admin\MenusController',
148+
'admin' => '\ctf0\SimpleMenu\Controllers\Admin\AdminController@index',
149+
'users' => '\ctf0\SimpleMenu\Controllers\Admin\UsersController',
150+
'pages' => '\ctf0\SimpleMenu\Controllers\Admin\PagesController',
151+
'roles' => '\ctf0\SimpleMenu\Controllers\Admin\RolesController',
152+
'menus' => '\ctf0\SimpleMenu\Controllers\Admin\MenusController',
153153
],
154154
];
155155
```

src/Commands/PackageSetup.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace ctf0\SimpleMenu\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class PackageSetup extends Command
8+
{
9+
protected $file;
10+
protected $signature = 'sm:setup';
11+
protected $description = 'setup package routes & assets compiling';
12+
13+
/**
14+
* Create a new command instance.
15+
*/
16+
public function __construct()
17+
{
18+
$this->file = $this->app['files'];
19+
20+
parent::__construct();
21+
}
22+
23+
/**
24+
* Execute the console command.
25+
*
26+
* @return mixed
27+
*/
28+
public function handle()
29+
{
30+
// routes
31+
$route_file = base_path('routes/web.php');
32+
$search = 'SimpleMenu';
33+
34+
if ($this->checkExist($route_file, $search)) {
35+
$data = "\n// SimpleMenu\nSimpleMenu::menuRoutes();";
36+
37+
$this->file->append($route_file, $data);
38+
}
39+
40+
// mix
41+
$mix_file = base_path('webpack.mix.js');
42+
$search = 'SimpleMenu';
43+
44+
if ($this->checkExist($mix_file, $search)) {
45+
$data = "\n// SimpleMenu\nmix.sass('resources/assets/vendor/SimpleMenu/sass/style.scss', 'public/assets/vendor/SimpleMenu/style.css')";
46+
47+
$this->file->append($mix_file, $data);
48+
}
49+
50+
$this->info('All Done');
51+
}
52+
53+
/**
54+
* [checkExist description].
55+
*
56+
* @param [type] $file [description]
57+
* @param [type] $search [description]
58+
*
59+
* @return [type] [description]
60+
*/
61+
protected function checkExist($file, $search)
62+
{
63+
return $this->file->exists($file) && !str_contains($this->file->get($file), $search);
64+
}
65+
}

src/SimpleMenuServiceProvider.php

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ctf0\SimpleMenu;
44

55
use Illuminate\Support\ServiceProvider;
6+
use ctf0\SimpleMenu\Commands\PackageSetup;
67
use ctf0\SimpleMenu\Observers\MenuObserver;
78
use ctf0\SimpleMenu\Observers\PageObserver;
89
use ctf0\SimpleMenu\Observers\UserObserver;
@@ -13,25 +14,17 @@
1314

1415
class SimpleMenuServiceProvider extends ServiceProvider
1516
{
16-
protected $file;
17-
1817
/**
1918
* Perform post-registration booting of services.
2019
*/
2120
public function boot()
2221
{
23-
$this->file = $this->app['files'];
24-
2522
$this->packagePublish();
2623
$this->observers();
2724
$this->macros();
2825
$this->viewComp();
26+
$this->command();
2927
$this->app['simplemenu'];
30-
31-
// append extra data
32-
if (!$this->app['cache']->store('file')->has('ct-sm')) {
33-
$this->autoReg();
34-
}
3528
}
3629

3730
protected function packagePublish()
@@ -120,49 +113,15 @@ protected function viewComp()
120113
}
121114

122115
/**
123-
* [autoReg description].
124-
*
125-
* @return [type] [description]
126-
*/
127-
protected function autoReg()
128-
{
129-
// routes
130-
$route_file = base_path('routes/web.php');
131-
$search = 'SimpleMenu';
132-
133-
if ($this->checkExist($route_file, $search)) {
134-
$data = "\n// SimpleMenu\nSimpleMenu::menuRoutes();";
135-
136-
$this->file->append($route_file, $data);
137-
}
138-
139-
// mix
140-
$mix_file = base_path('webpack.mix.js');
141-
$search = 'SimpleMenu';
142-
143-
if ($this->checkExist($mix_file, $search)) {
144-
$data = "\n// SimpleMenu\nmix.sass('resources/assets/vendor/SimpleMenu/sass/style.scss', 'public/assets/vendor/SimpleMenu/style.css')";
145-
146-
$this->file->append($mix_file, $data);
147-
}
148-
149-
// run check once
150-
$this->app['cache']->store('file')->rememberForever('ct-sm', function () {
151-
return 'added';
152-
});
153-
}
154-
155-
/**
156-
* [checkExist description].
157-
*
158-
* @param [type] $file [description]
159-
* @param [type] $search [description]
116+
* package commands.
160117
*
161118
* @return [type] [description]
162119
*/
163-
protected function checkExist($file, $search)
120+
protected function command()
164121
{
165-
return $this->file->exists($file) && !str_contains($this->file->get($file), $search);
122+
$this->commands([
123+
PackageSetup::class,
124+
]);
166125
}
167126

168127
/**

0 commit comments

Comments
 (0)