Extension and action examples
Use the action functions with records and Data objects supplied by your application. They pass each argument to the package operation and return its result.
These adapters show container registration. Use the owning package registry when a contract requires contributor discovery.
Contract adapters wrap an existing implementation. Call their registration function from your service provider with that implementation; tagged contracts keep their declared tag. Resolve the backend by its concrete class before registration so the replacement contract does not resolve itself. Static contract metadata uses one backend class per adapter.
Contract Capell\CustomerPortal\Contracts\PortalDashboardItemProvider
Section titled “Contract Capell\CustomerPortal\Contracts\PortalDashboardItemProvider”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
final class PortalDashboardItemProviderAdapter implements \Capell\CustomerPortal\Contracts\PortalDashboardItemProvider{ public function __construct(private readonly \Capell\CustomerPortal\Contracts\PortalDashboardItemProvider $backend) {}
#[\Override] public function dashboardItemsFor(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): iterable { return $this->backend->dashboardItemsFor($portalAccount); }}
function registerPortalDashboardItemProviderAdapter(\Capell\CustomerPortal\Contracts\PortalDashboardItemProvider $backend): void{ app()->bind(PortalDashboardItemProviderAdapter::class, static fn (): PortalDashboardItemProviderAdapter => new PortalDashboardItemProviderAdapter($backend)); app()->bind(\Capell\CustomerPortal\Contracts\PortalDashboardItemProvider::class, PortalDashboardItemProviderAdapter::class);}Contract Capell\CustomerPortal\Contracts\PortalPreferencesProvider
Section titled “Contract Capell\CustomerPortal\Contracts\PortalPreferencesProvider”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
final class PortalPreferencesProviderAdapter implements \Capell\CustomerPortal\Contracts\PortalPreferencesProvider{ public function __construct(private readonly \Capell\CustomerPortal\Contracts\PortalPreferencesProvider $backend) {}
#[\Override] public function preferencesFor(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): \Capell\CustomerPortal\Data\PortalPreferencesData { return $this->backend->preferencesFor($portalAccount); }}
function registerPortalPreferencesProviderAdapter(\Capell\CustomerPortal\Contracts\PortalPreferencesProvider $backend): void{ app()->bind(PortalPreferencesProviderAdapter::class, static fn (): PortalPreferencesProviderAdapter => new PortalPreferencesProviderAdapter($backend)); app()->bind(\Capell\CustomerPortal\Contracts\PortalPreferencesProvider::class, PortalPreferencesProviderAdapter::class);}Contract Capell\CustomerPortal\Contracts\PortalProfileProvider
Section titled “Contract Capell\CustomerPortal\Contracts\PortalProfileProvider”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
final class PortalProfileProviderAdapter implements \Capell\CustomerPortal\Contracts\PortalProfileProvider{ public function __construct(private readonly \Capell\CustomerPortal\Contracts\PortalProfileProvider $backend) {}
#[\Override] public function profileFor(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): \Capell\CustomerPortal\Data\PortalProfileData { return $this->backend->profileFor($portalAccount); }}
function registerPortalProfileProviderAdapter(\Capell\CustomerPortal\Contracts\PortalProfileProvider $backend): void{ app()->bind(PortalProfileProviderAdapter::class, static fn (): PortalProfileProviderAdapter => new PortalProfileProviderAdapter($backend)); app()->bind(\Capell\CustomerPortal\Contracts\PortalProfileProvider::class, PortalProfileProviderAdapter::class);}Contract Capell\CustomerPortal\Contracts\PortalSelfServiceItemProvider
Section titled “Contract Capell\CustomerPortal\Contracts\PortalSelfServiceItemProvider”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
final class PortalSelfServiceItemProviderAdapter implements \Capell\CustomerPortal\Contracts\PortalSelfServiceItemProvider{ public function __construct(private readonly \Capell\CustomerPortal\Contracts\PortalSelfServiceItemProvider $backend) {}
#[\Override] public function selfServiceItemsFor(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): iterable { return $this->backend->selfServiceItemsFor($portalAccount); }}
function registerPortalSelfServiceItemProviderAdapter(\Capell\CustomerPortal\Contracts\PortalSelfServiceItemProvider $backend): void{ app()->bind(PortalSelfServiceItemProviderAdapter::class, static fn (): PortalSelfServiceItemProviderAdapter => new PortalSelfServiceItemProviderAdapter($backend)); app()->bind(\Capell\CustomerPortal\Contracts\PortalSelfServiceItemProvider::class, PortalSelfServiceItemProviderAdapter::class);}Action addSupportRequestReply
Section titled “Action addSupportRequestReply”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runAddSupportRequestReply(\Capell\CustomerPortal\Models\PortalSupportRequest $supportRequest, string $message, string $senderType, ?\Illuminate\Database\Eloquent\Model $author = null, array $attachments = []): \Capell\CustomerPortal\Models\PortalSupportRequestReply{ return \Capell\CustomerPortal\Actions\AddSupportRequestReplyAction::run($supportRequest, $message, $senderType, $author, $attachments);}Action findOrCreatePortalAccount
Section titled “Action findOrCreatePortalAccount”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runFindOrCreatePortalAccount(\Capell\CustomerPortal\Data\PortalAccountIdentityData $identityData): \Capell\CustomerPortal\Models\PortalAccount{ return \Capell\CustomerPortal\Actions\FindOrCreatePortalAccountAction::run($identityData);}Action resolvePortalDashboardItems
Section titled “Action resolvePortalDashboardItems”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runResolvePortalDashboardItems(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): array{ return \Capell\CustomerPortal\Actions\ResolvePortalDashboardItemsAction::run($portalAccount);}Action resolvePortalPreferenceOptions
Section titled “Action resolvePortalPreferenceOptions”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runResolvePortalPreferenceOptions(): array{ return \Capell\CustomerPortal\Actions\ResolvePortalPreferenceOptionsAction::run();}Action resolvePortalProfile
Section titled “Action resolvePortalProfile”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runResolvePortalProfile(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): \Capell\CustomerPortal\Data\PortalProfileData{ return \Capell\CustomerPortal\Actions\ResolvePortalProfileAction::run($portalAccount);}Action resolvePortalSelfServiceItems
Section titled “Action resolvePortalSelfServiceItems”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runResolvePortalSelfServiceItems(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): array{ return \Capell\CustomerPortal\Actions\ResolvePortalSelfServiceItemsAction::run($portalAccount);}Action submitSupportRequest
Section titled “Action submitSupportRequest”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runSubmitSupportRequest(\Capell\CustomerPortal\Models\PortalAccount $portalAccount, \Capell\CustomerPortal\Data\SupportRequestData $supportRequestData): \Capell\CustomerPortal\Models\PortalSupportRequest{ return \Capell\CustomerPortal\Actions\SubmitSupportRequestAction::run($portalAccount, $supportRequestData);}Action updatePortalPreferences
Section titled “Action updatePortalPreferences”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runUpdatePortalPreferences(\Capell\CustomerPortal\Models\PortalAccount $portalAccount, \Capell\CustomerPortal\Data\PortalPreferencesData $preferencesData): \Capell\CustomerPortal\Models\PortalAccount{ return \Capell\CustomerPortal\Actions\UpdatePortalPreferencesAction::run($portalAccount, $preferencesData);}