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.

<?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);
}
<?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);
}
<?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);
}
<?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);
}
<?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);
}
<?php
declare(strict_types=1);
namespace App\CapellExamples\Experiments;
function runPruneExperimentHistory(?int $retentionDays = null): int
{
return \Capell\Experiments\Actions\PruneExperimentHistoryAction::run($retentionDays);
}
<?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);
}
<?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);
}