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.

Contract Capell\Deployments\Contracts\GitProviderContract

Section titled “Contract Capell\Deployments\Contracts\GitProviderContract”
<?php
declare(strict_types=1);
namespace App\CapellExamples\Deployments;
final class GitProviderContractAdapter implements \Capell\Deployments\Contracts\GitProviderContract
{
public function __construct(private readonly \Capell\Deployments\Contracts\GitProviderContract $backend) {}
#[\Override]
public function closePullRequest(\Capell\Deployments\Models\DeploymentConnection $conn, string|int $pullRequestId): void
{
$this->backend->closePullRequest($conn, $pullRequestId);
}
#[\Override]
public function commitFiles(\Capell\Deployments\Models\DeploymentConnection $conn, string $branch, string $commitMessage, array $files): string
{
return $this->backend->commitFiles($conn, $branch, $commitMessage, $files);
}
#[\Override]
public function createBranch(\Capell\Deployments\Models\DeploymentConnection $conn, string $branchName, string $fromCommitSha): void
{
$this->backend->createBranch($conn, $branchName, $fromCommitSha);
}
#[\Override]
public function enableAutoMerge(\Capell\Deployments\Models\DeploymentConnection $conn, string|int $pullRequestId): void
{
$this->backend->enableAutoMerge($conn, $pullRequestId);
}
#[\Override]
public function findOpenPullRequestForBranch(\Capell\Deployments\Models\DeploymentConnection $conn, string $headBranch): ?\Capell\Deployments\Data\PullRequestData
{
return $this->backend->findOpenPullRequestForBranch($conn, $headBranch);
}
#[\Override]
public function getBranchCommitSha(\Capell\Deployments\Models\DeploymentConnection $conn, string $branch): string
{
return $this->backend->getBranchCommitSha($conn, $branch);
}
#[\Override]
public function getDeployStatus(\Capell\Deployments\Models\DeploymentConnection $conn, string $commitSha): string
{
return $this->backend->getDeployStatus($conn, $commitSha);
}
#[\Override]
public function getFile(\Capell\Deployments\Models\DeploymentConnection $conn, string $path): \Capell\Deployments\Data\RepoFile
{
return $this->backend->getFile($conn, $path);
}
#[\Override]
public function getPullRequest(\Capell\Deployments\Models\DeploymentConnection $conn, string|int $pullRequestId): \Capell\Deployments\Data\PullRequestData
{
return $this->backend->getPullRequest($conn, $pullRequestId);
}
#[\Override]
public function openPullRequest(\Capell\Deployments\Models\DeploymentConnection $conn, string $headBranch, string $title, string $body): \Capell\Deployments\Data\PullRequestData
{
return $this->backend->openPullRequest($conn, $headBranch, $title, $body);
}
}
function registerGitProviderContractAdapter(\Capell\Deployments\Contracts\GitProviderContract $backend): void
{
app()->bind(GitProviderContractAdapter::class, static fn (): GitProviderContractAdapter => new GitProviderContractAdapter($backend));
app()->bind(\Capell\Deployments\Contracts\GitProviderContract::class, GitProviderContractAdapter::class);
}

Contract Capell\Deployments\Contracts\PublishesComposerChanges

Section titled “Contract Capell\Deployments\Contracts\PublishesComposerChanges”
<?php
declare(strict_types=1);
namespace App\CapellExamples\Deployments;
final class PublishesComposerChangesAdapter implements \Capell\Deployments\Contracts\PublishesComposerChanges
{
public function __construct(private readonly \Capell\Deployments\Contracts\PublishesComposerChanges $backend) {}
#[\Override]
public function publish(\Capell\Deployments\Data\ComposerPublicationOperationData $operation): \Capell\Deployments\Data\PublishComposerChangeResultData
{
return $this->backend->publish($operation);
}
}
function registerPublishesComposerChangesAdapter(\Capell\Deployments\Contracts\PublishesComposerChanges $backend): void
{
app()->bind(PublishesComposerChangesAdapter::class, static fn (): PublishesComposerChangesAdapter => new PublishesComposerChangesAdapter($backend));
app()->bind(\Capell\Deployments\Contracts\PublishesComposerChanges::class, PublishesComposerChangesAdapter::class);
}