Skip to content

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”
<?php
declare(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”
<?php
declare(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”
<?php
declare(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”
<?php
declare(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);
}
<?php
declare(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);
}
<?php
declare(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);
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runResolvePortalDashboardItems(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): array
{
return \Capell\CustomerPortal\Actions\ResolvePortalDashboardItemsAction::run($portalAccount);
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runResolvePortalPreferenceOptions(): array
{
return \Capell\CustomerPortal\Actions\ResolvePortalPreferenceOptionsAction::run();
}
<?php
declare(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);
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\CustomerPortal;
function runResolvePortalSelfServiceItems(\Capell\CustomerPortal\Models\PortalAccount $portalAccount): array
{
return \Capell\CustomerPortal\Actions\ResolvePortalSelfServiceItemsAction::run($portalAccount);
}
<?php
declare(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);
}
<?php
declare(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);
}