PHPackages                             vjik/scaffolder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vjik/scaffolder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vjik/scaffolder
===============

PHP Scaffolder Library

0.1(4mo ago)5114[1 issues](https://github.com/vjik/scaffolder/issues)BSD-3-ClausePHPPHP ~8.4.0

Since Jan 4Pushed 4mo agoCompare

[ Source](https://github.com/vjik/scaffolder)[ Packagist](https://packagist.org/packages/vjik/scaffolder)[ RSS](/packages/vjik-scaffolder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

PHP Scaffolder Library
======================

[](#php-scaffolder-library)

[![Latest Stable Version](https://camo.githubusercontent.com/b0f049cad3eced4d94ad4f95b279335e6b63638386f1750f4c968f8ed06ab0ec/68747470733a2f2f706f7365722e707567782e6f72672f766a696b2f73636166666f6c6465722f76)](https://packagist.org/packages/vjik/scaffolder)[![Total Downloads](https://camo.githubusercontent.com/dd197b607ccddb5d125f9c258e1525b5a0d95bc63a3ab2a1a5351de9bcbcf6a8/68747470733a2f2f706f7365722e707567782e6f72672f766a696b2f73636166666f6c6465722f646f776e6c6f616473)](https://packagist.org/packages/vjik/scaffolder)

A PHP library for making automated changes to project files through a decision-based architecture.

Real-world examples of a scaffolder tool built using this library:

- [PHPTG Scaffolder](https://github.com/phptg/scaffolder)

General Usage
-------------

[](#general-usage)

Note

A ready-made scaffolder tool built on top of this library is available at [vjik/scaffolder-template](https://github.com/vjik/scaffolder-template). This template provides a complete scaffolder framework that you can clone and customize for your projects.

The scaffolder allows you to automate project file modifications through a declarative approach. Create a PHP script that defines the changes you want to apply:

```
use Vjik\Scaffolder\Change;
use Vjik\Scaffolder\Runner;

require_once __DIR__ . '/vendor/autoload.php';

new Runner(
    changes: [
        new Change\WriteFile('README.md', 'Hello World'),
        new Change\PrepareComposerJson(),
        new Change\CopyFile(
            from: __DIR__ . '/templates/LICENSE',
            to: 'LICENSE',
        ),
    ],
)->run();
```

Run your script:

```
php my-scaffolder.php
```

The scaffolder will execute each change in sequence, showing progress:

```
Write `README.md`... Done.
Write `composer.json`... Done.
Normalize `composer.json`... Done.
Copy LICENSE... Done.

Success! 4 changes applied.

```

Architecture
------------

[](#architecture)

### Changes

[](#changes)

Changes implement the `Change` interface and define what modifications to apply. Each change:

- Implements a `decide(Context $context): callable|array|null` method
- Returns an "applier" callable to execute, or `null` for no-op
- Can inspect the current state and decide whether to apply

**Built-in Changes:**

- `WriteFile` - Write content to a file
- `WriteFileIfNotExists` - Write file only if it doesn't exist
- `CopyFile` - Copy a file
- `CopyFileIfNotExists` - Copy file only if it doesn't exist
- `PrepareComposerJson` - Update composer.json with package information
- `EnsureDirectoryWithGitkeep` - Ensure directory exists with .gitkeep
- `EnsureFact` - Ensure a fact is resolved (useful for prompting user input)
- `ChangeIf` - Conditionally apply changes based on a condition

### Facts

[](#facts)

Facts are template classes that resolve contextual information on-demand. They can:

- Read from files (e.g., existing `composer.json`)
- Prompt the user for input
- Derive values from other facts
- Add CLI options

**Example:**

```
use Vjik\Scaffolder\Context;

$context->getFact(PackageName::class); // Returns "vendor/package"
$context->getFact(NamespaceX::class);  // Returns "Vendor\\Package"
```

Facts are lazily resolved and cached, so expensive operations only happen when needed.

**Built-in Facts:**

- `ComposerJson` - Read and parse existing composer.json
- `PackageName` - Package name (e.g., "vendor/package")
- `PackageVendor` - Vendor name from package name
- `PackageProject` - Project name from package name
- `PackageDescription` - Package description
- `PackageLicense` - Package license
- `PackageType` - Package type (library, project, etc.)
- `PackageAuthors` - Array of package authors
- `NamespaceX` - Root namespace (e.g., "Vendor\\Package")
- `SourceDirectory` - Source code directory (default: "src")
- `TestsDirectory` - Tests directory (default: "tests")
- `PhpConstraint` - PHP version constraint
- `PhpConstraintName` - PHP constraint name (default: "php")
- `LowestMinorPhpVersion` - Lowest minor PHP version
- `HighestMinorPhpVersion` - Highest minor PHP version
- `MinorPhpVersionRange` - PHP version range
- `PrepareComposerAutoload` - Whether to prepare autoload section
- `PrepareComposerAutoloadDev` - Whether to prepare autoload-dev section
- `CopyrightHolder` - Copyright holder name
- `CopyrightYear` - Copyright year
- `Title` - Project title
- `UserName` - User/author name
- `UserEmail` - User/author email

### Parameters

[](#parameters)

The scaffolder supports a flexible parameter system that allows configuration through multiple sources with a clear priority order:

1. Command line options - facts can add their own CLI options
2. `scaffolder.php` file - project-specific configuration
3. Runner constructor - default values

**Setting parameters via scaffolder.php file:**

Create a `scaffolder.php` file in your project directory:

```
