ProjectContext
API reference › Scaffold › Config › ProjectContext
Represents the project that the scaffold commands inspect: its root, vendor directory, configuration and installed packages.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$config readonly constructor | ProjectConfig | Consumer settings from the project composer.json. | ProjectContext |
$installed readonly constructor | InstalledPackages | Packages installed in the project. | ProjectContext |
$projectRoot readonly constructor | string | Absolute path to the project root. | ProjectContext |
$vendorDir readonly constructor | string | Absolute path to the Composer vendor directory. | ProjectContext |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a project context from its resolved filesystem and Composer metadata. | ProjectContext |
create() static | Creates 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 |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”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
| Parameter | Type | Description |
|---|---|---|
$projectRoot | string | Absolute path to the project root. |
$vendorDir | string | Absolute path to the Composer vendor directory. |
$config | ProjectConfig | Consumer settings from the project composer.json. |
$installed | InstalledPackages | Packages installed in the project. |
create()
Section titled “create() ”public static function create(string $projectRoot): selfCreates the context of the project rooted at $projectRoot from its composer.json and installed packages.
Parameters
| Parameter | Type | Description |
|---|---|---|
$projectRoot | string | Absolute path to the project root. |
Returns
self: Project context with the configuration and installed packages of the project.
Throws
RuntimeException: when the projectcomposer.jsonis missing or invalid.
isInstalled()
Section titled “isInstalled() ”public function isInstalled(string $providerName, mixed $providerLock = null): boolReturns whether the provider is installed: from the installed packages when known, otherwise from the existence of its resolved root directory.
Parameters
| Parameter | Type | Description |
|---|---|---|
$providerName | string | Provider package name. |
$providerLock | mixed | Decoded providers.<name> entry of scaffold-lock.json, or null when absent. |
Returns
bool: true when the provider is installed in the project, false otherwise.
providerRoot()
Section titled “providerRoot() ”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
| Parameter | Type | Description |
|---|---|---|
$providerName | string | Provider package name. |
$providerLock | mixed | Decoded 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.
providers()
Section titled “providers() ”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
| Parameter | Type | Description |
|---|---|---|
$lockProviders | array<string, | 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.