diff --git a/Makefile b/Makefile index 314031474..869144f79 100644 --- a/Makefile +++ b/Makefile @@ -487,18 +487,19 @@ $(REQUIREMENT_CHECKER_EXTRACT): $(SCOPED_BOX_BIN): $(SCOPED_BOX_DEPS) @echo "$(YELLOW_COLOR)Compile Box.$(NO_COLOR)" - $(BOX) compile --ansi --no-parallel + @# Use parallelization + $(BOX) compile --ansi rm $(TMP_SCOPED_BOX_BIN) || true mv -v bin/box.phar $(TMP_SCOPED_BOX_BIN) @echo "$(YELLOW_COLOR)Compile Box with the isolated Box PHAR.$(NO_COLOR)" - php $(TMP_SCOPED_BOX_BIN) compile --ansi --no-parallel + php $(TMP_SCOPED_BOX_BIN) compile --ansi mv -fv bin/box.phar box @echo "$(YELLOW_COLOR)Test the PHAR which has been created by the isolated PHAR.$(NO_COLOR)" - ./box compile --ansi --no-parallel + ./box compile --ansi mv -fv box bin/box.phar rm $(TMP_SCOPED_BOX_BIN) diff --git a/bin/bench-test.php b/bin/bench-test.php index ca9e823a1..f529e778f 100644 --- a/bin/bench-test.php +++ b/bin/bench-test.php @@ -45,6 +45,7 @@ if ($parallelTime <= $maxParallelTimeTarget) { echo 'OK.'.PHP_EOL; + exit(0); } @@ -59,5 +60,5 @@ echo 'Failed!'.PHP_EOL; echo 'Missed the target by '.$relativeDifference.'%'.PHP_EOL; -// TODO: https://github.com/box-project/box/issues/552 -exit(0); + +exit(1); diff --git a/composer.json b/composer.json index c4549dd11..35dc0b1b0 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-mbstring": "*", "ext-phar": "*", "composer-plugin-api": "^2.2", - "amphp/parallel-functions": "^1.1", + "amphp/parallel": "^2.0", "composer/semver": "^3.3.2", "composer/xdebug-handler": "^3.0.3", "fidry/console": "^0.6.0", diff --git a/composer.lock b/composer.lock index f3101fa2d..f6e566a6c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,47 +4,40 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f10df66d9f665afff338919a664cda9d", + "content-hash": "c445e1791edfa74311fef34527afc10a", "packages": [ { "name": "amphp/amp", - "version": "v2.6.2", + "version": "v3.0.0", "source": { "type": "git", "url": "https://github.com/amphp/amp.git", - "reference": "9d5100cebffa729aaffecd3ad25dc5aeea4f13bb" + "reference": "aaf0ec1d5a2c20b523258995a10e80c1fb765871" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/amp/zipball/9d5100cebffa729aaffecd3ad25dc5aeea4f13bb", - "reference": "9d5100cebffa729aaffecd3ad25dc5aeea4f13bb", + "url": "https://api.github.com/repos/amphp/amp/zipball/aaf0ec1d5a2c20b523258995a10e80c1fb765871", + "reference": "aaf0ec1d5a2c20b523258995a10e80c1fb765871", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=8.1", + "revolt/event-loop": "^1 || ^0.2" }, "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", - "ext-json": "*", - "jetbrains/phpstorm-stubs": "^2019.3", - "phpunit/phpunit": "^7 | ^8 | ^9", - "psalm/phar": "^3.11@dev", - "react/promise": "^2" + "amphp/php-cs-fixer-config": "^2", + "phpunit/phpunit": "^9", + "psalm/phar": "^4.13" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, "autoload": { "files": [ - "lib/functions.php", - "lib/Internal/functions.php" + "src/functions.php", + "src/Future/functions.php", + "src/Internal/functions.php" ], "psr-4": { - "Amp\\": "lib" + "Amp\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -52,10 +45,6 @@ "MIT" ], "authors": [ - { - "name": "Daniel Lowrey", - "email": "rdlowrey@php.net" - }, { "name": "Aaron Piotrowski", "email": "aaron@trowski.com" @@ -67,6 +56,10 @@ { "name": "Niklas Keller", "email": "me@kelunik.com" + }, + { + "name": "Daniel Lowrey", + "email": "rdlowrey@php.net" } ], "description": "A non-blocking concurrency framework for PHP applications.", @@ -83,9 +76,8 @@ "promise" ], "support": { - "irc": "irc://irc.freenode.org/amphp", "issues": "https://github.com/amphp/amp/issues", - "source": "https://github.com/amphp/amp/tree/v2.6.2" + "source": "https://github.com/amphp/amp/tree/v3.0.0" }, "funding": [ { @@ -93,46 +85,45 @@ "type": "github" } ], - "time": "2022-02-20T17:52:18+00:00" + "time": "2022-12-18T16:52:44+00:00" }, { "name": "amphp/byte-stream", - "version": "v1.8.1", + "version": "v2.1.0", "source": { "type": "git", "url": "https://github.com/amphp/byte-stream.git", - "reference": "acbd8002b3536485c997c4e019206b3f10ca15bd" + "reference": "0a4b0e80dad92c75e6131f8ad253919211540338" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/byte-stream/zipball/acbd8002b3536485c997c4e019206b3f10ca15bd", - "reference": "acbd8002b3536485c997c4e019206b3f10ca15bd", + "url": "https://api.github.com/repos/amphp/byte-stream/zipball/0a4b0e80dad92c75e6131f8ad253919211540338", + "reference": "0a4b0e80dad92c75e6131f8ad253919211540338", "shasum": "" }, "require": { - "amphp/amp": "^2", - "php": ">=7.1" + "amphp/amp": "^3", + "amphp/parser": "^1.1", + "amphp/pipeline": "^1", + "amphp/serialization": "^1", + "amphp/sync": "^2", + "php": ">=8.1", + "revolt/event-loop": "^1 || ^0.2.3" }, "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1.4", - "friendsofphp/php-cs-fixer": "^2.3", - "jetbrains/phpstorm-stubs": "^2019.3", - "phpunit/phpunit": "^6 || ^7 || ^8", - "psalm/phar": "^3.11.4" + "amphp/php-cs-fixer-config": "^2", + "amphp/phpunit-util": "^3", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.4" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, "autoload": { "files": [ - "lib/functions.php" + "src/functions.php", + "src/Internal/functions.php" ], "psr-4": { - "Amp\\ByteStream\\": "lib" + "Amp\\ByteStream\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -150,7 +141,7 @@ } ], "description": "A stream abstraction to make working with non-blocking I/O simple.", - "homepage": "http://amphp.org/byte-stream", + "homepage": "https://amphp.org/byte-stream", "keywords": [ "amp", "amphp", @@ -160,9 +151,8 @@ "stream" ], "support": { - "irc": "irc://irc.freenode.org/amphp", "issues": "https://github.com/amphp/byte-stream/issues", - "source": "https://github.com/amphp/byte-stream/tree/v1.8.1" + "source": "https://github.com/amphp/byte-stream/tree/v2.1.0" }, "funding": [ { @@ -170,45 +160,39 @@ "type": "github" } ], - "time": "2021-03-30T17:13:30+00:00" + "time": "2023-11-19T14:34:16+00:00" }, { - "name": "amphp/parallel", - "version": "v1.4.3", + "name": "amphp/cache", + "version": "v2.0.0", "source": { "type": "git", - "url": "https://github.com/amphp/parallel.git", - "reference": "3aac213ba7858566fd83d38ccb85b91b2d652cb0" + "url": "https://github.com/amphp/cache.git", + "reference": "218bb3888d380eb9dd926cd06f803573c84391d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/parallel/zipball/3aac213ba7858566fd83d38ccb85b91b2d652cb0", - "reference": "3aac213ba7858566fd83d38ccb85b91b2d652cb0", + "url": "https://api.github.com/repos/amphp/cache/zipball/218bb3888d380eb9dd926cd06f803573c84391d3", + "reference": "218bb3888d380eb9dd926cd06f803573c84391d3", "shasum": "" }, "require": { - "amphp/amp": "^2", - "amphp/byte-stream": "^1.6.1", - "amphp/parser": "^1", - "amphp/process": "^1", + "amphp/amp": "^3", "amphp/serialization": "^1", - "amphp/sync": "^1.0.1", - "php": ">=7.1" + "amphp/sync": "^2", + "php": ">=8.1", + "revolt/event-loop": "^1 || ^0.2" }, "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1.1", - "phpunit/phpunit": "^8 || ^7" + "amphp/php-cs-fixer-config": "^2", + "amphp/phpunit-util": "^3", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.4" }, "type": "library", "autoload": { - "files": [ - "lib/Context/functions.php", - "lib/Sync/functions.php", - "lib/Worker/functions.php" - ], "psr-4": { - "Amp\\Parallel\\": "lib" + "Amp\\Cache\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -216,27 +200,112 @@ "MIT" ], "authors": [ + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + }, { "name": "Aaron Piotrowski", "email": "aaron@trowski.com" }, { - "name": "Stephen Coakley", - "email": "me@stephencoakley.com" + "name": "Daniel Lowrey", + "email": "rdlowrey@php.net" } ], - "description": "Parallel processing component for Amp.", - "homepage": "https://github.com/amphp/parallel", + "description": "A fiber-aware cache API based on Amp and Revolt.", + "homepage": "https://amphp.org/cache", + "support": { + "issues": "https://github.com/amphp/cache/issues", + "source": "https://github.com/amphp/cache/tree/v2.0.0" + }, + "funding": [ + { + "url": "https://github.com/amphp", + "type": "github" + } + ], + "time": "2023-01-09T21:04:12+00:00" + }, + { + "name": "amphp/dns", + "version": "v2.1.0", + "source": { + "type": "git", + "url": "https://github.com/amphp/dns.git", + "reference": "c3b518f321f26e786554480de580f06b9f34d1cd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/amphp/dns/zipball/c3b518f321f26e786554480de580f06b9f34d1cd", + "reference": "c3b518f321f26e786554480de580f06b9f34d1cd", + "shasum": "" + }, + "require": { + "amphp/amp": "^3", + "amphp/byte-stream": "^2", + "amphp/cache": "^2", + "amphp/parser": "^1", + "amphp/windows-registry": "^1", + "daverandom/libdns": "^2.0.2", + "ext-filter": "*", + "php": ">=8.1", + "revolt/event-loop": "^1 || ^0.2" + }, + "require-dev": { + "amphp/php-cs-fixer-config": "^2", + "amphp/phpunit-util": "^3", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.4" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "Amp\\Dns\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Wright", + "email": "addr@daverandom.com" + }, + { + "name": "Daniel Lowrey", + "email": "rdlowrey@php.net" + }, + { + "name": "Bob Weinand", + "email": "bobwei9@hotmail.com" + }, + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + }, + { + "name": "Aaron Piotrowski", + "email": "aaron@trowski.com" + } + ], + "description": "Async DNS resolution for Amp.", + "homepage": "https://github.com/amphp/dns", "keywords": [ + "amp", + "amphp", "async", - "asynchronous", - "concurrent", - "multi-processing", - "multi-threading" + "client", + "dns", + "resolve" ], "support": { - "issues": "https://github.com/amphp/parallel/issues", - "source": "https://github.com/amphp/parallel/tree/v1.4.3" + "issues": "https://github.com/amphp/dns/issues", + "source": "https://github.com/amphp/dns/tree/v2.1.0" }, "funding": [ { @@ -244,41 +313,50 @@ "type": "github" } ], - "time": "2023-03-23T08:04:23+00:00" + "time": "2023-11-18T15:49:57+00:00" }, { - "name": "amphp/parallel-functions", - "version": "v1.1.0", + "name": "amphp/parallel", + "version": "v2.2.3", "source": { "type": "git", - "url": "https://github.com/amphp/parallel-functions.git", - "reference": "04e92fcacfc921a56dfe12c23b3265e62593a7cb" + "url": "https://github.com/amphp/parallel.git", + "reference": "223c47cfa57dc8166d058c072c47fe650d6b5b1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/parallel-functions/zipball/04e92fcacfc921a56dfe12c23b3265e62593a7cb", - "reference": "04e92fcacfc921a56dfe12c23b3265e62593a7cb", + "url": "https://api.github.com/repos/amphp/parallel/zipball/223c47cfa57dc8166d058c072c47fe650d6b5b1d", + "reference": "223c47cfa57dc8166d058c072c47fe650d6b5b1d", "shasum": "" }, "require": { - "amphp/amp": "^2.0.3", - "amphp/parallel": "^1.4", - "amphp/serialization": "^1.0", - "laravel/serializable-closure": "^1.0", - "php": ">=7.4" + "amphp/amp": "^3", + "amphp/byte-stream": "^2", + "amphp/parser": "^1", + "amphp/pipeline": "^1", + "amphp/process": "^2", + "amphp/serialization": "^1", + "amphp/socket": "^2", + "amphp/sync": "^2", + "php": ">=8.1", + "revolt/event-loop": "^1" }, "require-dev": { - "amphp/php-cs-fixer-config": "v2.x-dev", - "amphp/phpunit-util": "^2.0", - "phpunit/phpunit": "^9.5.11" + "amphp/php-cs-fixer-config": "^2", + "amphp/phpunit-util": "^3", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.4" }, "type": "library", "autoload": { "files": [ - "src/functions.php" + "src/Context/functions.php", + "src/Context/Internal/functions.php", + "src/Ipc/functions.php", + "src/Worker/functions.php" ], "psr-4": { - "Amp\\ParallelFunctions\\": "src" + "Amp\\Parallel\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -286,15 +364,31 @@ "MIT" ], "authors": [ + { + "name": "Aaron Piotrowski", + "email": "aaron@trowski.com" + }, { "name": "Niklas Keller", "email": "me@kelunik.com" + }, + { + "name": "Stephen Coakley", + "email": "me@stephencoakley.com" } ], - "description": "Parallel processing made simple.", + "description": "Parallel processing component for Amp.", + "homepage": "https://github.com/amphp/parallel", + "keywords": [ + "async", + "asynchronous", + "concurrent", + "multi-processing", + "multi-threading" + ], "support": { - "issues": "https://github.com/amphp/parallel-functions/issues", - "source": "https://github.com/amphp/parallel-functions/tree/v1.1.0" + "issues": "https://github.com/amphp/parallel/issues", + "source": "https://github.com/amphp/parallel/tree/v2.2.3" }, "funding": [ { @@ -302,7 +396,7 @@ "type": "github" } ], - "time": "2022-02-03T19:32:41+00:00" + "time": "2023-11-25T00:18:59+00:00" }, { "name": "amphp/parser", @@ -366,37 +460,107 @@ ], "time": "2022-12-30T18:08:47+00:00" }, + { + "name": "amphp/pipeline", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/amphp/pipeline.git", + "reference": "810dee498d2fd7d2c9247b32d95f38c92c13169e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/amphp/pipeline/zipball/810dee498d2fd7d2c9247b32d95f38c92c13169e", + "reference": "810dee498d2fd7d2c9247b32d95f38c92c13169e", + "shasum": "" + }, + "require": { + "amphp/amp": "^3", + "php": ">=8.1", + "revolt/event-loop": "^1 || ^0.2" + }, + "require-dev": { + "amphp/php-cs-fixer-config": "^2", + "amphp/phpunit-util": "^3", + "phpunit/phpunit": "^9", + "psalm/phar": "^4.12" + }, + "type": "library", + "autoload": { + "psr-4": { + "Amp\\Pipeline\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Aaron Piotrowski", + "email": "aaron@trowski.com" + }, + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + } + ], + "description": "Asynchronous iterators and operators.", + "homepage": "https://amphp.org/pipeline", + "keywords": [ + "amp", + "amphp", + "async", + "io", + "iterator", + "non-blocking" + ], + "support": { + "issues": "https://github.com/amphp/pipeline/issues", + "source": "https://github.com/amphp/pipeline/tree/v1.0.0" + }, + "funding": [ + { + "url": "https://github.com/amphp", + "type": "github" + } + ], + "time": "2022-12-22T02:13:01+00:00" + }, { "name": "amphp/process", - "version": "v1.1.4", + "version": "v2.0.1", "source": { "type": "git", "url": "https://github.com/amphp/process.git", - "reference": "76e9495fd6818b43a20167cb11d8a67f7744ee0f" + "reference": "a65d3bc1f36ef12d44df42a68f0f0643183f1052" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/process/zipball/76e9495fd6818b43a20167cb11d8a67f7744ee0f", - "reference": "76e9495fd6818b43a20167cb11d8a67f7744ee0f", + "url": "https://api.github.com/repos/amphp/process/zipball/a65d3bc1f36ef12d44df42a68f0f0643183f1052", + "reference": "a65d3bc1f36ef12d44df42a68f0f0643183f1052", "shasum": "" }, "require": { - "amphp/amp": "^2", - "amphp/byte-stream": "^1.4", - "php": ">=7" + "amphp/amp": "^3", + "amphp/byte-stream": "^2", + "amphp/sync": "^2", + "php": ">=8.1", + "revolt/event-loop": "^1 || ^0.2" }, "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1", - "phpunit/phpunit": "^6" + "amphp/php-cs-fixer-config": "^2", + "amphp/phpunit-util": "^3", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.4" }, "type": "library", "autoload": { "files": [ - "lib/functions.php" + "src/functions.php" ], "psr-4": { - "Amp\\Process\\": "lib" + "Amp\\Process\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -417,11 +581,11 @@ "email": "me@kelunik.com" } ], - "description": "Asynchronous process manager.", - "homepage": "https://github.com/amphp/process", + "description": "A fiber-aware process manager based on Amp and Revolt.", + "homepage": "https://amphp.org/process", "support": { "issues": "https://github.com/amphp/process/issues", - "source": "https://github.com/amphp/process/tree/v1.1.4" + "source": "https://github.com/amphp/process/tree/v2.0.1" }, "funding": [ { @@ -429,7 +593,7 @@ "type": "github" } ], - "time": "2022-07-06T23:50:12+00:00" + "time": "2023-01-15T16:00:57+00:00" }, { "name": "amphp/serialization", @@ -489,34 +653,121 @@ }, "time": "2020-03-25T21:39:07+00:00" }, + { + "name": "amphp/socket", + "version": "v2.2.0", + "source": { + "type": "git", + "url": "https://github.com/amphp/socket.git", + "reference": "3418a0c5c0d4978b0e8e0619ce1da0851c4053d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/amphp/socket/zipball/3418a0c5c0d4978b0e8e0619ce1da0851c4053d3", + "reference": "3418a0c5c0d4978b0e8e0619ce1da0851c4053d3", + "shasum": "" + }, + "require": { + "amphp/amp": "^3", + "amphp/byte-stream": "^2", + "amphp/dns": "^2", + "ext-openssl": "*", + "kelunik/certificate": "^1.1", + "league/uri": "^6.5 | ^7", + "league/uri-interfaces": "^2.3 | ^7", + "php": ">=8.1", + "revolt/event-loop": "^1 || ^0.2" + }, + "require-dev": { + "amphp/php-cs-fixer-config": "^2", + "amphp/phpunit-util": "^3", + "amphp/process": "^2", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.4" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.php", + "src/Internal/functions.php", + "src/SocketAddress/functions.php" + ], + "psr-4": { + "Amp\\Socket\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Lowrey", + "email": "rdlowrey@gmail.com" + }, + { + "name": "Aaron Piotrowski", + "email": "aaron@trowski.com" + }, + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + } + ], + "description": "Non-blocking socket connection / server implementations based on Amp and Revolt.", + "homepage": "https://github.com/amphp/socket", + "keywords": [ + "amp", + "async", + "encryption", + "non-blocking", + "sockets", + "tcp", + "tls" + ], + "support": { + "issues": "https://github.com/amphp/socket/issues", + "source": "https://github.com/amphp/socket/tree/v2.2.0" + }, + "funding": [ + { + "url": "https://github.com/amphp", + "type": "github" + } + ], + "time": "2023-08-19T15:28:34+00:00" + }, { "name": "amphp/sync", - "version": "v1.4.2", + "version": "v2.1.0", "source": { "type": "git", "url": "https://github.com/amphp/sync.git", - "reference": "85ab06764f4f36d63b1356b466df6111cf4b89cf" + "reference": "50ddc7392cc8034b3e4798cef3cc90d3f4c0441c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/sync/zipball/85ab06764f4f36d63b1356b466df6111cf4b89cf", - "reference": "85ab06764f4f36d63b1356b466df6111cf4b89cf", + "url": "https://api.github.com/repos/amphp/sync/zipball/50ddc7392cc8034b3e4798cef3cc90d3f4c0441c", + "reference": "50ddc7392cc8034b3e4798cef3cc90d3f4c0441c", "shasum": "" }, "require": { - "amphp/amp": "^2.2", - "php": ">=7.1" + "amphp/amp": "^3", + "amphp/pipeline": "^1", + "amphp/serialization": "^1", + "php": ">=8.1", + "revolt/event-loop": "^1 || ^0.2" }, "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "amphp/phpunit-util": "^1.1", - "phpunit/phpunit": "^9 || ^8 || ^7" + "amphp/php-cs-fixer-config": "^2", + "amphp/phpunit-util": "^3", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.4" }, "type": "library", "autoload": { "files": [ - "src/functions.php", - "src/ConcurrentIterator/functions.php" + "src/functions.php" ], "psr-4": { "Amp\\Sync\\": "src" @@ -531,23 +782,79 @@ "name": "Aaron Piotrowski", "email": "aaron@trowski.com" }, + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + }, { "name": "Stephen Coakley", "email": "me@stephencoakley.com" } ], - "description": "Mutex, Semaphore, and other synchronization tools for Amp.", - "homepage": "https://github.com/amphp/sync", - "keywords": [ - "async", - "asynchronous", - "mutex", - "semaphore", - "synchronization" - ], + "description": "Non-blocking synchronization primitives for PHP based on Amp and Revolt.", + "homepage": "https://github.com/amphp/sync", + "keywords": [ + "async", + "asynchronous", + "mutex", + "semaphore", + "synchronization" + ], + "support": { + "issues": "https://github.com/amphp/sync/issues", + "source": "https://github.com/amphp/sync/tree/v2.1.0" + }, + "funding": [ + { + "url": "https://github.com/amphp", + "type": "github" + } + ], + "time": "2023-08-19T13:53:40+00:00" + }, + { + "name": "amphp/windows-registry", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/amphp/windows-registry.git", + "reference": "8248247a41af7f97b88e4716c0f8de39696ef111" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/amphp/windows-registry/zipball/8248247a41af7f97b88e4716c0f8de39696ef111", + "reference": "8248247a41af7f97b88e4716c0f8de39696ef111", + "shasum": "" + }, + "require": { + "amphp/byte-stream": "^2", + "amphp/process": "^2", + "php": ">=8.1" + }, + "require-dev": { + "amphp/php-cs-fixer-config": "^2", + "psalm/phar": "^5.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Amp\\WindowsRegistry\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + } + ], + "description": "Windows Registry Reader.", "support": { - "issues": "https://github.com/amphp/sync/issues", - "source": "https://github.com/amphp/sync/tree/v1.4.2" + "issues": "https://github.com/amphp/windows-registry/issues", + "source": "https://github.com/amphp/windows-registry/tree/v1.0.0" }, "funding": [ { @@ -555,7 +862,7 @@ "type": "github" } ], - "time": "2021-10-25T18:29:10+00:00" + "time": "2023-01-09T22:29:20+00:00" }, { "name": "composer/pcre", @@ -775,6 +1082,50 @@ ], "time": "2022-02-25T21:32:43+00:00" }, + { + "name": "daverandom/libdns", + "version": "v2.0.3", + "source": { + "type": "git", + "url": "https://github.com/DaveRandom/LibDNS.git", + "reference": "42c2d700d1178c9f9e78664793463f7f1aea248c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DaveRandom/LibDNS/zipball/42c2d700d1178c9f9e78664793463f7f1aea248c", + "reference": "42c2d700d1178c9f9e78664793463f7f1aea248c", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "php": ">=7.0" + }, + "suggest": { + "ext-intl": "Required for IDN support" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "LibDNS\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "DNS protocol implementation written in pure PHP", + "keywords": [ + "dns" + ], + "support": { + "issues": "https://github.com/DaveRandom/LibDNS/issues", + "source": "https://github.com/DaveRandom/LibDNS/tree/v2.0.3" + }, + "time": "2022-09-20T18:15:38+00:00" + }, { "name": "doctrine/deprecations", "version": "1.1.2", @@ -1178,27 +1529,26 @@ "time": "2023-09-26T02:20:38+00:00" }, { - "name": "laravel/serializable-closure", - "version": "v1.3.3", + "name": "kelunik/certificate", + "version": "v1.1.3", "source": { "type": "git", - "url": "https://github.com/laravel/serializable-closure.git", - "reference": "3dbf8a8e914634c48d389c1234552666b3d43754" + "url": "https://github.com/kelunik/certificate.git", + "reference": "7e00d498c264d5eb4f78c69f41c8bd6719c0199e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/3dbf8a8e914634c48d389c1234552666b3d43754", - "reference": "3dbf8a8e914634c48d389c1234552666b3d43754", + "url": "https://api.github.com/repos/kelunik/certificate/zipball/7e00d498c264d5eb4f78c69f41c8bd6719c0199e", + "reference": "7e00d498c264d5eb4f78c69f41c8bd6719c0199e", "shasum": "" }, "require": { - "php": "^7.3|^8.0" + "ext-openssl": "*", + "php": ">=7.0" }, "require-dev": { - "nesbot/carbon": "^2.61", - "pestphp/pest": "^1.21.3", - "phpstan/phpstan": "^1.8.2", - "symfony/var-dumper": "^5.4.11" + "amphp/php-cs-fixer-config": "^2", + "phpunit/phpunit": "^6 | 7 | ^8 | ^9" }, "type": "library", "extra": { @@ -1208,7 +1558,7 @@ }, "autoload": { "psr-4": { - "Laravel\\SerializableClosure\\": "src/" + "Kelunik\\Certificate\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1217,25 +1567,198 @@ ], "authors": [ { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - }, + "name": "Niklas Keller", + "email": "me@kelunik.com" + } + ], + "description": "Access certificate details and transform between different formats.", + "keywords": [ + "DER", + "certificate", + "certificates", + "openssl", + "pem", + "x509" + ], + "support": { + "issues": "https://github.com/kelunik/certificate/issues", + "source": "https://github.com/kelunik/certificate/tree/v1.1.3" + }, + "time": "2023-02-03T21:26:53+00:00" + }, + { + "name": "league/uri", + "version": "7.3.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri.git", + "reference": "36743c3961bb82bf93da91917b6bced0358a8d45" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri/zipball/36743c3961bb82bf93da91917b6bced0358a8d45", + "reference": "36743c3961bb82bf93da91917b6bced0358a8d45", + "shasum": "" + }, + "require": { + "league/uri-interfaces": "^7.3", + "php": "^8.1" + }, + "conflict": { + "league/uri-schemes": "^1.0" + }, + "suggest": { + "ext-bcmath": "to improve IPV4 host parsing", + "ext-fileinfo": "to create Data URI from file contennts", + "ext-gmp": "to improve IPV4 host parsing", + "ext-intl": "to handle IDN host with the best performance", + "jeremykendall/php-domain-parser": "to resolve Public Suffix and Top Level Domain", + "league/uri-components": "Needed to easily manipulate URI objects components", + "php-64bit": "to improve IPV4 host parsing", + "symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "URI manipulation library", + "homepage": "https://uri.thephpleague.com", + "keywords": [ + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "middleware", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "uri-template", + "url", + "ws" + ], + "support": { + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri-src/issues", + "source": "https://github.com/thephpleague/uri/tree/7.3.0" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2023-09-09T17:21:43+00:00" + }, + { + "name": "league/uri-interfaces", + "version": "7.3.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri-interfaces.git", + "reference": "c409b60ed2245ff94c965a8c798a60166db53361" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/c409b60ed2245ff94c965a8c798a60166db53361", + "reference": "c409b60ed2245ff94c965a8c798a60166db53361", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "php": "^8.1", + "psr/http-factory": "^1", + "psr/http-message": "^1.1 || ^2.0" + }, + "suggest": { + "ext-bcmath": "to improve IPV4 host parsing", + "ext-gmp": "to improve IPV4 host parsing", + "ext-intl": "to handle IDN host with the best performance", + "php-64bit": "to improve IPV4 host parsing", + "symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ { - "name": "Nuno Maduro", - "email": "nuno@laravel.com" + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" } ], - "description": "Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.", + "description": "Common interfaces and classes for URI representation and interaction", + "homepage": "https://uri.thephpleague.com", "keywords": [ - "closure", - "laravel", - "serializable" + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "url", + "ws" ], "support": { - "issues": "https://github.com/laravel/serializable-closure/issues", - "source": "https://github.com/laravel/serializable-closure" + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri-src/issues", + "source": "https://github.com/thephpleague/uri-interfaces/tree/7.3.0" }, - "time": "2023-11-08T14:08:06+00:00" + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2023-09-09T17:21:43+00:00" }, { "name": "nikic/iter", @@ -1663,6 +2186,114 @@ }, "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/http-factory", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "e616d01114759c4c489f93b099585439f795fe35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", + "reference": "e616d01114759c4c489f93b099585439f795fe35", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + }, + "time": "2023-04-10T20:10:41+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, { "name": "psr/log", "version": "3.0.0", @@ -1713,6 +2344,78 @@ }, "time": "2021-07-14T16:46:02+00:00" }, + { + "name": "revolt/event-loop", + "version": "v1.0.5", + "source": { + "type": "git", + "url": "https://github.com/revoltphp/event-loop.git", + "reference": "fce6063869513de56f639aa522b2ef2fedbf8d73" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/revoltphp/event-loop/zipball/fce6063869513de56f639aa522b2ef2fedbf8d73", + "reference": "fce6063869513de56f639aa522b2ef2fedbf8d73", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "ext-json": "*", + "jetbrains/phpstorm-stubs": "^2019.3", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.15" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Revolt\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Aaron Piotrowski", + "email": "aaron@trowski.com" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "ceesjank@gmail.com" + }, + { + "name": "Christian Lück", + "email": "christian@clue.engineering" + }, + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + } + ], + "description": "Rock-solid event loop for concurrent PHP applications.", + "keywords": [ + "async", + "asynchronous", + "concurrency", + "event", + "event-loop", + "non-blocking", + "scheduler" + ], + "support": { + "issues": "https://github.com/revoltphp/event-loop/issues", + "source": "https://github.com/revoltphp/event-loop/tree/v1.0.5" + }, + "time": "2023-11-19T14:45:35+00:00" + }, { "name": "sebastian/diff", "version": "4.0.5", diff --git a/src/Box.php b/src/Box.php index 3fd905318..d7c9afbdd 100644 --- a/src/Box.php +++ b/src/Box.php @@ -15,6 +15,7 @@ namespace KevinGH\Box; use Amp\MultiReasonException; +use Amp\Parallel\Worker\TaskFailureThrowable; use BadMethodCallException; use Countable; use DateTimeImmutable; @@ -288,7 +289,7 @@ public function registerStub(string $file): void /** * @param array $files * - * @throws MultiReasonException + * @throws TaskFailureThrowable */ public function addFiles(array $files, bool $binary): void { diff --git a/src/Console/Command/Compile.php b/src/Console/Command/Compile.php index c215d50cf..4e5247295 100644 --- a/src/Console/Command/Compile.php +++ b/src/Console/Command/Compile.php @@ -14,7 +14,7 @@ namespace KevinGH\Box\Console\Command; -use Amp\MultiReasonException; +use Amp\Parallel\Worker\TaskFailureThrowable; use DateTimeImmutable; use DateTimeInterface; use Fidry\Console\Command\Command; @@ -40,7 +40,6 @@ use KevinGH\Box\Console\PhpSettingsChecker; use KevinGH\Box\Constants; use KevinGH\Box\MapFile; -use KevinGH\Box\Parallelization\AmpFailureCollector; use KevinGH\Box\Phar\CompressionAlgorithm; use KevinGH\Box\Phar\SigningAlgorithm; use KevinGH\Box\RequirementChecker\DecodedComposerJson; @@ -501,16 +500,12 @@ private static function addFilesWithErrorHandling(Configuration $config, Box $bo $box->addFiles($config->getFiles(), false); return; - } catch (MultiReasonException $ampFailure) { + } catch (TaskFailureThrowable $ampFailure) { throw new ConsoleRuntimeException( sprintf( 'An Amp\Parallel error occurred. To diagnostic if it is an Amp error related, you may try again with "--no-parallel".' - .'Reason(s) of the failure:%s%s', - PHP_EOL, - implode( - PHP_EOL, - AmpFailureCollector::collectReasons($ampFailure), - ), + .'Reason(s) of the failure: %s', + $ampFailure->getMessage(), ), previous: $ampFailure, ); diff --git a/src/Parallelization/AmpFailureCollector.php b/src/Parallelization/AmpFailureCollector.php deleted file mode 100644 index 17979ce0b..000000000 --- a/src/Parallelization/AmpFailureCollector.php +++ /dev/null @@ -1,39 +0,0 @@ - - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace KevinGH\Box\Parallelization; - -use Amp\MultiReasonException; -use KevinGH\Box\NotInstantiable; -use Throwable; -use function array_map; -use function array_unique; - -final class AmpFailureCollector -{ - use NotInstantiable; - - /** - * @return list - */ - public static function collectReasons(MultiReasonException $exception): array - { - return array_unique( - array_map( - static fn (Throwable $throwable) => $throwable->getMessage(), - $exception->getReasons(), - ), - ); - } -} diff --git a/src/Parallelization/ParallelFileProcessor.php b/src/Parallelization/ParallelFileProcessor.php index 5913a35a2..eda020b98 100644 --- a/src/Parallelization/ParallelFileProcessor.php +++ b/src/Parallelization/ParallelFileProcessor.php @@ -14,26 +14,26 @@ namespace KevinGH\Box\Parallelization; -use Amp\MultiReasonException; -use Fidry\FileSystem\FS; -use Humbug\PhpScoper\Symbol\SymbolsRegistry; +use Amp\Parallel\Worker\Execution; +use Amp\Parallel\Worker\TaskFailureThrowable; +use Amp\Parallel\Worker\WorkerPool; use KevinGH\Box\Compactor\Compactors; use KevinGH\Box\MapFile; -use Symfony\Component\Process\Process; -use function Amp\ParallelFunctions\parallelMap; -use function Amp\Promise\wait; -use function KevinGH\Box\register_aliases; -use function KevinGH\Box\register_error_handler; +use function Amp\Future\await; +use function Amp\Parallel\Worker\workerPool; +use function array_chunk; /** * @private */ final class ParallelFileProcessor { + public const FILE_CHUNK_SIZE = 100; + /** * @param string[] $filePaths * - * @throws MultiReasonException + * @throws TaskFailureThrowable * * @return list */ @@ -43,54 +43,53 @@ public static function processFilesInParallel( MapFile $mapFile, Compactors $compactors, ): array { - $processFile = static function (string $file) use ($cwd, $mapFile, $compactors): array { - chdir($cwd); - - // Keep the fully qualified call here since this function may be executed without the right autoloading - // mechanism - register_aliases(); - register_error_handler(); - - $contents = FS::getFileContents($file); - - $local = $mapFile($file); - - $processedContents = $compactors->compact($local, $contents); - - return [$local, $processedContents, $compactors->getScoperSymbolsRegistry()]; - }; - - // In the case of parallel processing, an issue is caused due to the statefulness nature of the PhpScoper - // symbols registry. - // - // Indeed, the PhpScoper symbols registry stores the records of exposed/excluded classes and functions. If nothing is done, - // then the symbols registry retrieved in the end will here will be "blank" since the updated symbols registries are the ones - // from the workers used for the parallel processing. - // - // In order to avoid that, the symbols registries will be returned as a result as well in order to be able to merge - // all the symbols registries into one. - // - // This process is allowed thanks to the nature of the state of the symbols registries: having redundant classes or - // functions registered can easily be deal with so merging all those different states is actually - // straightforward. - $tuples = wait(parallelMap($filePaths, $processFile)); + $workerPool = workerPool(); + + $result = self::queueAndWaitForTasks( + $filePaths, + $workerPool, + $cwd, + $mapFile, + $compactors, + ); - if ([] === $tuples) { - return []; - } + $compactors->registerSymbolsRegistry($result->symbolsRegistry); - $filesWithContents = []; - $symbolRegistries = []; + return $result->filesWithContents; + } - foreach ($tuples as [$local, $processedContents, $symbolRegistry]) { - $filesWithContents[] = [$local, $processedContents]; - $symbolRegistries[] = $symbolRegistry; + /** + * @param string[] $filePaths + * + * @throws TaskFailureThrowable + */ + public static function queueAndWaitForTasks( + array $filePaths, + WorkerPool $workerPool, + string $cwd, + MapFile $mapFile, + Compactors $compactors, + ): TaskResult { + $executions = []; + + foreach (array_chunk($filePaths, self::FILE_CHUNK_SIZE) as $filePathsChunk) { + $executions[] = $workerPool->submit( + new ProcessFileTask( + $filePathsChunk, + $cwd, + $mapFile, + $compactors, + ), + ); } - $compactors->registerSymbolsRegistry( - SymbolsRegistry::createFromRegistries(array_filter($symbolRegistries)), + $results = await( + array_map( + static fn (Execution $execution) => $execution->getFuture(), + $executions, + ), ); - return $filesWithContents; + return TaskResult::aggregate($results); } } diff --git a/src/Parallelization/ParallelizationDecider.php b/src/Parallelization/ParallelizationDecider.php index d63fda54c..1dd05de83 100644 --- a/src/Parallelization/ParallelizationDecider.php +++ b/src/Parallelization/ParallelizationDecider.php @@ -25,7 +25,7 @@ final class ParallelizationDecider { use NotInstantiable; - private const MIN_FILE_COUNT = 500; + private const MIN_FILE_COUNT = 5 * ParallelFileProcessor::FILE_CHUNK_SIZE; public static function shouldProcessFilesInParallel( Scoper $scoper, diff --git a/src/Parallelization/ProcessFileTask.php b/src/Parallelization/ProcessFileTask.php new file mode 100644 index 000000000..756d6bdf7 --- /dev/null +++ b/src/Parallelization/ProcessFileTask.php @@ -0,0 +1,79 @@ + + * Théo Fidry + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace KevinGH\Box\Parallelization; + +use Amp\Cancellation; +use Amp\Parallel\Worker\Task; +use Amp\Sync\Channel; +use Fidry\FileSystem\FS; +use Humbug\PhpScoper\Symbol\SymbolsRegistry; +use KevinGH\Box\Compactor\Compactors; +use KevinGH\Box\MapFile; +use function array_map; +use function KevinGH\Box\register_aliases; +use function KevinGH\Box\register_error_handler; + +/** + * @private + */ +final readonly class ProcessFileTask implements Task +{ + /** + * @param string[] $filePaths + */ + public function __construct( + private array $filePaths, + private string $cwd, + private MapFile $mapFile, + private Compactors $compactors, + ) { + } + + public function run(Channel $channel, Cancellation $cancellation): TaskResult + { + chdir($this->cwd); + + register_aliases(); + register_error_handler(); + + $mapFile = $this->mapFile; + $compactors = $this->compactors; + + $processFile = static function (string $file) use ($mapFile, $compactors): array { + $contents = FS::getFileContents($file); + + $local = $mapFile($file); + + $processedContents = $compactors->compact($local, $contents); + + return [$local, $processedContents, $compactors->getScoperSymbolsRegistry()]; + }; + + $tuples = array_map($processFile, $this->filePaths); + + $filesWithContents = []; + $symbolRegistries = []; + + foreach ($tuples as [$local, $processedContents, $symbolRegistry]) { + $filesWithContents[] = [$local, $processedContents]; + $symbolRegistries[] = $symbolRegistry; + } + + return new TaskResult( + $filesWithContents, + SymbolsRegistry::createFromRegistries(array_filter($symbolRegistries)), + ); + } +} diff --git a/src/Parallelization/TaskResult.php b/src/Parallelization/TaskResult.php new file mode 100644 index 000000000..5c58f536b --- /dev/null +++ b/src/Parallelization/TaskResult.php @@ -0,0 +1,52 @@ + + * Théo Fidry + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace KevinGH\Box\Parallelization; + +use Humbug\PhpScoper\Symbol\SymbolsRegistry; +use function array_merge; + +/** + * @private + */ +final readonly class TaskResult +{ + /** + * @param self[] $results + */ + public static function aggregate(array $results): self + { + $filesWithContents = []; + $symbolsRegistries = []; + + foreach ($results as $result) { + $filesWithContents[] = $result->filesWithContents; + $symbolsRegistries[] = $result->symbolsRegistry; + } + + return new self( + array_merge(...$filesWithContents), + SymbolsRegistry::createFromRegistries($symbolsRegistries), + ); + } + + /** + * @param list $filesWithContents + */ + public function __construct( + public array $filesWithContents, + public SymbolsRegistry $symbolsRegistry, + ) { + } +} diff --git a/tests/Parallelization/TaskResultTest.php b/tests/Parallelization/TaskResultTest.php new file mode 100644 index 000000000..270df8d26 --- /dev/null +++ b/tests/Parallelization/TaskResultTest.php @@ -0,0 +1,91 @@ + + * Théo Fidry + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace KevinGH\Box\Parallelization; + +use Humbug\PhpScoper\Symbol\SymbolsRegistry; +use PhpParser\Node\Name\FullyQualified; +use PHPUnit\Framework\TestCase; + +/** + * @covers \KevinGH\Box\Parallelization\TaskResult + * @internal + */ +final class TaskResultTest extends TestCase +{ + /** + * @dataProvider resultsProvider + */ + public function test_it_can_aggregate_results( + array $results, + TaskResult $expected, + ): void { + $actual = TaskResult::aggregate($results); + + self::assertEquals($expected, $actual); + } + + public static function resultsProvider(): iterable + { + $symbolsRegistry1 = new SymbolsRegistry(); + $symbolsRegistry1->recordFunction( + new FullyQualified('Acme\foo'), + new FullyQualified('Isolated\Acme\foo'), + ); + + $symbolsRegistry2 = new SymbolsRegistry(); + $symbolsRegistry2->recordFunction( + new FullyQualified('Acme\bar'), + new FullyQualified('Isolated\Acme\bar'), + ); + + $expectedSymbolsRegistry = new SymbolsRegistry(); + $expectedSymbolsRegistry->recordFunction( + new FullyQualified('Acme\foo'), + new FullyQualified('Isolated\Acme\foo'), + ); + $expectedSymbolsRegistry->recordFunction( + new FullyQualified('Acme\bar'), + new FullyQualified('Isolated\Acme\bar'), + ); + + yield [ + [ + new TaskResult( + [ + ['fileA', 'contentA'], + ['fileB', 'contentB'], + ], + $symbolsRegistry1, + ), + new TaskResult( + [ + ['fileC', 'contentC'], + ['fileD', 'contentD'], + ], + $symbolsRegistry2, + ), + ], + new TaskResult( + [ + ['fileA', 'contentA'], + ['fileB', 'contentB'], + ['fileC', 'contentC'], + ['fileD', 'contentD'], + ], + $expectedSymbolsRegistry, + ), + ]; + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 88bb618dd..857c717c4 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -12,7 +12,6 @@ * with this source code in the file LICENSE. */ -use Laravel\SerializableClosure\Support\ClosureStream; use org\bovigo\vfs\vfsStreamWrapper; use Symfony\Component\Filesystem\Path; use function KevinGH\Box\register_aliases; @@ -21,7 +20,6 @@ register_aliases(); vfsStreamWrapper::register(); -ClosureStream::register(); $binBoxPath = Path::normalize(__DIR__.'/../bin/box');