Open reimic opened 4 months ago
We'll need to:
All dependencies but three degrade gracefully to PHP 7.0. Here's the resulting composer.json:
{
"prefer-stable": true,
"require": {
"symfony/event-dispatcher": "v3.4.47",
"symfony/filesystem": "v3.4.47",
"symfony/process": "v3.4.47",
"symfony/http-kernel": "v3.4.49",
"pimple/pimple": "v3.2.0",
"psr/simple-cache": "1.0.1",
"opis/json-schema": "1.1.0"
},
"require-dev": {
"phpunit/phpunit": "6.5.14",
"squizlabs/php_codesniffer": "3.9.0",
"nette/php-generator": "v3.0.5",
"bamarni/composer-bin-plugin": "v1.5.0",
"wp-coding-standards/wpcs": "3.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"allow-plugins": {
"php-http/discovery": true,
"bamarni/composer-bin-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"pestphp/pest-plugin": true
},
"platform": {
"php": "7.0.8"
}
},
"autoload": {
"classmap": [
"src/"
],
"psr-4": {
"WordPress\\": "src/WordPress",
"Symfony\\Component\\Process\\": "vendor/symfony/process"
},
"files": [
"src/WordPress/Blueprints/functions.php",
"src/WordPress/Zip/functions.php",
"src/WordPress/Streams/stream_str_replace.php"
]
},
"scripts": {
"phpcs": "phpcs --standard=WordPress"
}
}
The three packages that don't play well with PHP 7.0:
The lowest version is 4.x and it requires PHP 7.1. We could fork and transpile it, but it also requires a ton of dependencies and the API wasn't that nice and reliable when I explored it for the URLSource
. Let's see if the asynchronous HTTP streaming can be achieved with a custom implementation or another library. Guzzle 4.x seems to work with PHP 7.0 and support streams – perhaps it would do just fine? https://github.com/guzzle/guzzle/tree/4.x
The library is nice and useful but again it loads a bunch of dependencies. Let's try to reproduce its behavior using a small, custom, dependency-less implementation. Here's what it does in BlueprintMapper.php:
// In constructor
$this->mapper = JsonMapperBuilder::new()
->withPropertyMapper( new \JsonMapper\Handler\PropertyMapper( $classFactoryRegistry ) )
->withDocBlockAnnotationsMiddleware()
->withTypedPropertiesMiddleware()
->withNamespaceResolverMiddleware()
->build();
public function map( object $blueprint ): Blueprint {
return $this->mapper->mapToClass( $blueprint, Blueprint::class );
}
tl;dr, it turns a raw json_decode()
output into a Blueprint instance using the type information from PHP docblocks and custom data factories. See the details and related explorations in:
This is a code generator for model classes originally explored in https://github.com/WordPress/blueprints/pull/19. It's a developer tool that doesn't need to work with PHP 7.0 at all, it can work in PHP >= 8.3 for all I care – it's merely a contributor tool not exposed to Blueprint library consumers. I'm not sure if there's a way of including it in composer.json
but I wouldn't mind just shipping it as a .phar
file directly in the repo.
The above dependencies are no longer used in this repo. The only remaining part of this ticket are automated tools to ensure this library remains compatible with all PHP versions between 7.0 and 8.3
Since WordPress offers support for PHP >= 7.0 so should we.
Tasks: