# 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\Comments\Contracts\CommentSpamProvider`

<!-- example: contract Capell\Comments\Contracts\CommentSpamProvider -->

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

namespace App\CapellExamples\Comments;

final class CommentSpamProviderAdapter implements \Capell\Comments\Contracts\CommentSpamProvider
{
    public function __construct(private readonly \Capell\Comments\Contracts\CommentSpamProvider $backend) {}

    #[\Override]
    public function score(\Capell\Comments\Data\CommentSpamCheckData $check): \Capell\Comments\Data\CommentSpamScoreData
    {
        return $this->backend->score($check);
    }
}

function registerCommentSpamProviderAdapter(\Capell\Comments\Contracts\CommentSpamProvider $backend): void
{
    app()->bind(CommentSpamProviderAdapter::class, static fn (): CommentSpamProviderAdapter => new CommentSpamProviderAdapter($backend));
    app()->bind(\Capell\Comments\Contracts\CommentSpamProvider::class, CommentSpamProviderAdapter::class);
}
```

## Action `applyPrivacyRetention`

<!-- example: action applyPrivacyRetention -->

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

namespace App\CapellExamples\Comments;

function runApplyPrivacyRetention(?int $retentionDays = null, ?string $email = null, ?int $siteId = null, bool $dryRun = false): \Capell\Comments\Data\CommentPrivacyRetentionResultData
{
    return \Capell\Comments\Actions\ApplyCommentPrivacyRetentionAction::run($retentionDays, $email, $siteId, $dryRun);
}
```

## Action `disableReplyNotifications`

<!-- example: action disableReplyNotifications -->

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

namespace App\CapellExamples\Comments;

function runDisableReplyNotifications(string $token): ?\Capell\Comments\Models\CommentAuthor
{
    return \Capell\Comments\Actions\DisableCommentAuthorReplyNotificationsAction::run($token);
}
```

## Action `install`

<!-- example: action install -->

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

namespace App\CapellExamples\Comments;

function runInstall(\Capell\Core\Data\PackageData $package, array $arguments = [], ?\Capell\Core\Contracts\ProgressReporter $reporter = null): void
{
    \Capell\Comments\Actions\InstallCommentsPackageAction::run($package, $arguments, $reporter);
}
```

## Action `requestReplyNotification`

<!-- example: action requestReplyNotification -->

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

namespace App\CapellExamples\Comments;

function runRequestReplyNotification(\Capell\Comments\Models\Comment $reply): ?\Capell\Comments\Models\CommentToken
{
    return \Capell\Comments\Actions\RequestCommentReplyNotificationAction::run($reply);
}
```

## Action `scoreSpam`

<!-- example: action scoreSpam -->

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

namespace App\CapellExamples\Comments;

function runScoreSpam(string $body, int $linkCount, ?\Capell\Comments\Data\CommentSpamCheckData $check = null): \Capell\Comments\Data\CommentSpamScoreData
{
    return \Capell\Comments\Actions\ScoreCommentSpamAction::run($body, $linkCount, $check);
}
```

## Action `toggleReaction`

<!-- example: action toggleReaction -->

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

namespace App\CapellExamples\Comments;

function runToggleReaction(\Illuminate\Database\Eloquent\Model $commentable, string $commentPublicId, ?\Illuminate\Database\Eloquent\Model $user = null, ?string $ipAddress = null, ?string $userAgent = null, \Capell\Comments\Enums\CommentReactionType $type = \Capell\Comments\Enums\CommentReactionType::Like): \Capell\Comments\Data\CommentReactionResultData
{
    return \Capell\Comments\Actions\ToggleCommentReactionAction::run($commentable, $commentPublicId, $user, $ipAddress, $userAgent, $type);
}
```