slendium / build
Small utility to organize tasks to make a PHP project production ready
Requires
- php: ^8.4
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12
README
Small utility for making PHP projects production-ready. Validating code using unit tests or static analysis should happen before this tool runs.
Installation
Simply run composer require slendium/build to add it to your project.
Usage
From your project root, run ./vendor/bin/slendium-build to start the "build" in the current working
directory. WARNING: tasks may remove local files, so make sure to only run this command on a clean
copy of the project.
The script will go through the following steps:
- Run
composer install --no-dev --classmap-authoritative - Find a list of tasks to run
- Either directly from the arguments, where each argument should be a PHP
class-string<Task> - Or from a file called
SlendiumBuild.jsonin the current working directory
- Either directly from the arguments, where each argument should be a PHP
- Run the tasks in the given order, if all classes exist
SlendiumBuild.json
This JSON file can be put in your project root to specify build options. Currently it supports one key:
tasks- a non-empty list ofclass-string<Task>'s to run in the given order
Tasks
To define your own task, simply create a PHP class that implements the Task interface and add the
fully qualified class name to the script arguments or to the JSON configuration file.
Example task
class MyTask implements Task { #[Override] public function run(BuildEnvironment $environment): iterable { $items = \iterator_to_array(ClassmapSearch::byInstanceOf($environment->classmap, Marker::class)); $progress = 0; foreach ($items as $class => file) { MyClassAnalysisUtil::analyze($class); $progress += 1; yield new Task\ProgressUpdate($progress, \count($items)); } if ($progress === 0) { yield new Task\Warning("Project did not contain any Marker classes to analyze"); } } }