Skip to content
PHP Ecosystem
Explore

ProjectContext

API reference › Scaffold › Config › ProjectContext

final readonly classPHPForge\Scaffold\Config\ProjectContext
Sourcesrc/Config/ProjectContext.php

Represents the project that the scaffold commands inspect: its root, vendor directory, configuration and installed packages.

PropertyTypeDescriptionDefined by
$config readonly constructorProjectConfigConsumer settings from the project composer.json.ProjectContext
$installed readonly constructorInstalledPackagesPackages installed in the project.ProjectContext
$projectRoot readonly constructorstringAbsolute path to the project root.ProjectContext
$vendorDir readonly constructorstringAbsolute path to the Composer vendor directory.ProjectContext
MethodDescriptionDefined by
__construct()Creates a project context from its resolved filesystem and Composer metadata.ProjectContext
create() staticCreates the context of the project rooted at $projectRoot from its composer.json and installed packages.ProjectContext
isInstalled()Returns whether the provider is installed: from the installed packages when known, otherwise from the existence of its resolved root directory.ProjectContext
providerRoot()Resolves the root of a provider from its Composer install path, then its lock-recorded path inside the vendor directory, then <vendorDir>/<providerName>.ProjectContext
providers()Returns the allowed providers that are installed, as descriptors whose extra the scaffold core reads from their composer.json.ProjectContext
public function __construct(string $projectRoot, string $vendorDir, PHPForge\Scaffold\Config\ProjectConfig $config, PHPForge\Scaffold\Config\InstalledPackages $installed)

Creates a project context from its resolved filesystem and Composer metadata.

Parameters

ParameterTypeDescription
$projectRootstringAbsolute path to the project root.
$vendorDirstringAbsolute path to the Composer vendor directory.
$configProjectConfigConsumer settings from the project composer.json.
$installedInstalledPackagesPackages installed in the project.
public static function create(string $projectRoot): self

Creates the context of the project rooted at $projectRoot from its composer.json and installed packages.

Parameters

ParameterTypeDescription
$projectRootstringAbsolute path to the project root.

Returns

self: Project context with the configuration and installed packages of the project.

Throws

public function isInstalled(string $providerName, mixed $providerLock = null): bool

Returns whether the provider is installed: from the installed packages when known, otherwise from the existence of its resolved root directory.

Parameters

ParameterTypeDescription
$providerNamestringProvider package name.
$providerLockmixedDecoded providers.<name> entry of scaffold-lock.json, or null when absent.

Returns

bool: true when the provider is installed in the project, false otherwise.

public function providerRoot(string $providerName, mixed $providerLock = null): array{root: string, warning: string|null}

Resolves the root of a provider from its Composer install path, then its lock-recorded path inside the vendor directory, then <vendorDir>/<providerName>.

Parameters

ParameterTypeDescription
$providerNamestringProvider package name.
$providerLockmixedDecoded providers.<name> entry of scaffold-lock.json, or null when absent.

Returns

array{root: string, warning: string|null}: Provider root, and a warning when the lock-recorded path resolves outside the vendor directory.

public function providers(array<string, mixed> $lockProviders): array{providers: array<string, PHPForge\Scaffold\Config\ProviderPackage>, warnings: array<string, string>}

Returns the allowed providers that are installed, as descriptors whose extra the scaffold core reads from their composer.json.

Parameters

ParameterTypeDescription
$lockProvidersarray<string, mixed>providers map of scaffold-lock.json, used for recorded paths and, when the installed packages are unknown, recorded versions.

Returns

array{providers: array<string, ProviderPackage>, warnings: array<string, string>}: Providers keyed by name in allowed-packages order, and warnings about provider roots keyed by provider name.