Skip to content

Commit ad8f19f

Browse files
committed
Add listener to generate helpers after discovery
1 parent 16a3ba4 commit ad8f19f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Barryvdh\LaravelIdeHelper\Listeners;
4+
5+
use Illuminate\Console\Events\CommandFinished;
6+
use Illuminate\Contracts\Config\Repository as Config;
7+
use Illuminate\Contracts\Console\Kernel as Artisan;
8+
9+
class GenerateHelperAndMeta
10+
{
11+
/** @var \Illuminate\Contracts\Console\Kernel */
12+
protected $artisan;
13+
14+
/** @var \Illuminate\Contracts\Config\Repository */
15+
protected $config;
16+
17+
/**
18+
* @param \Illuminate\Contracts\Console\Kernel $artisan
19+
* @param \Illuminate\Contracts\Config\Repository $config
20+
*/
21+
public function __construct(Artisan $artisan, Config $config)
22+
{
23+
$this->artisan = $artisan;
24+
$this->config = $config;
25+
}
26+
27+
/**
28+
* Handle the event.
29+
*
30+
* @param CommandFinished $event
31+
*/
32+
public function handle(CommandFinished $event)
33+
{
34+
if ($this->shouldntRun($event)) {
35+
return;
36+
}
37+
38+
foreach ($this->config->get('ide-helper.post_discover', []) as $command) {
39+
$this->artisan->call($command, [], $event->output);
40+
}
41+
}
42+
43+
protected function shouldntRun(CommandFinished $event): bool
44+
{
45+
return $event->exitCode != 0 ||
46+
$event->command != 'package:discover' ||
47+
$event->input->hasParameterOption(['--version', '-V'], true) ||
48+
$event->input->hasParameterOption(['--help', '-h'], true);
49+
}
50+
}

0 commit comments

Comments
 (0)