Standalone PHP libraries for use in WordPress plugins and standalone PHP projects:
This fork consolidates a few earlier projects and explorations into a single composer package.
The Blueprints v2 runner is an all-php CLI tool that runs Blueprints v1 and v2. To use it, download blueprints.phar from the latest release and run it:
php blueprints.phar
From there, follow the help message for required arguments and options.
If you want to use Blueprints as a library, you absolutely can. It is designed to be reusable,
compatible with web and CLI environments on PHP 7.2+. There’s not much technical documentation
at this point but you can refer to the blueprints.php file to see
how the runner is implemented.
The individual components are now distributed via Composer at https://packagist.org/packages/wp-php-toolkit. You can install specific components you need rather than the entire toolkit.
To install a specific component, use composer:
composer require wp-php-toolkit/http-client
composer require wp-php-toolkit/data-liberation
composer require wp-php-toolkit/git
# ... and so on for other components
For convenience, a standalone Blueprints runner and other tools from this repository are shipped as phar files available in the GitHub releases.
A Dev Container spec is included in .devcontainer/.
It provides PHP 8.1 with all the required extensions, Composer, and editor
tooling pre-configured. Works with VS Code (“Reopen in Container”), GitHub
Codespaces, or devcontainer up --workspace-folder . from the CLI.
For running tests and lints in an isolated container without a full dev
environment, use the Docker Compose sandbox:
# Build once
docker compose build
# Run all tests
docker compose run --rm sandbox vendor/bin/phpunit -c phpunit.xml
# Run tests for one component
docker compose run --rm sandbox vendor/bin/phpunit components/Zip/Tests/
# Run a PHP script
docker compose run --rm sandbox php my-script.php
# Lint
docker compose run --rm sandbox vendor/bin/phpcs -d memory_limit=1G .
The sandbox has no network access, a read-only root filesystem, and all Linux
capabilities dropped — the only writable areas are the project mount and /tmp.
The test suite works directly on the host too — no database, no web server,
no external services needed. You just need PHP 7.2+ with json and mbstring.
composer test
composer lint
To fix the linting errors, run:
composer lint-fix
The root composer.json file is an amalgamation of composer.base.json all
component composer.json files. To regenerate it, run:
bin/regenerate_composer.json.php
This will merge all the package-specific dependencies and the autoload rules into
the root composer.json file.
Windows compatibility is achieved on a few different fronts:
This repository comes with a .gitattributes file to ensure that the unit test
files and fixtures are normalized to \n on checkout. It’s important, because
Windows uses \r\n for newlines in text files. Unix-based systems use \n.
Without the .gitattributes, git on Windows would replace all the \n with \r\n
on checkout.
The strings produced by the library uses \n for newlines where it can make
that choice. For example, the WXRWriter class will separate XML tags with
\n newlines to make sure the generated XML is consistent across platforms.
The Filesystem components makes a point of using Unix-style forward slashes
as directory separators, even on Windows.
As a library consumer, ensure all the local paths you pass to the library are
using Unix-style forward slashes as directory separators. A simple str_replace
will do the trick:
if (DIRECTORY_SEPARATOR === '\\') {
$path = str_replace('\\', '/', $path);
}
The reason for using Unix-style forward slashes is care for data integrity.
Windows understands both forward slashes and backslashes, so the replacement
operation is safe there. On Unix, however, a backslash can be used as a part
of a filename so it cannot be safely translated.
Importantly, do not just run this str_replace() on every possible path.
C:\my-dir\my-file.txt is both, a valid Windows absolute path and a valid Unix
filename and a relative path. Furthermore, Filesystem supports more filesystems
than just local disk.
Anytime you’re handling paths, consider:
If the answers are “local” and “Windows”, you may need to apply the str_replace()
slash normalization. Otherwise, just keep the path as it is.
The takeaway from this section is: paths are difficult.
For a fun read on the topic, check out this article: Windows File Paths.
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.