1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand as IdeHelperGeneratorCommand; |
6
|
|
|
use SleepingOwl\Admin\Console\Generator; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* A command to generate autocomplete information for your IDE. |
10
|
|
|
* |
11
|
|
|
* @author Aios Dave <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class GeneratorCommand extends IdeHelperGeneratorCommand |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* The console command name. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $name = 'sleepingowl:ide:generate'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
24
|
|
|
*/ |
25
|
|
|
public function handle() |
26
|
|
|
{ |
27
|
|
|
if (file_exists(base_path().'/vendor/compiled.php') || |
28
|
|
|
file_exists(base_path().'/bootstrap/cache/compiled.php') || |
29
|
|
|
file_exists(base_path().'/storage/framework/compiled.php')) { |
30
|
|
|
$this->error( |
31
|
|
|
'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)' |
32
|
|
|
); |
33
|
|
|
} else { |
34
|
|
|
$filename = (string) $this->argument('filename'); |
35
|
|
|
$format = (string) $this->option('format'); |
36
|
|
|
|
37
|
|
|
// Strip the php extension |
38
|
|
|
if (substr($filename, -4, 4) == '.php') { |
39
|
|
|
$filename = substr($filename, 0, -4); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$filename = implode('.', [$filename, $format]); |
43
|
|
|
|
44
|
|
|
if ($this->option('memory')) { |
45
|
|
|
$this->useMemoryDriver(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$helpers = ''; |
49
|
|
|
if ($this->option('helpers') || ($this->config->get('ide-helper.include_helpers'))) { |
50
|
|
|
foreach ($this->config->get('ide-helper.helper_files', []) as $helper) { |
51
|
|
|
if (file_exists($helper)) { |
52
|
|
|
$helpers .= str_replace(['<?php', '?>'], '', $this->files->get($helper)); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} else { |
56
|
|
|
$helpers = ''; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers); |
60
|
|
|
$content = $generator->generate($format); |
61
|
|
|
$written = (int) $this->files->put($filename, $content); |
62
|
|
|
|
63
|
|
|
if ($written === false) { |
|
|
|
|
64
|
|
|
$this->error("The helper file could not be created at $filename"); |
65
|
|
|
} else { |
66
|
|
|
$this->info("A new helper file was written to $filename"); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|