mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
47 lines
1006 B
PHP
47 lines
1006 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pest\Support;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final class HigherOrderMessageCollection
|
|
{
|
|
/**
|
|
* @var array<int, HigherOrderMessage>
|
|
*/
|
|
private $messages = [];
|
|
|
|
/**
|
|
* Adds a new higher order message to the collection.
|
|
*
|
|
* @param array<int, mixed> $arguments
|
|
*/
|
|
public function add(string $filename, int $line, string $methodName, array $arguments): void
|
|
{
|
|
$this->messages[] = new HigherOrderMessage($filename, $line, $methodName, $arguments);
|
|
}
|
|
|
|
/**
|
|
* Proxy all the messages starting from the target.
|
|
*/
|
|
public function chain(object $target): void
|
|
{
|
|
foreach ($this->messages as $message) {
|
|
$target = $message->call($target) ?? $target;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Proxy all the messages to the target.
|
|
*/
|
|
public function proxy(object $target): void
|
|
{
|
|
foreach ($this->messages as $message) {
|
|
$message->call($target);
|
|
}
|
|
}
|
|
}
|