|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace CodexShaper\DBM\Commands; |
| 4 | + |
| 5 | +use CodexShaper\DBM\ManagerServiceProvider; |
| 6 | +use Illuminate\Console\Command; |
| 7 | +use Illuminate\Filesystem\Filesystem; |
| 8 | +use Symfony\Component\Console\Input\InputOption; |
| 9 | +use Symfony\Component\Process\Process; |
| 10 | + |
| 11 | +class DatabaseSeed extends Command |
| 12 | +{ |
| 13 | + /** |
| 14 | + * The console command name. |
| 15 | + * |
| 16 | + * @var string |
| 17 | + */ |
| 18 | + protected $name = 'dbm:seed'; |
| 19 | + /** |
| 20 | + * The console command description. |
| 21 | + * |
| 22 | + * @var string |
| 23 | + */ |
| 24 | + protected $description = 'Seed the Laravel Database Manager'; |
| 25 | + /** |
| 26 | + * The database Seeder Path. |
| 27 | + * |
| 28 | + * @var string |
| 29 | + */ |
| 30 | + protected $seedersPath = __DIR__.'/../../database/seeds/'; |
| 31 | + |
| 32 | + /** |
| 33 | + * Get Option. |
| 34 | + * |
| 35 | + * @return array |
| 36 | + */ |
| 37 | + protected function getOptions() |
| 38 | + { |
| 39 | + return [ |
| 40 | + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production', null], |
| 41 | + ]; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Get the composer command for the environment. |
| 46 | + * |
| 47 | + * @return string |
| 48 | + */ |
| 49 | + protected function findComposer() |
| 50 | + { |
| 51 | + if (file_exists(getcwd().'/composer.phar')) { |
| 52 | + return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
| 53 | + } |
| 54 | + |
| 55 | + return 'composer'; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Execute the console command. |
| 60 | + * |
| 61 | + * @param \Illuminate\Filesystem\Filesystem $filesystem |
| 62 | + * |
| 63 | + * @return void |
| 64 | + */ |
| 65 | + public function handle(Filesystem $filesystem) |
| 66 | + { |
| 67 | + $this->info('Database Manager Seeding...'); |
| 68 | + // Seeding Dummy Data |
| 69 | + $class = 'DatabaseManagerSeeder'; |
| 70 | + $file = $this->seedersPath.$class.'.php'; |
| 71 | + if (file_exists($file) && ! class_exists($class)) { |
| 72 | + require_once $file; |
| 73 | + } |
| 74 | + with(new $class())->run(); |
| 75 | + |
| 76 | + $this->info('Seeding Completed'); |
| 77 | + } |
| 78 | +} |
0 commit comments