Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework agnostic business logic #51

Open
michalmytych opened this issue Oct 7, 2023 · 0 comments
Open

Framework agnostic business logic #51

michalmytych opened this issue Oct 7, 2023 · 0 comments
Labels
architecture enhancement New feature or request

Comments

@michalmytych
Copy link
Owner

michalmytych commented Oct 7, 2023

  • Separate all Laravel elements with adapter Interfaces: eg: LoggerInterface -> Log Laravel facade. Bind interfaces and concretes in AppServiceProvider.
  • Separate ORM from business logic -> Repository pattern (inject Eloquent model in concrete). In repositories map all models to domain entities, ore just use Laravel models as plain PHP object: $model->property, $model->relation (Collection).
  • Introduce own Collection (maybe implementing specific contract). Or use Laravel collection as library-like code.
  • Integrations related code move to separate modules and call through adapter interfaces.
  • Bind Laravel Events to some strings an resolve events in business logic like this:
/* @var EventDispatcherInterface $eventDispatcher Event dispatcher adapter **/
$eventDispatcher->dispatch('transaction_added', $transaction->id);

$eventsBindings = [
     'transaction_added' => [
          \App\Events\TransactionAdded::class,  [ 'transactionId' ]
     ]
];
@michalmytych michalmytych added enhancement New feature or request architecture labels Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant