Skip to content

Installer Fix - Exception ->" Argument #1 ($command) must be of type array, string given" #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/Commands/InstallMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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';
}

Expand All @@ -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();

Expand All @@ -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;
Expand Down
103 changes: 103 additions & 0 deletions src/Commands/InstallMenuBuilder_v2.5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace CodexShaper\Menu\Commands;

use CodexShaper\Menu\MenuServiceProvider;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Process\Process;

class InstallMenuBuilder extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'menu:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install the Laravel Menu Builder';
/**
* The database Seeder Path.
*
* @var string
*/
protected $seedersPath = __DIR__ . '/../../database/seeds/';

/**
* Get Option
*
* @return array
*/
protected function getOptions()
{
return [
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production', null],
];
}

/**
* Get the composer command for the environment.
*
* @return string
*/
protected function findComposer()
{
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';
}

/**
* Execute the console command.
*
* @param \Illuminate\Filesystem\Filesystem $filesystem
*
* @return void
*/
public function handle(Filesystem $filesystem)
{
$this->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');
}
}