-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from hydephp/move-shared-logic-to-base-class
Move shared command logic to base action command class hydephp/develop@28d4644
- Loading branch information
github-actions
committed
Aug 11, 2022
1 parent
bc37dee
commit 6d71dc7
Showing
4 changed files
with
65 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Concerns; | ||
|
||
use LaravelZero\Framework\Commands\Command; | ||
|
||
/** | ||
* Base class for commands that run a simple action. | ||
*/ | ||
abstract class ActionCommand extends Command | ||
{ | ||
protected function action(string $title, \Closure $task, $resultMessage = 'Finished') | ||
{ | ||
/** @var float $actionTime */ | ||
$actionTime = microtime(true); | ||
|
||
$this->comment("$title..."); | ||
|
||
$result = $task(); | ||
|
||
$this->line(" > $resultMessage in ".$this->getExecutionTimeInMs($actionTime).'ms'); | ||
|
||
return $result; | ||
} | ||
|
||
protected function getExecutionTimeInMs(float $timeStart): string | ||
{ | ||
return number_format(((microtime(true) - $timeStart) * 1000), 2); | ||
} | ||
} |