-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add illuminate/events as suggestion * Add post migration to config * Add listener to generate model helper * Add event listeners if enabled * Fix config file format * Add docblock for shouldRun flag * Allow running multiple commands after migrations * Simplify config * Change default value
- Loading branch information
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Listeners; | ||
|
||
use Illuminate\Console\Events\CommandFinished; | ||
use Illuminate\Contracts\Config\Repository as Config; | ||
use Illuminate\Contracts\Console\Kernel as Artisan; | ||
|
||
class GenerateModelHelper | ||
{ | ||
/** | ||
* Tracks whether we should run the models command on the CommandFinished event or not. | ||
* Set to true by the MigrationsEnded event, needs to be cleared before artisan call to prevent infinite loop. | ||
* | ||
* @var bool | ||
*/ | ||
public static $shouldRun = false; | ||
|
||
/** @var \Illuminate\Contracts\Console\Kernel */ | ||
protected $artisan; | ||
|
||
/** @var \Illuminate\Contracts\Config\Repository */ | ||
protected $config; | ||
|
||
/** | ||
* @param \Illuminate\Contracts\Console\Kernel $artisan | ||
* @param \Illuminate\Contracts\Config\Repository $config | ||
*/ | ||
public function __construct(Artisan $artisan, Config $config) | ||
{ | ||
$this->artisan = $artisan; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param CommandFinished $event | ||
*/ | ||
public function handle(CommandFinished $event) | ||
{ | ||
if (!self::$shouldRun) { | ||
return; | ||
} | ||
|
||
self::$shouldRun = false; | ||
|
||
foreach ($this->config->get('ide-helper.post_migrate', []) as $command) { | ||
$this->artisan->call($command, [], $event->output); | ||
} | ||
} | ||
} |