Final Class Yiisoft\Middleware\Dispatcher\Debug\MiddlewareCollector
| Inheritance | Yiisoft\Middleware\Dispatcher\Debug\MiddlewareCollector |
|---|---|
| Implements | Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface |
| Uses Traits | Yiisoft\Yii\Debug\Collector\CollectorTrait |
Public Methods
Method Details
| public mixed __construct ( \Yiisoft\Yii\Debug\Collector\TimelineCollector $timelineCollector ) | ||
| $timelineCollector | \Yiisoft\Yii\Debug\Collector\TimelineCollector | |
public function __construct(
private readonly TimelineCollector $timelineCollector
) {
}
public function collect(BeforeMiddleware|AfterMiddleware $event): void
{
if (!$this->isActive()) {
return;
}
if (
method_exists($event->getMiddleware(), '__debugInfo')
&& (new ReflectionClass($event->getMiddleware()))->isAnonymous()
) {
/**
* @var callable $callback
* @psalm-suppress MixedArrayAccess
*/
$callback = $event->getMiddleware()->__debugInfo()['callback'];
if (is_array($callback)) {
if (is_string($callback[0])) {
$name = implode('::', $callback);
} else {
$name = $callback[0]::class . '::' . $callback[1];
}
} elseif (is_string($callback)) {
$name = '{closure:' . $callback . '}';
} else {
$name = 'object(Closure)#' . spl_object_id($callback);
}
} else {
$name = $event->getMiddleware()::class;
}
if ($event instanceof BeforeMiddleware) {
$this->beforeStack[] = [
'name' => $name,
'time' => microtime(true),
'memory' => memory_get_usage(),
'request' => $event->getRequest(),
];
} else {
$this->afterStack[] = [
'name' => $name,
'time' => microtime(true),
'memory' => memory_get_usage(),
'response' => $event->getResponse(),
];
}
$this->timelineCollector->collect($this, spl_object_id($event));
}
| public array getCollected ( ) |
public function getCollected(): array
{
if (!$this->isActive()) {
return [];
}
$beforeStack = $this->beforeStack;
$afterStack = $this->afterStack;
$beforeAction = array_pop($beforeStack);
$afterAction = array_shift($afterStack);
$actionHandler = [];
if (is_array($beforeAction) && is_array($afterAction)) {
$actionHandler = $this->getActionHandler($beforeAction, $afterAction);
}
return [
'beforeStack' => $beforeStack,
'actionHandler' => $actionHandler,
'afterStack' => $afterStack,
];
}
| public array getSummary ( ) |
public function getSummary(): array
{
if (!$this->isActive()) {
return [];
}
return [
'total' => ($total = count($this->beforeStack)) > 0 ? $total - 1 : 0, // Remove action handler
];
}
Signup or Login in order to comment.