vjik / scaffolder
PHP Scaffolder Library
Installs: 72
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/vjik/scaffolder
Requires
- php: ~8.4.0
- ext-filter: *
- composer/semver: ^3.4.4
- symfony/console: ^8.0.3
- symfony/filesystem: ^8.0.1
- yiisoft/strings: ^2.7
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8.3
- phpstan/phpstan: ^2.1.33
- rector/rector: ^2.3
This package is auto-updated.
Last update: 2026-01-04 18:46:02 UTC
README
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:
General Usage
Note
A ready-made scaffolder tool built on top of this library is available at 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
Changes
Changes implement the Change interface and define what modifications to apply. Each change:
- Implements a
decide(Context $context): callable|array|nullmethod - Returns an "applier" callable to execute, or
nullfor no-op - Can inspect the current state and decide whether to apply
Built-in Changes:
WriteFile- Write content to a fileWriteFileIfNotExists- Write file only if it doesn't existCopyFile- Copy a fileCopyFileIfNotExists- Copy file only if it doesn't existPrepareComposerJson- Update composer.json with package informationEnsureDirectoryWithGitkeep- Ensure directory exists with .gitkeepEnsureFact- Ensure a fact is resolved (useful for prompting user input)ChangeIf- Conditionally apply changes based on a condition
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.jsonPackageName- Package name (e.g., "vendor/package")PackageVendor- Vendor name from package namePackageProject- Project name from package namePackageDescription- Package descriptionPackageLicense- Package licensePackageType- Package type (library, project, etc.)PackageAuthors- Array of package authorsNamespaceX- Root namespace (e.g., "Vendor\Package")SourceDirectory- Source code directory (default: "src")TestsDirectory- Tests directory (default: "tests")PhpConstraint- PHP version constraintPhpConstraintName- PHP constraint name (default: "php")LowestMinorPhpVersion- Lowest minor PHP versionHighestMinorPhpVersion- Highest minor PHP versionMinorPhpVersionRange- PHP version rangePrepareComposerAutoload- Whether to prepare autoload sectionPrepareComposerAutoloadDev- Whether to prepare autoload-dev sectionCopyrightHolder- Copyright holder nameCopyrightYear- Copyright yearTitle- Project titleUserName- User/author nameUserEmail- User/author email
Parameters
The scaffolder supports a flexible parameter system that allows configuration through multiple sources with a clear priority order:
- Command line options - facts can add their own CLI options
scaffolder.phpfile - project-specific configuration- Runner constructor - default values
Setting parameters via scaffolder.php file:
Create a scaffolder.php file in your project directory:
<?php return [ 'namespace' => 'MyVendor\\MyProject', 'license' => 'MIT', ];
Setting default parameters via Runner:
new Runner( // ... params: [ 'namespace' => 'DefaultVendor\\DefaultProject', 'license' => 'BSD-3-Clause', ], )->run();
Parameters from scaffolder.php will override runner defaults.
Command Line Options:
--directory- specify the target directory where changes will be applied (default: current working directory)--scaffolder-file- Specify custom name for the configuration file (default:scaffolder.php)
php my-scaffolder.php --directory=/path/to/project --scaffolder-file=my-config.php
Documentation
If you have any questions or problems with this package, use author telegram chat for communication.
License
The vjik/scaffolder is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Credits
The package is inspired by phpyh/scaffolder code originally created by Valentin Udaltsov.