Skip to content
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

[10.x] Add runningConsoleCommand(...$commands) method #48751

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
18 changes: 18 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,24 @@ public function runningInConsole()
return $this->isRunningInConsole;
}

/**
* Determine if the application is running any of the given console commands.
*
* @param string|array ...$commands
* @return bool
*/
public function runningConsoleCommand(...$commands)
{
if (! $this->runningInConsole()) {
return false;
}

return in_array(
$_SERVER['argv'][1] ?? null,
is_array($commands[0]) ? $commands[0] : $commands
);
}

/**
* Determine if the application is running unit tests.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @method static bool isProduction()
* @method static string detectEnvironment(\Closure $callback)
* @method static bool runningInConsole()
* @method static bool runningConsoleCommand(string|array ...$commands)
* @method static bool runningUnitTests()
* @method static bool hasDebugModeEnabled()
* @method static void registerConfiguredProviders()
Expand Down