|
| 1 | + |
| 2 | +Provides a base configuration and common utilities for Composer commands. |
| 3 | + |
| 4 | +Extending classes MUST rely on this base abstraction to interact with the console |
| 5 | +application gracefully, and SHALL adhere to the expected return types for commands. |
| 6 | + |
| 7 | +*** |
| 8 | + |
| 9 | +* Full name: `\FastForward\DevTools\Command\AbstractCommand` |
| 10 | +* Parent class: [`BaseCommand`](../../../Composer/Command/BaseCommand) |
| 11 | +* This class is an **Abstract class** |
| 12 | + |
| 13 | +## Properties |
| 14 | + |
| 15 | +### filesystem |
| 16 | + |
| 17 | +```php |
| 18 | +protected \Symfony\Component\Filesystem\Filesystem $filesystem |
| 19 | +``` |
| 20 | + |
| 21 | +*** |
| 22 | + |
| 23 | +## Methods |
| 24 | + |
| 25 | +### __construct |
| 26 | + |
| 27 | +Constructs a new AbstractCommand instance. |
| 28 | + |
| 29 | +```php |
| 30 | +public __construct(\Symfony\Component\Filesystem\Filesystem|null $filesystem = null): mixed |
| 31 | +``` |
| 32 | + |
| 33 | +The method MAY accept a Filesystem instance; if omitted, it SHALL instantiate a new one. |
| 34 | + |
| 35 | +**Parameters:** |
| 36 | + |
| 37 | +| Parameter | Type | Description | |
| 38 | +|---------------|----------------------------------------------------|-------------------------------| |
| 39 | +| `$filesystem` | **\Symfony\Component\Filesystem\Filesystem\|null** | the filesystem utility to use | |
| 40 | + |
| 41 | +*** |
| 42 | + |
| 43 | +### runProcess |
| 44 | + |
| 45 | +Executes a given system process gracefully and outputs its buffer. |
| 46 | + |
| 47 | +```php |
| 48 | +protected runProcess(\Symfony\Component\Process\Process $command, \Symfony\Component\Console\Output\OutputInterface $output): int |
| 49 | +``` |
| 50 | + |
| 51 | +The method MUST execute the provided command ensuring the output is channeled |
| 52 | +to the OutputInterface. It SHOULD leverage TTY if supported. If the process |
| 53 | +fails, it MUST return `self::FAILURE`; otherwise, it SHALL return `self::SUCCESS`. |
| 54 | + |
| 55 | +**Parameters:** |
| 56 | + |
| 57 | +| Parameter | Type | Description | |
| 58 | +|------------|-------------------------------------------------------|-------------------------------------------------| |
| 59 | +| `$command` | **\Symfony\Component\Process\Process** | the configured process instance to run | |
| 60 | +| `$output` | **\Symfony\Component\Console\Output\OutputInterface** | the output interface to log warnings or results | |
| 61 | + |
| 62 | +**Return Value:** |
| 63 | + |
| 64 | +the status code of the command execution |
| 65 | + |
| 66 | +*** |
| 67 | + |
| 68 | +### getCurrentWorkingDirectory |
| 69 | + |
| 70 | +Retrieves the current working directory of the application. |
| 71 | + |
| 72 | +```php |
| 73 | +protected getCurrentWorkingDirectory(): string |
| 74 | +``` |
| 75 | + |
| 76 | +The method MUST return the initial working directory defined by the application. |
| 77 | +If not available, it SHALL fall back to the safe current working directory. |
| 78 | + |
| 79 | +**Return Value:** |
| 80 | + |
| 81 | +the absolute path to the current working directory |
| 82 | + |
| 83 | +*** |
| 84 | + |
| 85 | +### getAbsolutePath |
| 86 | + |
| 87 | +Computes the absolute path for a given relative or absolute path. |
| 88 | + |
| 89 | +```php |
| 90 | +protected getAbsolutePath(string $relativePath): string |
| 91 | +``` |
| 92 | + |
| 93 | +This method MUST return the exact path if it is already absolute. |
| 94 | +If relative, it SHALL make it absolute relying on the current working directory. |
| 95 | + |
| 96 | +**Parameters:** |
| 97 | + |
| 98 | +| Parameter | Type | Description | |
| 99 | +|-----------------|------------|---------------------------------| |
| 100 | +| `$relativePath` | **string** | the path to evaluate or resolve | |
| 101 | + |
| 102 | +**Return Value:** |
| 103 | + |
| 104 | +the resolved absolute path |
| 105 | + |
| 106 | +*** |
| 107 | + |
| 108 | +### getConfigFile |
| 109 | + |
| 110 | +Determines the correct absolute path to a configuration file. |
| 111 | + |
| 112 | +```php |
| 113 | +protected getConfigFile(string $filename, bool $force = false): string |
| 114 | +``` |
| 115 | + |
| 116 | +The method MUST attempt to resolve the configuration file locally in the working directory. |
| 117 | +If absent and not forced, it SHALL provide the default equivalent from the package itself. |
| 118 | + |
| 119 | +**Parameters:** |
| 120 | + |
| 121 | +| Parameter | Type | Description | |
| 122 | +|-------------|------------|---------------------------------------------------------------------------------| |
| 123 | +| `$filename` | **string** | the name of the configuration file | |
| 124 | +| `$force` | **bool** | determines whether to bypass fallback and forcefully return the local file path | |
| 125 | + |
| 126 | +**Return Value:** |
| 127 | + |
| 128 | +the resolved absolute path to the configuration file |
| 129 | + |
| 130 | +*** |
| 131 | + |
| 132 | +### runCommand |
| 133 | + |
| 134 | +Configures and executes a registered console command by name. |
| 135 | + |
| 136 | +```php |
| 137 | +protected runCommand(string $commandName, array|\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output): int |
| 138 | +``` |
| 139 | + |
| 140 | +The method MUST look up the command from the application and run it. It SHALL ignore generic |
| 141 | +validation errors and route the custom input and output correctly. |
| 142 | + |
| 143 | +**Parameters:** |
| 144 | + |
| 145 | +| Parameter | Type | Description | |
| 146 | +|----------------|------------------------------------------------------------|-----------------------------------------| |
| 147 | +| `$commandName` | **string** | the name of the required command | |
| 148 | +| `$input` | **array\|\Symfony\Component\Console\Input\InputInterface** | the input arguments or array definition | |
| 149 | +| `$output` | **\Symfony\Component\Console\Output\OutputInterface** | the interface for buffering output | |
| 150 | + |
| 151 | +**Return Value:** |
| 152 | + |
| 153 | +the status code resulting from the dispatched command |
| 154 | + |
| 155 | +*** |
| 156 | + |
| 157 | +### getPsr4Namespaces |
| 158 | + |
| 159 | +Retrieves configured PSR-4 namespaces from the composer configuration. |
| 160 | + |
| 161 | +```php |
| 162 | +protected getPsr4Namespaces(): array |
| 163 | +``` |
| 164 | + |
| 165 | +This method SHALL parse the underlying `composer.json` using the Composer instance, |
| 166 | +and MUST provide an empty array if no specific paths exist. |
| 167 | + |
| 168 | +**Return Value:** |
| 169 | + |
| 170 | +the PSR-4 namespaces mappings |
| 171 | + |
| 172 | +*** |
| 173 | + |
| 174 | +### getTitle |
| 175 | + |
| 176 | +Computes the human-readable title or description of the current application. |
| 177 | + |
| 178 | +```php |
| 179 | +protected getTitle(): string |
| 180 | +``` |
| 181 | + |
| 182 | +The method SHOULD utilize the package description as the title, but MUST provide |
| 183 | +the raw package name as a fallback mechanism. |
| 184 | + |
| 185 | +**Return Value:** |
| 186 | + |
| 187 | +the computed title or description string |
| 188 | + |
| 189 | +*** |
0 commit comments