-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add contexts for profiler * styleci * psalm fix * Profiler tests * fix * add more test * styleci
- Loading branch information
Showing
10 changed files
with
195 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Profiler\Context; | ||
|
||
use Throwable; | ||
use Yiisoft\Db\Profiler\ContextInterface; | ||
|
||
abstract class AbstractContext implements ContextInterface | ||
{ | ||
protected const METHOD = 'method'; | ||
protected const EXCEPTION = 'exception'; | ||
|
||
private Throwable|null $exception = null; | ||
|
||
public function __construct(private string $method) | ||
{ | ||
} | ||
|
||
public function setException(Throwable $e): static | ||
{ | ||
$this->exception = $e; | ||
return $this; | ||
} | ||
|
||
public function asArray(): array | ||
{ | ||
return [ | ||
self::METHOD => $this->method, | ||
self::EXCEPTION => $this->exception, | ||
]; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Profiler\Context; | ||
|
||
final class CommandContext extends AbstractContext | ||
{ | ||
private const LOG_CONTEXT = 'logContext'; | ||
private const SQL = 'sql'; | ||
private const PARAMS = 'params'; | ||
|
||
public function __construct( | ||
private string $method, | ||
private string $logContext, | ||
private string $sql, | ||
private array $params, | ||
) { | ||
parent::__construct($this->method); | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return 'command'; | ||
} | ||
|
||
public function asArray(): array | ||
{ | ||
return parent::asArray() + [ | ||
self::LOG_CONTEXT => $this->logContext, | ||
self::SQL => $this->sql, | ||
self::PARAMS => $this->params, | ||
]; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Profiler\Context; | ||
|
||
final class ConnectionContext extends AbstractContext | ||
{ | ||
public function getType(): string | ||
{ | ||
return 'connection'; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Profiler; | ||
|
||
interface ContextInterface | ||
{ | ||
/** | ||
* @return string Type of the context | ||
*/ | ||
public function getType(): string; | ||
|
||
public function asArray(): array; | ||
} |
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