Dumplie\SharedKernel\Application\Command\ExtensionRegistry::register PHP Method

register() public method

public register ( Dumplie\SharedKernel\Application\Command\Extension $commandExtension, integer $priority )
$commandExtension Dumplie\SharedKernel\Application\Command\Extension
$priority integer
    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;
            });
        }
    }

Usage Example

 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 () {
     });
 }
All Usage Examples Of Dumplie\SharedKernel\Application\Command\ExtensionRegistry::register