phparch icon indicating copy to clipboard operation
phparch copied to clipboard

Support wildcard dependency checks

Open marc-mabe opened this issue 3 years ago • 0 comments

Hi,

This is a feature request to be able to support dependency checks via wildcards.

Something like this:

$phpArch->validate(new ForbiddenDependency('App\\Bus\\*\\Command', 'App\\Bus\\*\\Command'));
$phpArch->validate(new ForbiddenDependency('App\\Bus\\*\\Query', 'App\\Bus\\*\\Command'));

##Background: I have a command/event/query bus implementation for business logic separated by business domain. I would like to forbid commands to trigger other commands es this should be done via events.

##Example: Wrong:

class XCommandHandler implements CommandHandler {
    public function handle(XCommand $command); void
    {
        // do whatever needs to be done

        $this->commandBus->dispatch(new OtherCommand());
    }
}

class OtherCommandHandler implements CommandHandler {
    public function handle(OtherCommand $command); void
    {
        // do whatever needs to be done
    }
}

Correct:

class XCommandHandler implements CommandHandler {
    public function handle(XCommand $command); void
    {
        // do whatever needs to be done

        $this->eventBus->dispatch(new XSucceededEvent());
    }
}

class OnXSucceededTriggerOther implements EventHandler {
    public function handle(XSucceededEvent $event); void
    {
        // do whatever needs to be done

        $this->commandBus->dispatch(new OtherCommand());
    }
}

class OtherCommandHandler implements CommandHandler {
    public function handle(OtherCommand $command); void
    {
        // do whatever needs to be done
    }
}

marc-mabe avatar May 12 '22 08:05 marc-mabe