# 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.

## Action `allocateVariant`

<!-- example: action allocateVariant -->

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

namespace App\CapellExamples\Experiments;

function runAllocateVariant(\Capell\Experiments\Models\Experiment $experiment, string $allocationKey, ?\Capell\Experiments\Data\ExperimentContextData $context = null): ?\Capell\Experiments\Data\VariantAllocationData
{
    return \Capell\Experiments\Actions\AllocateVariantAction::run($experiment, $allocationKey, $context);
}
```

## Action `buildWinnerReport`

<!-- example: action buildWinnerReport -->

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

namespace App\CapellExamples\Experiments;

function runBuildWinnerReport(\Capell\Experiments\Models\Experiment $experiment, ?\Capell\Experiments\Models\ExperimentGoal $goal = null, int $minimumSampleSize = 100, float $confidenceLevel = 0.95): \Capell\Experiments\Data\WinnerReportData
{
    return \Capell\Experiments\Actions\BuildWinnerReportAction::run($experiment, $goal, $minimumSampleSize, $confidenceLevel);
}
```

## Action `createExperiment`

<!-- example: action createExperiment -->

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

namespace App\CapellExamples\Experiments;

function runCreateExperiment(\Capell\Experiments\Data\ExperimentData $data): \Capell\Experiments\Models\Experiment
{
    return \Capell\Experiments\Actions\CreateExperimentAction::run($data);
}
```

## Action `declareExperimentWinner`

<!-- example: action declareExperimentWinner -->

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

namespace App\CapellExamples\Experiments;

function runDeclareExperimentWinner(\Capell\Experiments\Models\Experiment $experiment, ?\Capell\Experiments\Models\ExperimentGoal $goal = null, ?\Carbon\CarbonInterface $declaredAt = null, bool $endExperiment = true): \Capell\Experiments\Models\Experiment
{
    return \Capell\Experiments\Actions\DeclareExperimentWinnerAction::run($experiment, $goal, $declaredAt, $endExperiment);
}
```

## Action `evaluateAudienceRules`

<!-- example: action evaluateAudienceRules -->

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

namespace App\CapellExamples\Experiments;

function runEvaluateAudienceRules(\Capell\Experiments\Models\Experiment $experiment, \Capell\Experiments\Data\ExperimentContextData $context): bool
{
    return \Capell\Experiments\Actions\EvaluateAudienceRulesAction::run($experiment, $context);
}
```

## Action `pruneExperimentHistory`

<!-- example: action pruneExperimentHistory -->

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

namespace App\CapellExamples\Experiments;

function runPruneExperimentHistory(?int $retentionDays = null): int
{
    return \Capell\Experiments\Actions\PruneExperimentHistoryAction::run($retentionDays);
}
```

## Action `recordGoalEvent`

<!-- example: action recordGoalEvent -->

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

namespace App\CapellExamples\Experiments;

function runRecordGoalEvent(\Capell\Experiments\Models\ExperimentAllocation $allocation, \Capell\Experiments\Models\ExperimentGoal $goal, \Capell\Experiments\Data\ExperimentGoalEventData $data): \Capell\Experiments\Models\ExperimentGoalEvent
{
    return \Capell\Experiments\Actions\RecordGoalEventAction::run($allocation, $goal, $data);
}
```

## Action `resolveExperimentVariantForContext`

<!-- example: action resolveExperimentVariantForContext -->

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

namespace App\CapellExamples\Experiments;

function runResolveExperimentVariantForContext(string $allocationKey, ?\Capell\Experiments\Data\ExperimentContextData $context = null): ?\Capell\Experiments\Data\ResolvedExperimentVariantData
{
    return \Capell\Experiments\Actions\ResolveExperimentVariantForContextAction::run($allocationKey, $context);
}
```