# Extension and action examples

<!-- Maintained by scripts/generate-package-readmes.php -->

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\SocialFeeds\Contracts\SocialFeedHostResolver`

<!-- example: contract Capell\SocialFeeds\Contracts\SocialFeedHostResolver -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\SocialFeeds;

final class SocialFeedHostResolverAdapter implements \Capell\SocialFeeds\Contracts\SocialFeedHostResolver
{
    public function __construct(private readonly \Capell\SocialFeeds\Contracts\SocialFeedHostResolver $backend) {}

    #[\Override]
    public function resolve(string $host): array
    {
        return $this->backend->resolve($host);
    }
}

function registerSocialFeedHostResolverAdapter(\Capell\SocialFeeds\Contracts\SocialFeedHostResolver $backend): void
{
    app()->bind(SocialFeedHostResolverAdapter::class, static fn (): SocialFeedHostResolverAdapter => new SocialFeedHostResolverAdapter($backend));
    app()->bind(\Capell\SocialFeeds\Contracts\SocialFeedHostResolver::class, SocialFeedHostResolverAdapter::class);
}
```

## Contract `Capell\SocialFeeds\Contracts\SocialFeedProvider`

<!-- example: contract Capell\SocialFeeds\Contracts\SocialFeedProvider -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\SocialFeeds;

final class SocialFeedProviderAdapter implements \Capell\SocialFeeds\Contracts\SocialFeedProvider
{
    public function __construct(private readonly \Capell\SocialFeeds\Contracts\SocialFeedProvider $backend) {}

    #[\Override]
    public function authStrategy(): \Capell\SocialFeeds\Enums\SocialAuthStrategy
    {
        return $this->backend->authStrategy();
    }

    #[\Override]
    public function credentialSchema(): array
    {
        return $this->backend->credentialSchema();
    }

    #[\Override]
    public function fetch(\Capell\SocialFeeds\Models\SocialFeedConnection $connection, int $limit): array
    {
        return $this->backend->fetch($connection, $limit);
    }

    #[\Override]
    public function key(): string
    {
        return $this->backend->key();
    }

    #[\Override]
    public function label(): string
    {
        return $this->backend->label();
    }
}

function registerSocialFeedProviderAdapter(\Capell\SocialFeeds\Contracts\SocialFeedProvider $backend): void
{
    app()->bind(SocialFeedProviderAdapter::class, static fn (): SocialFeedProviderAdapter => new SocialFeedProviderAdapter($backend));
    app()->bind(\Capell\SocialFeeds\Contracts\SocialFeedProvider::class, SocialFeedProviderAdapter::class);
}
```

## Contract `Capell\SocialFeeds\Contracts\SocialFeedProviderProvider`

<!-- example: contract Capell\SocialFeeds\Contracts\SocialFeedProviderProvider -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\SocialFeeds;

final class SocialFeedProviderProviderAdapter implements \Capell\SocialFeeds\Contracts\SocialFeedProviderProvider
{
    public function __construct(private readonly \Capell\SocialFeeds\Contracts\SocialFeedProviderProvider $backend) {}

    #[\Override]
    public function registerProviders(\Capell\SocialFeeds\Support\SocialFeedProviderRegistry $registry): void
    {
        $this->backend->registerProviders($registry);
    }
}

function registerSocialFeedProviderProviderAdapter(\Capell\SocialFeeds\Contracts\SocialFeedProviderProvider $backend): void
{
    app()->bind(SocialFeedProviderProviderAdapter::class, static fn (): SocialFeedProviderProviderAdapter => new SocialFeedProviderProviderAdapter($backend));
    app()->bind(\Capell\SocialFeeds\Contracts\SocialFeedProviderProvider::class, SocialFeedProviderProviderAdapter::class);
    app()->tag([SocialFeedProviderProviderAdapter::class], \Capell\SocialFeeds\Contracts\SocialFeedProviderProvider::TAG);
}
```

## Action `fetchRenderData`

<!-- example: action fetchRenderData -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\SocialFeeds;

function runFetchRenderData(\Capell\SocialFeeds\Data\SocialFeedWidgetConfigData $config): \Capell\SocialFeeds\Data\SocialFeedRenderData
{
    return \Capell\SocialFeeds\Actions\FetchSocialFeedRenderDataAction::run($config);
}
```

## Action `syncConnection`

<!-- example: action syncConnection -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\SocialFeeds;

function runSyncConnection(\Capell\SocialFeeds\Models\SocialFeedConnection|int $connection, ?int $limit = null): int
{
    return \Capell\SocialFeeds\Actions\SyncSocialFeedConnectionAction::run($connection, $limit);
}
```

## Action `upsertItems`

<!-- example: action upsertItems -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\SocialFeeds;

function runUpsertItems(\Capell\SocialFeeds\Models\SocialFeedConnection $connection, array $posts): int
{
    return \Capell\SocialFeeds\Actions\UpsertSocialFeedItemsAction::run($connection, $posts);
}
```