* @license MIT */ class Php extends Plugin { /** * PHP versions. */ private const VERSIONS = [ '55', '56', '70', '71', '72', '73', '74', '80', ]; /** * Default target. */ private const DEFAULT_TARGET = '70'; /** * Get PHP version range to target. * * @param array $config * @return array */ private static function getRange(array $config): array { $target = $config['target'] ?? PHP_MAJOR_VERSION.PHP_MINOR_VERSION; if (\preg_match(":^\D*(\d+\.\d+)\..*:", $config['target'], $matches)) { $target = $matches[1]; } $key = \array_search(\str_replace('.', '', $target), self::VERSIONS); return \array_slice( self::VERSIONS, $key === false ? self::DEFAULT_TARGET : $key ); } public static function composerRequires(array $config): array { return \array_fill_keys( \array_map(fn (string $version): string => "symfony/polyfill-$version", self::getRange($config)), '*' ); } public static function runWithAfter(array $config): array { $classes = []; foreach (self::getRange($config) as $version) { foreach (\scandir(__DIR__."/Php$version") as $file) { if (\substr($file, -4) !== '.php') { continue; } $class = \basename($version, '.php'); $classes[$class] = $config[$class] ?? []; } } return $classes; } }