Skip to content

Make it possible to provide a class instance to binding transformers #2

@alexstandiford

Description

@alexstandiford

Currently, event bindings are supported using a callback.

            Ready::class => [
                ['action' => 'init', 'transformer' => function () {
                    $ready = null;

                    if (!self::$initRan) {
                        $ready = new Ready();
                        self::$initRan = true;
                    }

                    return $ready;
                }]
            ],

This tends to be overly terse, and require calls like this in cases where you want to encapsulate the logic:

        $saleTransformerCallback = fn($orderId, $orderData) => $this->container->get(
          SaleTriggeredTransformer::class
        )->getSaleTriggeredEvent($orderId, $orderData);

          SaleTriggered::class => [
            ['action' => 'action', 'transformer' => $saleTransformerCallback],
          ],

It would be much nicer if it were possible to do this, instead:

          SaleTriggered::class => [
            ['action' => 'action', 'transformer' => SaleTriggeredTransformer::class],
          ],

Would likely require that we create an EventTransformer interface, and we'd need to update the loader to support it, but once it's all set, this would really clean up and simplify event bindings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions