Skip to content

Commit 2a4c30c

Browse files
authored
Add command (#48751)
1 parent 2dcc960 commit 2a4c30c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Illuminate/Foundation/Application.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,24 @@ public function runningInConsole()
709709
return $this->isRunningInConsole;
710710
}
711711

712+
/**
713+
* Determine if the application is running any of the given console commands.
714+
*
715+
* @param string|array ...$commands
716+
* @return bool
717+
*/
718+
public function runningConsoleCommand(...$commands)
719+
{
720+
if (! $this->runningInConsole()) {
721+
return false;
722+
}
723+
724+
return in_array(
725+
$_SERVER['argv'][1] ?? null,
726+
is_array($commands[0]) ? $commands[0] : $commands
727+
);
728+
}
729+
712730
/**
713731
* Determine if the application is running unit tests.
714732
*

src/Illuminate/Support/Facades/App.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @method static bool isProduction()
3939
* @method static string detectEnvironment(\Closure $callback)
4040
* @method static bool runningInConsole()
41+
* @method static bool runningConsoleCommand(string|array ...$commands)
4142
* @method static bool runningUnitTests()
4243
* @method static bool hasDebugModeEnabled()
4344
* @method static void registerConfiguredProviders()

0 commit comments

Comments
 (0)