diff --git a/.gitignore b/.gitignore index 5338a0e1..fdcf6369 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ outdir/ test.php run_phar.php run_src.php +.phive +vendor-bin +new-wp diff --git a/README.md b/README.md index 47c517ae..cb9c8f77 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ ## Setup -Install composer dependencies: +Install [composer](https://getcomposer.org/) and the required composer dependencies via ```shell composer install ``` +## Useful commands + Run tests with ```shell @@ -24,11 +26,17 @@ Run a Blueprint with php blueprint_compiling.php ``` -Setup WordPress with SQLite using asynchronous resource fetching as follows: +## Building to .phar + +The Blueprints library is distributed as a .phar library. To build the .phar file, run: ```shell -php setup_wordpress.php -cd outdir/wordpress -php wp-cli.phar core install --url=localhost:8550 --title="My test site" --admin_user=admin --admin_email="admin@localhost.com" --admin_password="password" -php wp-cli.phar server --port=8550 +vendor/bin/box compile ``` + +To try the built .phar file, run: + +```shell +rm -rf new-wp/* && USE_PHAR=1 php blueprint_compiling.php +``` + diff --git a/bin/build_phar.sh b/bin/build_phar.sh deleted file mode 100644 index 0c2d7ba7..00000000 --- a/bin/build_phar.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -php -dphar.readonly=0 bin/build_phar.php diff --git a/blueprint_compiling.php b/blueprint_compiling.php index 08c83b77..6e01385e 100644 --- a/blueprint_compiling.php +++ b/blueprint_compiling.php @@ -1,10 +1,13 @@ withWordPressVersion( 'https://wordpress.org/latest.zip' ) @@ -34,12 +37,6 @@ ->toBlueprint(); -$c = ( new ContainerBuilder() )->build( - new NativePHPRuntime( - __DIR__ . '/new-wp' - ) -); - -$results = $c['blueprint.engine']->runBlueprint( $blueprint ); +$results = run_blueprint( $blueprint, __DIR__ . '/new-wp' ); var_dump( $results ); diff --git a/box.json b/box.json new file mode 100644 index 00000000..4e37b2e8 --- /dev/null +++ b/box.json @@ -0,0 +1,13 @@ +{ + "main": "vendor/autoload.php", + "output": "dist/blueprints.phar", + "compactors": [ + "KevinGH\\Box\\Compactor\\Php" + ], + "compression": "GZ", + "annotations": false, + "directories": [ + "vendor/symfony/process" + ], + "force-autodiscovery": true +} diff --git a/composer.json b/composer.json index 316d3832..9d2818e0 100644 --- a/composer.json +++ b/composer.json @@ -1,36 +1,38 @@ { "require": { + "json-mapper/json-mapper": "^2.21", "symfony/event-dispatcher": "^7.0", - "justinrainbow/json-schema": "^5.2", "symfony/filesystem": "^7.0", - "psr/simple-cache": "^3.0", + "symfony/process": "^7.0", "symfony/http-client": "^7.0", "symfony/http-kernel": "^7.0", "pimple/pimple": "^3.0", - "opis/json-schema": "^2.3", - "nette/php-generator": "^4.1", - "json-mapper/json-mapper": "^2.21" + "psr/simple-cache": "^3.0", + "opis/json-schema": "^2.3" }, "require-dev": { "pestphp/pest": "^2.33", - "jane-php/json-schema": "^7.6" + "nette/php-generator": "^4.1", + "jane-php/json-schema": "^7.6", + "bamarni/composer-bin-plugin": "^1.8" }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "allow-plugins": { "pestphp/pest-plugin": true, - "php-http/discovery": true + "php-http/discovery": true, + "bamarni/composer-bin-plugin": true } }, "autoload": { "psr-4": { - "WordPress\\": "src/WordPress" + "WordPress\\": "src/WordPress", + "Symfony\\Component\\Process\\": "vendor/symfony/process" }, "files": [ "src/WordPress/Blueprints/functions.php", "src/WordPress/Zip/functions.php", - "src/WordPress/Blueprints/functions.php", "src/WordPress/Streams/stream_str_replace.php" ] } diff --git a/composer.lock b/composer.lock index 1460b5e0..79705992 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "944e9eb87cfc3492069b6a0fd6c36f8b", + "content-hash": "f70fd8a5043c08bdc0f94e0b5bbb93c0", "packages": [ { "name": "json-mapper/json-mapper", @@ -75,76 +75,6 @@ ], "time": "2023-12-12T11:57:53+00:00" }, - { - "name": "justinrainbow/json-schema", - "version": "v5.2.13", - "source": { - "type": "git", - "url": "https://github.com/justinrainbow/json-schema.git", - "reference": "fbbe7e5d79f618997bc3332a6f49246036c45793" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/fbbe7e5d79f618997bc3332a6f49246036c45793", - "reference": "fbbe7e5d79f618997bc3332a6f49246036c45793", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", - "json-schema/json-schema-test-suite": "1.2.0", - "phpunit/phpunit": "^4.8.35" - }, - "bin": [ - "bin/validate-json" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "JsonSchema\\": "src/JsonSchema/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bruno Prieto Reis", - "email": "bruno.p.reis@gmail.com" - }, - { - "name": "Justin Rainbow", - "email": "justin.rainbow@gmail.com" - }, - { - "name": "Igor Wiedler", - "email": "igor@wiedler.ch" - }, - { - "name": "Robert Schönthal", - "email": "seroscho@googlemail.com" - } - ], - "description": "A library to validate a json schema.", - "homepage": "https://github.com/justinrainbow/json-schema", - "keywords": [ - "json", - "schema" - ], - "support": { - "issues": "https://github.com/justinrainbow/json-schema/issues", - "source": "https://github.com/justinrainbow/json-schema/tree/v5.2.13" - }, - "time": "2023-09-26T02:20:38+00:00" - }, { "name": "myclabs/php-enum", "version": "1.8.4", @@ -208,161 +138,6 @@ ], "time": "2022-08-04T09:53:51+00:00" }, - { - "name": "nette/php-generator", - "version": "v4.1.3", - "source": { - "type": "git", - "url": "https://github.com/nette/php-generator.git", - "reference": "08ab9bff22ae34fe4e1d2fe8ba16b3770ea2459f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nette/php-generator/zipball/08ab9bff22ae34fe4e1d2fe8ba16b3770ea2459f", - "reference": "08ab9bff22ae34fe4e1d2fe8ba16b3770ea2459f", - "shasum": "" - }, - "require": { - "nette/utils": "^3.2.9 || ^4.0", - "php": "8.0 - 8.3" - }, - "require-dev": { - "jetbrains/phpstorm-attributes": "dev-master", - "nette/tester": "^2.4", - "nikic/php-parser": "^4.18 || ^5.0", - "phpstan/phpstan": "^1.0", - "tracy/tracy": "^2.8" - }, - "suggest": { - "nikic/php-parser": "to use ClassType::from(withBodies: true) & ClassType::fromCode()" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause", - "GPL-2.0-only", - "GPL-3.0-only" - ], - "authors": [ - { - "name": "David Grudl", - "homepage": "https://davidgrudl.com" - }, - { - "name": "Nette Community", - "homepage": "https://nette.org/contributors" - } - ], - "description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.3 features.", - "homepage": "https://nette.org", - "keywords": [ - "code", - "nette", - "php", - "scaffolding" - ], - "support": { - "issues": "https://github.com/nette/php-generator/issues", - "source": "https://github.com/nette/php-generator/tree/v4.1.3" - }, - "time": "2024-01-18T17:44:20+00:00" - }, - { - "name": "nette/utils", - "version": "v4.0.4", - "source": { - "type": "git", - "url": "https://github.com/nette/utils.git", - "reference": "d3ad0aa3b9f934602cb3e3902ebccf10be34d218" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nette/utils/zipball/d3ad0aa3b9f934602cb3e3902ebccf10be34d218", - "reference": "d3ad0aa3b9f934602cb3e3902ebccf10be34d218", - "shasum": "" - }, - "require": { - "php": ">=8.0 <8.4" - }, - "conflict": { - "nette/finder": "<3", - "nette/schema": "<1.2.2" - }, - "require-dev": { - "jetbrains/phpstorm-attributes": "dev-master", - "nette/tester": "^2.5", - "phpstan/phpstan": "^1.0", - "tracy/tracy": "^2.9" - }, - "suggest": { - "ext-gd": "to use Image", - "ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()", - "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", - "ext-json": "to use Nette\\Utils\\Json", - "ext-mbstring": "to use Strings::lower() etc...", - "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause", - "GPL-2.0-only", - "GPL-3.0-only" - ], - "authors": [ - { - "name": "David Grudl", - "homepage": "https://davidgrudl.com" - }, - { - "name": "Nette Community", - "homepage": "https://nette.org/contributors" - } - ], - "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.", - "homepage": "https://nette.org", - "keywords": [ - "array", - "core", - "datetime", - "images", - "json", - "nette", - "paginator", - "password", - "slugify", - "string", - "unicode", - "utf-8", - "utility", - "validation" - ], - "support": { - "issues": "https://github.com/nette/utils/issues", - "source": "https://github.com/nette/utils/tree/v4.0.4" - }, - "time": "2024-01-17T16:50:36+00:00" - }, { "name": "nikic/php-parser", "version": "v4.18.0", @@ -2373,6 +2148,63 @@ } ], "packages-dev": [ + { + "name": "bamarni/composer-bin-plugin", + "version": "1.8.2", + "source": { + "type": "git", + "url": "https://github.com/bamarni/composer-bin-plugin.git", + "reference": "92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bamarni/composer-bin-plugin/zipball/92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880", + "reference": "92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "ext-json": "*", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-phpunit": "^1.1", + "phpunit/phpunit": "^8.5 || ^9.5", + "symfony/console": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0", + "symfony/finder": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0", + "symfony/process": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Bamarni\\Composer\\Bin\\BamarniBinPlugin" + }, + "autoload": { + "psr-4": { + "Bamarni\\Composer\\Bin\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "No conflicts for your bin dependencies", + "keywords": [ + "composer", + "conflict", + "dependency", + "executable", + "isolation", + "tool" + ], + "support": { + "issues": "https://github.com/bamarni/composer-bin-plugin/issues", + "source": "https://github.com/bamarni/composer-bin-plugin/tree/1.8.2" + }, + "time": "2022-10-31T08:38:03+00:00" + }, { "name": "brianium/paratest", "version": "v7.4.3", @@ -3167,6 +2999,161 @@ ], "time": "2023-03-08T13:26:56+00:00" }, + { + "name": "nette/php-generator", + "version": "v4.1.3", + "source": { + "type": "git", + "url": "https://github.com/nette/php-generator.git", + "reference": "08ab9bff22ae34fe4e1d2fe8ba16b3770ea2459f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/php-generator/zipball/08ab9bff22ae34fe4e1d2fe8ba16b3770ea2459f", + "reference": "08ab9bff22ae34fe4e1d2fe8ba16b3770ea2459f", + "shasum": "" + }, + "require": { + "nette/utils": "^3.2.9 || ^4.0", + "php": "8.0 - 8.3" + }, + "require-dev": { + "jetbrains/phpstorm-attributes": "dev-master", + "nette/tester": "^2.4", + "nikic/php-parser": "^4.18 || ^5.0", + "phpstan/phpstan": "^1.0", + "tracy/tracy": "^2.8" + }, + "suggest": { + "nikic/php-parser": "to use ClassType::from(withBodies: true) & ClassType::fromCode()" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.3 features.", + "homepage": "https://nette.org", + "keywords": [ + "code", + "nette", + "php", + "scaffolding" + ], + "support": { + "issues": "https://github.com/nette/php-generator/issues", + "source": "https://github.com/nette/php-generator/tree/v4.1.3" + }, + "time": "2024-01-18T17:44:20+00:00" + }, + { + "name": "nette/utils", + "version": "v4.0.4", + "source": { + "type": "git", + "url": "https://github.com/nette/utils.git", + "reference": "d3ad0aa3b9f934602cb3e3902ebccf10be34d218" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/utils/zipball/d3ad0aa3b9f934602cb3e3902ebccf10be34d218", + "reference": "d3ad0aa3b9f934602cb3e3902ebccf10be34d218", + "shasum": "" + }, + "require": { + "php": ">=8.0 <8.4" + }, + "conflict": { + "nette/finder": "<3", + "nette/schema": "<1.2.2" + }, + "require-dev": { + "jetbrains/phpstorm-attributes": "dev-master", + "nette/tester": "^2.5", + "phpstan/phpstan": "^1.0", + "tracy/tracy": "^2.9" + }, + "suggest": { + "ext-gd": "to use Image", + "ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()", + "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", + "ext-json": "to use Nette\\Utils\\Json", + "ext-mbstring": "to use Strings::lower() etc...", + "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.", + "homepage": "https://nette.org", + "keywords": [ + "array", + "core", + "datetime", + "images", + "json", + "nette", + "paginator", + "password", + "slugify", + "string", + "unicode", + "utf-8", + "utility", + "validation" + ], + "support": { + "issues": "https://github.com/nette/utils/issues", + "source": "https://github.com/nette/utils/tree/v4.0.4" + }, + "time": "2024-01-17T16:50:36+00:00" + }, { "name": "nunomaduro/collision", "version": "v8.1.0", @@ -3880,21 +3867,21 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.8.1", + "version": "1.8.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353" + "reference": "153ae662783729388a584b4361f2545e4d841e3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353", - "reference": "bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/153ae662783729388a584b4361f2545e4d841e3c", + "reference": "153ae662783729388a584b4361f2545e4d841e3c", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", - "php": "^7.4 || ^8.0", + "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", "phpstan/phpdoc-parser": "^1.13" }, @@ -3932,9 +3919,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.1" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.2" }, - "time": "2024-01-18T19:15:27+00:00" + "time": "2024-02-23T11:10:43+00:00" }, { "name": "phpstan/phpdoc-parser", diff --git a/src/WordPress/Blueprints/ContainerBuilder.php b/src/WordPress/Blueprints/ContainerBuilder.php index cc54b2fc..f468466d 100644 --- a/src/WordPress/Blueprints/ContainerBuilder.php +++ b/src/WordPress/Blueprints/ContainerBuilder.php @@ -181,9 +181,6 @@ function () use ( $c ) { $container[ "step.runner." . DefineSiteUrlStep::DISCRIMINATOR ] = function () { return new DefineSiteUrlStepRunner(); }; - $container[ "step.runner." . RmDirStep::DISCRIMINATOR ] = function () { - return new RmDirStepRunner(); - }; $container[ "step.runner." . RmStep::DISCRIMINATOR ] = function () { return new RmStepRunner(); }; diff --git a/src/WordPress/Blueprints/Resource/ResourceMap.php b/src/WordPress/Blueprints/Resource/ResourceMap.php index 742f2cb5..122cc5da 100644 --- a/src/WordPress/Blueprints/Resource/ResourceMap.php +++ b/src/WordPress/Blueprints/Resource/ResourceMap.php @@ -26,7 +26,8 @@ public function offsetGet( $offset ): mixed { return $pair[1]; } } - throw new \Exception( "Offset not found" ); + + throw new \Exception( "Stream for resource " . json_encode( $offset ) . " not found" ); } public function offsetSet( $offset, $value ): void { diff --git a/src/WordPress/Blueprints/functions.php b/src/WordPress/Blueprints/functions.php index d2fc8dbb..ae7281ce 100644 --- a/src/WordPress/Blueprints/functions.php +++ b/src/WordPress/Blueprints/functions.php @@ -3,6 +3,17 @@ namespace WordPress\Blueprints; use Symfony\Component\Filesystem\Exception\IOException; +use WordPress\Blueprints\Runtime\NativePHPRuntime; + +function run_blueprint( $json, $documentRoot = '/wordpress' ) { + $c = ( new ContainerBuilder() )->build( + new NativePHPRuntime( + $documentRoot + ) + ); + + return $c['blueprint.engine']->runBlueprint( $json ); +} function list_files( string $path, $omitDotFiles = false ): array { return array_values( array_filter( scandir( $path ), function ( $file ) use ( $omitDotFiles ) {