public function register(Extension $commandExtension, int $priority = 0)
{
$this->extensions[] = [self::EXTENSION_KEY => $commandExtension, self::EXTENSION_PRIORITY_KEY => $priority];
if (count($this->extensions) > 1) {
uasort($this->extensions, function ($itemA, $itemB) {
if ($itemA[self::EXTENSION_PRIORITY_KEY] === $itemB[self::EXTENSION_PRIORITY_KEY]) {
return 0;
}
return $itemA[self::EXTENSION_PRIORITY_KEY] > $itemB[self::EXTENSION_PRIORITY_KEY] ? -1 : 1;
});
}
}
function it_execute_extension_points(Extension $extension) { $command = new AddToCart("SKU", 1, (string) CartId::generate()); $extension->pre($command, Argument::type(ServiceLocator::class))->shouldBeCalled(); $extension->post($command, Argument::type(ServiceLocator::class))->shouldBeCalled(); $extension->expands($command)->willReturn(true); $this->registry->register($extension->getWrappedObject()); $this->execute($command, function () { }); }