# AbstractScaffoldCommand

> Runs a scaffold console command: validates its input, resolves the project root and reports a RuntimeException of the command body as a [scaffold] error.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Console](/docs/extensions/scaffold/reference/console/index.md) › [Command](/docs/extensions/scaffold/reference/console/command/index.md) › AbstractScaffoldCommand

| abstract class | `PHPForge\Scaffold\Console\Command\AbstractScaffoldCommand` |
| --- | --- |
| Extends | `Symfony\Component\Console\Command\Command` |
| Source | [`src/Console/Command/AbstractScaffoldCommand.php`](https://github.com/php-forge/scaffold/blob/main/src/Console/Command/AbstractScaffoldCommand.php#L23) |

7 subclasses:

- [`DiffCommand`](/docs/extensions/scaffold/reference/console/command/diffcommand/index.md)
- [`EjectCommand`](/docs/extensions/scaffold/reference/console/command/ejectcommand/index.md)
- [`ProvidersCommand`](/docs/extensions/scaffold/reference/console/command/providerscommand/index.md)
- [`PruneCommand`](/docs/extensions/scaffold/reference/console/command/prunecommand/index.md)
- [`ReapplyCommand`](/docs/extensions/scaffold/reference/console/command/reapplycommand/index.md)
- [`StatusCommand`](/docs/extensions/scaffold/reference/console/command/statuscommand/index.md)
- [`SyncCommand`](/docs/extensions/scaffold/reference/console/command/synccommand/index.md)

Runs a scaffold console command: validates its input, resolves the project root and reports a
[`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php) of the command body as a `[scaffold]` error.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`execute()`](#method-execute) protected final | Validates the input, resolves the project root and runs [`AbstractScaffoldCommand::handle()`](/docs/extensions/scaffold/reference/console/command/abstractscaffoldcommand/index.md#method-handle). | `AbstractScaffoldCommand` |
| [`handle()`](#method-handle) protected abstract | Runs the command body against the project root and returns its exit code. | `AbstractScaffoldCommand` |
| [`validate()`](#method-validate) protected | Returns whether the input is valid, writing the error to the error output when it is not. | `AbstractScaffoldCommand` |

## Method details

### execute() <span id="method-execute"></span>

```php
final protected function execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output): int
```

Validates the input, resolves the project root and runs [`AbstractScaffoldCommand::handle()`](/docs/extensions/scaffold/reference/console/command/abstractscaffoldcommand/index.md#method-handle).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$input` | `Symfony\Component\Console\Input\InputInterface` | Command input that may carry the global `--working-dir` option. |
| `$output` | `Symfony\Component\Console\Output\OutputInterface` | Console output that receives the command output and the error messages. |

**Returns**

`int`: Exit code of [`AbstractScaffoldCommand::handle()`](/docs/extensions/scaffold/reference/console/command/abstractscaffoldcommand/index.md#method-handle); `1` when the project root is not found or a runtime error is reported; `2` when the input is invalid.

### handle() <span id="method-handle"></span>

```php
abstract protected function handle(Symfony\Component\Console\Input\InputInterface $input, PHPForge\Scaffold\Console\SymfonyOutputWriter $out, string $projectRoot): int
```

Runs the command body against the project root and returns its exit code.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$input` | `Symfony\Component\Console\Input\InputInterface` | Command input. |
| `$out` | [`PHPForge\Scaffold\Console\SymfonyOutputWriter`](/docs/extensions/scaffold/reference/console/symfonyoutputwriter/index.md) | Output sink of the command. |
| `$projectRoot` | `string` | Absolute path of the directory containing the project `composer.json`. |

**Returns**

`int`: Exit code of the command.

**Throws**

- [`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php): when the lock file or the project manifest cannot be read or written.

### validate() <span id="method-validate"></span>

```php
protected function validate(Symfony\Component\Console\Input\InputInterface $input, PHPForge\Scaffold\Console\SymfonyOutputWriter $out): bool
```

Returns whether the input is valid, writing the error to the error output when it is not.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$input` | `Symfony\Component\Console\Input\InputInterface` | Command input. |
| `$out` | [`PHPForge\Scaffold\Console\SymfonyOutputWriter`](/docs/extensions/scaffold/reference/console/symfonyoutputwriter/index.md) | Output sink that receives the error message. |

**Returns**

`bool`: `true` when the command may run, `false` otherwise.