-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfiledCommand.php
More file actions
38 lines (32 loc) · 960 Bytes
/
ProfiledCommand.php
File metadata and controls
38 lines (32 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Perfbase\CakePHP\Command;
use Cake\Command\Command;
use Cake\Console\ConsoleIo;
use Perfbase\CakePHP\Lifecycle\ConsoleCommandLifecycle;
abstract class ProfiledCommand extends Command
{
/**
* @param array<int, string> $argv
* @return int|null
* @throws \Throwable
*/
public function run(array $argv, ConsoleIo $io): ?int
{
$lifecycle = new ConsoleCommandLifecycle($this);
$lifecycle->startProfiling();
try {
$result = parent::run($argv, $io);
if (is_int($result)) {
$lifecycle->setExitCode($result);
} elseif ($result === null) {
$lifecycle->setExitCode(0);
}
return $result;
} catch (\Throwable $exception) {
$lifecycle->setException($exception->getMessage());
throw $exception;
} finally {
$lifecycle->stopProfiling();
}
}
}