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.
Action allocateVariant
Section titled “Action allocateVariant”<?phpdeclare(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
Section titled “Action buildWinnerReport”<?phpdeclare(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
Section titled “Action createExperiment”<?phpdeclare(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
Section titled “Action declareExperimentWinner”<?phpdeclare(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
Section titled “Action evaluateAudienceRules”<?phpdeclare(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
Section titled “Action pruneExperimentHistory”<?phpdeclare(strict_types=1);
namespace App\CapellExamples\Experiments;
function runPruneExperimentHistory(?int $retentionDays = null): int{ return \Capell\Experiments\Actions\PruneExperimentHistoryAction::run($retentionDays);}Action recordGoalEvent
Section titled “Action recordGoalEvent”<?phpdeclare(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
Section titled “Action resolveExperimentVariantForContext”<?phpdeclare(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);}