diff --git a/src/Commands/InstallMenuBuilder.php b/src/Commands/InstallMenuBuilder.php index 330ae12..f926fb2 100644 --- a/src/Commands/InstallMenuBuilder.php +++ b/src/Commands/InstallMenuBuilder.php @@ -27,10 +27,10 @@ class InstallMenuBuilder extends Command * * @var string */ - protected $seedersPath = __DIR__.'/../../database/seeds/'; + protected $seedersPath = __DIR__ . '/../../database/seeds/'; /** - * Get Option. + * Get Option * * @return array */ @@ -48,10 +48,10 @@ protected function getOptions() */ protected function findComposer() { - if (file_exists(getcwd().'/composer.phar')) { - return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; + if (file_exists(getcwd() . '/composer.phar')) { + /* return '"' . PHP_BINARY . '" ' . getcwd() . '/composer.phar'; // Leading quotes causing duplicate returns (origin) */ + return PHP_BINARY . '" ' . getcwd() . '/composer.phar'; /* Removed leading quotation marks */ } - return 'composer'; } @@ -74,7 +74,8 @@ public function handle(Filesystem $filesystem) $this->info('Dumping the autoloaded files and reloading all new files'); $composer = $this->findComposer(); - $process = Process::fromShellCommandline($composer.' dump-autoload'); + /* $process = new Process($composer . ' dump-autoload'); // Process waits array, as can be seen during the release of the exception: "Symfony\Component\Process\Process::__construct(): Argument #1 ($command) must be of type array, string given" */ + $process = new Process([$composer . ' dump-autoload']); /* Command passed as array */ $process->setTimeout(null); // Setting timeout to null to prevent installation from stopping at a certain point in time $process->setWorkingDirectory(base_path())->run(); @@ -84,13 +85,13 @@ public function handle(Filesystem $filesystem) if (false === strpos($routes_contents, 'MenuBuilder::routes();')) { $filesystem->append( base_path('routes/web.php'), - "\n\nMenuBuilder::routes();\n" + "\n\nRoute::group(['prefix' => config('menu.prefix')], function () {\n MenuBuilder::routes();\n});\n" ); } // Seeding Dummy Data $class = 'MenuDatabaseSeeder'; - $file = $this->seedersPath.$class.'.php'; + $file = $this->seedersPath . $class . '.php'; if (file_exists($file) && !class_exists($class)) { require_once $file; diff --git a/src/Commands/InstallMenuBuilder_v2.5.php b/src/Commands/InstallMenuBuilder_v2.5.php new file mode 100644 index 0000000..c23e937 --- /dev/null +++ b/src/Commands/InstallMenuBuilder_v2.5.php @@ -0,0 +1,103 @@ +info('Publishing the MenuBuilder assets, database, and config files'); + // Publish only relevant resources on install + $tags = ['menu.seeds', 'menu.config']; + $this->call('vendor:publish', ['--provider' => MenuServiceProvider::class, '--tag' => $tags]); + + $this->info('Migrating the database tables into your application'); + $this->call('migrate', ['--force' => $this->option('force')]); + + $this->info('Dumping the autoloaded files and reloading all new files'); + $composer = $this->findComposer(); + /* $process = new Process($composer . ' dump-autoload'); // Process waits array, as can be seen during the release of the exception: "Symfony\Component\Process\Process::__construct(): Argument #1 ($command) must be of type array, string given" */ + $process = new Process([$composer . ' dump-autoload']); /* Comando passado como array */ + $process->setTimeout(null); // Setting timeout to null to prevent installation from stopping at a certain point in time + $process->setWorkingDirectory(base_path())->run(); + + // Load Permission routes into application's 'routes/web.php' + $this->info('Adding Permission routes to routes/web.php'); + $routes_contents = $filesystem->get(base_path('routes/web.php')); + if (false === strpos($routes_contents, 'MenuBuilder::routes();')) { + $filesystem->append( + base_path('routes/web.php'), + "\n\nRoute::group(['prefix' => config('menu.prefix')], function () {\n MenuBuilder::routes();\n});\n" + ); + } + + // Seeding Dummy Data + $class = 'MenuDatabaseSeeder'; + $file = $this->seedersPath . $class . '.php'; + + if (file_exists($file) && !class_exists($class)) { + require_once $file; + } + with(new $class())->run(); + + $this->info('Seeding Completed'); + } +}