Receber por email
← Voltar para o catálogo

symfony-hexagonal-skill

Symfony ports and adapters — port interfaces, adapter implementations, dependency injection, autowiring, repository interfaces. Triggers on: port, adapter, interface, repository interface, DI, autowiring, dependency injection, services.yaml, binding

31estrelas
Atualizado há 7 meses

Ver no GitHub ↗

Como adicionar

/plugin marketplace add aligundogdu/symfony-hexagonal-skill

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Para o autor da skill

Cole no README do seu repo

Mostra que sua skill está catalogada na Skillteca, gera backlink e tráfego rastreável.

[![Skillteca](https://www.skillteca.com.br/api/badge/symfony-hexagonal-skill-mpsy7arb/svg)](https://www.skillteca.com.br/skills/symfony-hexagonal-skill-mpsy7arb)

Skills relacionadas

Ver todas de Desenvolvimento →

Alerta por categoria

Receba novas skills de Desenvolvimento toda segunda

1 email curto, só com as skills novas de Desenvolvimento. 4 minutos de leitura, sem spam, cancela com 1 clique.

Você confirma o email no primeiro envio. Sem spam. Cancela com 1 clique.

Ler descrição completa

Symfony Ports & Adapters

You are an expert in the Ports & Adapters pattern within Symfony hexagonal architecture.

When to Activate

  • User needs to define a port (interface) for external dependency
  • User needs to implement an adapter
  • User asks about DI configuration or autowiring
  • User wants to bind an interface to a concrete implementation

Port = Interface in Domain

Ports are interfaces that define contracts for external dependencies. They live in Domain/{Module}/Port/.

Rules

  • One interface per concern (Single Responsibility)
  • Domain-centric naming (not tech-centric): UserRepositoryInterface not DoctrineUserRepository
  • Only domain types in signatures (value objects, entities, primitives)
  • No framework types in port signatures

Common Port Types

| Port Type | Example | |-----------|---------| | Repository | UserRepositoryInterface | | External Service | PaymentGatewayInterface | | Notification | NotificationServiceInterface | | File Storage | FileStorageInterface | | Event Dispatcher | EventDispatcherInterface |

Template

namespace App\Domain\{Module}\Port;

interface {Concern}Interface
{
    public function methodUsingDomainTypes(ValueObject $param): ?Entity;
}

Adapter = Implementation in Infrastructure

Adapters implement ports using specific technologies. They live in Infrastructure/{Module}/.

Rules

  • Implements exactly one port interface
  • Contains ALL technology-specific code
  • Named with technology prefix: Doctrine{Entity}Repository, Stripe{Payment}Gateway
  • final readonly class when possible

Template

namespace App\Infrastructure\{Module}\Persistence;

use App\Domain\{Module}\Port\{Repository}Interface;

final readonly class Doctrine{Entity}Repository implements {Repository}Interface
{
    public function __construct(
        private EntityManagerInterface $entityManager,
    ) {
    }

    // implement all port methods
}

DI Configuration

# config/services.yaml
services:
    # Bind ports to adapters
    App\Domain\User\Port\UserRepositoryInterface:
        alias: App\Infrastructure\User\Persistence\DoctrineUserRepository

    App\Domain\Payment\Port\PaymentGatewayInterface:
        alias: App\Infrastructure\Payment\ExternalService\StripePaymentGateway

    App\Domain\Notification\Port\NotificationServiceInterface:
        alias: App\Infrastructure\Notification\ExternalService\SymfonyMailerAdapter

References

See references/ for detailed guides:

  • port-adapter-examples.md — Full examples for various port types
  • di-configuration.md — Advanced DI configuration patterns
Compartilhar X LinkedIn