Skip to content

Commit

Permalink
Drop PHP5.3 support (#674)
Browse files Browse the repository at this point in the history
As Composer 2.3 is dropping PHP 5.3 and requires 7.2.5+ as the minimum PHP version, so does Box.

In theory it would be possible to keep the 5.3 compatibility, but that would require non trivial efforts as it would require to make the bundle requirement checker work without Composer autoloading _and_ keeping track of Composer Semver too.

Since 7.2.5 is now the minimum, the requirement checker has been pimped up a bit.

Closes #656
  • Loading branch information
theofidry authored Jun 20, 2022
1 parent c78fe3c commit a6182b4
Show file tree
Hide file tree
Showing 44 changed files with 496 additions and 682 deletions.
4 changes: 2 additions & 2 deletions .docker/build
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ readonly DOCKER=$(which docker)
# Globals
# PWD

if [[ "$(docker images -q box_php53 2> /dev/null)" == "" ]]; then
$DOCKER build --platform=linux/amd64 --tag=box_php53 --file "$PWD/.docker/php53" .
if [[ "$(docker images -q box_php725 2> /dev/null)" == "" ]]; then
$DOCKER build --platform=linux/amd64 --tag=box_php725 --file "$PWD/.docker/php725" .
fi

if [[ "$(docker images -q box_php81 2> /dev/null)" == "" ]]; then
Expand Down
4 changes: 0 additions & 4 deletions .docker/php53

This file was deleted.

1 change: 1 addition & 0 deletions .docker/php725
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM php:7.2.5-alpine
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/fixtures/build/dir012/expected-output
/fixtures/check-requirements/*/actual-output
/fixtures/check-requirements/*/expected-output-*
!/fixtures/check-requirements/*/expected-output-*-dist
/fixtures/check-requirements/*/*.phar
/fixtures/php-settings-checker/*
!/fixtures/php-settings-checker/index.php
Expand Down
8 changes: 4 additions & 4 deletions .requirement-checker/src/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
final class Checker
{
private static $requirementsConfig;
public static function checkRequirements()
public static function checkRequirements() : bool
{
$requirements = self::retrieveRequirements();
$checkPassed = $requirements->evaluateRequirements();
$io = new IO();
self::printCheck($checkPassed, new Printer($io->getVerbosity(), $io->hasColorSupport()), $requirements);
return $checkPassed;
}
public static function printCheck($checkPassed, Printer $printer, RequirementCollection $requirements)
public static function printCheck($checkPassed, Printer $printer, RequirementCollection $requirements) : void
{
if (\false === $checkPassed && IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) {
$printer->setVerbosity(IO::VERBOSITY_VERY_VERBOSE);
Expand All @@ -36,7 +36,7 @@ public static function printCheck($checkPassed, Printer $printer, RequirementCol
} else {
$printer->printvln('> No requirements found.', $verbosity);
}
$errorMessages = array();
$errorMessages = [];
foreach ($requirements->getRequirements() as $requirement) {
if ($errorMessage = $printer->getRequirementErrorMessage($requirement)) {
if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
Expand Down Expand Up @@ -70,7 +70,7 @@ public static function printCheck($checkPassed, Printer $printer, RequirementCol
}
$printer->printvln('', $verbosity);
}
private static function retrieveRequirements()
private static function retrieveRequirements() : RequirementCollection
{
if (null === self::$requirementsConfig) {
self::$requirementsConfig = __DIR__ . '/../.requirements.php';
Expand Down
72 changes: 42 additions & 30 deletions .requirement-checker/src/IO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,75 @@

namespace HumbugBox3160\KevinGH\RequirementChecker;

use function fstat;
use function function_exists;
use function getenv;
use function implode;
use function posix_isatty;
use function preg_match;
use function preg_quote;
use function sapi_windows_vt100_support;
use function sprintf;
use function str_replace;
use function stream_isatty;
use const STDOUT;
final class IO
{
const VERBOSITY_QUIET = 16;
const VERBOSITY_NORMAL = 32;
const VERBOSITY_VERBOSE = 64;
const VERBOSITY_VERY_VERBOSE = 128;
const VERBOSITY_DEBUG = 256;
public const VERBOSITY_QUIET = 16;
public const VERBOSITY_NORMAL = 32;
public const VERBOSITY_VERBOSE = 64;
public const VERBOSITY_VERY_VERBOSE = 128;
public const VERBOSITY_DEBUG = 256;
private $interactive;
private $verbosity = self::VERBOSITY_NORMAL;
private $colorSupport;
private $options;
public function __construct()
{
$this->options = \implode(' ', $_SERVER['argv']);
$this->options = implode(' ', $_SERVER['argv']);
$shellVerbosity = $this->configureVerbosity();
$this->interactive = $this->checkInteractivity($shellVerbosity);
$this->colorSupport = $this->checkColorSupport();
}
public function isInteractive()
public function isInteractive() : bool
{
return $this->interactive;
}
public function getVerbosity()
public function getVerbosity() : int
{
return $this->verbosity;
}
public function hasColorSupport()
public function hasColorSupport() : bool
{
return $this->colorSupport;
}
public function hasParameter($values)
public function hasParameter($values) : bool
{
$values = (array) $values;
foreach ($values as $value) {
$regexp = \sprintf('/\\s%s\\b/', \str_replace(' ', '\\s+', \preg_quote($value, '/')));
if (1 === \preg_match($regexp, $this->options)) {
$regexp = sprintf('/\\s%s\\b/', str_replace(' ', '\\s+', preg_quote($value, '/')));
if (1 === preg_match($regexp, $this->options)) {
return \true;
}
}
return \false;
}
private function checkInteractivity($shellVerbosity)
private function checkInteractivity(int $shellVerbosity) : bool
{
if (-1 === $shellVerbosity) {
return \false;
}
if (\true === $this->hasParameter(array('--no-interaction', '-n'))) {
if (\true === $this->hasParameter(['--no-interaction', '-n'])) {
return \false;
}
if (\function_exists('posix_isatty') && !@\posix_isatty(\STDOUT) && \false === \getenv('SHELL_INTERACTIVE')) {
if (function_exists('posix_isatty') && !@posix_isatty(STDOUT) && \false === getenv('SHELL_INTERACTIVE')) {
return \false;
}
return \true;
}
private function configureVerbosity()
private function configureVerbosity() : int
{
switch ($shellVerbosity = (int) \getenv('SHELL_VERBOSITY')) {
switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {
case -1:
$this->verbosity = self::VERBOSITY_QUIET;
break;
Expand All @@ -75,39 +87,39 @@ private function configureVerbosity()
$shellVerbosity = 0;
break;
}
if ($this->hasParameter(array('--quiet', '-q'))) {
if ($this->hasParameter(['--quiet', '-q'])) {
$this->verbosity = self::VERBOSITY_QUIET;
$shellVerbosity = -1;
} elseif ($this->hasParameter(array('-vvv', '--verbose=3', '--verbose 3'))) {
} elseif ($this->hasParameter(['-vvv', '--verbose=3', '--verbose 3'])) {
$this->verbosity = self::VERBOSITY_DEBUG;
$shellVerbosity = 3;
} elseif ($this->hasParameter(array('-vv', '--verbose=2', '--verbose 2'))) {
} elseif ($this->hasParameter(['-vv', '--verbose=2', '--verbose 2'])) {
$this->verbosity = self::VERBOSITY_VERY_VERBOSE;
$shellVerbosity = 2;
} elseif ($this->hasParameter(array('-v', '--verbose=1', '--verbose 1', '--verbose'))) {
} elseif ($this->hasParameter(['-v', '--verbose=1', '--verbose 1', '--verbose'])) {
$this->verbosity = self::VERBOSITY_VERBOSE;
$shellVerbosity = 1;
}
return $shellVerbosity;
}
private function checkColorSupport()
private function checkColorSupport() : bool
{
if ($this->hasParameter(array('--ansi'))) {
if ($this->hasParameter(['--ansi'])) {
return \true;
}
if ($this->hasParameter(array('--no-ansi'))) {
if ($this->hasParameter(['--no-ansi'])) {
return \false;
}
if (\DIRECTORY_SEPARATOR === '\\') {
return \function_exists('sapi_windows_vt100_support') && \sapi_windows_vt100_support(\STDOUT) || \false !== \getenv('ANSICON') || 'ON' === \getenv('ConEmuANSI') || 'xterm' === \getenv('TERM');
return function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT) || \false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
}
if (\function_exists('stream_isatty')) {
return \stream_isatty(\STDOUT);
if (function_exists('stream_isatty')) {
return stream_isatty(STDOUT);
}
if (\function_exists('posix_isatty')) {
return \posix_isatty(\STDOUT);
if (function_exists('posix_isatty')) {
return posix_isatty(STDOUT);
}
$stat = \fstat(\STDOUT);
$stat = fstat(STDOUT);
return $stat ? 020000 === ($stat['mode'] & 0170000) : \false;
}
}
7 changes: 4 additions & 3 deletions .requirement-checker/src/IsExtensionFulfilled.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace HumbugBox3160\KevinGH\RequirementChecker;

use function extension_loaded;
final class IsExtensionFulfilled implements IsFulfilled
{
private $requiredExtension;
public function __construct($requiredExtension)
public function __construct(string $requiredExtension)
{
$this->requiredExtension = $requiredExtension;
}
public function __invoke()
public function __invoke() : bool
{
return \extension_loaded($this->requiredExtension);
return extension_loaded($this->requiredExtension);
}
}
2 changes: 1 addition & 1 deletion .requirement-checker/src/IsFulfilled.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface IsFulfilled
{
public function __invoke();
public function __invoke() : bool;
}
7 changes: 4 additions & 3 deletions .requirement-checker/src/IsPhpVersionFulfilled.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace HumbugBox3160\KevinGH\RequirementChecker;

use HumbugBox3160\Composer\Semver\Semver;
use function sprintf;
final class IsPhpVersionFulfilled implements IsFulfilled
{
private $requiredPhpVersion;
public function __construct($requiredPhpVersion)
public function __construct(string $requiredPhpVersion)
{
$this->requiredPhpVersion = $requiredPhpVersion;
}
public function __invoke()
public function __invoke() : bool
{
return Semver::satisfies(\sprintf('%d.%d.%d', \PHP_MAJOR_VERSION, \PHP_MINOR_VERSION, \PHP_RELEASE_VERSION), $this->requiredPhpVersion);
return Semver::satisfies(sprintf('%d.%d.%d', \PHP_MAJOR_VERSION, \PHP_MINOR_VERSION, \PHP_RELEASE_VERSION), $this->requiredPhpVersion);
}
}
63 changes: 37 additions & 26 deletions .requirement-checker/src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

namespace HumbugBox3160\KevinGH\RequirementChecker;

use function array_shift;
use function count;
use function explode;
use function ltrim;
use function min;
use function sprintf;
use function str_pad;
use function str_repeat;
use function strlen;
use function trim;
use function wordwrap;
use const PHP_EOL;
final class Printer
{
private $styles = array('reset' => "\x1b[0m", 'red' => "\x1b[31m", 'green' => "\x1b[32m", 'yellow' => "\x1b[33m", 'title' => "\x1b[33m", 'error' => "\x1b[37;41m", 'success' => "\x1b[30;42m");
private $styles = ['reset' => "\x1b[0m", 'red' => "\x1b[31m", 'green' => "\x1b[32m", 'yellow' => "\x1b[33m", 'title' => "\x1b[33m", 'error' => "\x1b[37;41m", 'success' => "\x1b[30;42m"];
private $verbosity;
private $supportColors;
private $width;
public function __construct($verbosity, $supportColors, $width = null)
public function __construct(int $verbosity, bool $supportColors, ?int $width = null)
{
if (null === $width) {
$terminal = new Terminal();
Expand All @@ -18,71 +30,70 @@ public function __construct($verbosity, $supportColors, $width = null)
$this->supportColors = $supportColors;
$this->width = $width ?: 80;
}
public function getVerbosity()
public function getVerbosity() : int
{
return $this->verbosity;
}
public function setVerbosity($verbosity)
public function setVerbosity($verbosity) : void
{
$this->verbosity = $verbosity;
}
public function title($title, $verbosity, $style = null)
public function title(string $title, int $verbosity, ?string $style = null) : void
{
if (null === $style) {
$style = 'title';
}
$this->printvln('', $verbosity, $style);
$this->printvln($title, $verbosity, $style);
$this->printvln(\str_repeat('=', \min(\strlen($title), $this->width)), $verbosity, $style);
$this->printvln(str_repeat('=', min(strlen($title), $this->width)), $verbosity, $style);
$this->printvln('', $verbosity, $style);
}
public function getRequirementErrorMessage(Requirement $requirement)
public function getRequirementErrorMessage(Requirement $requirement) : ?string
{
if ($requirement->isFulfilled()) {
return null;
}
$errorMessage = \wordwrap($requirement->getTestMessage(), $this->width - 3, \PHP_EOL . ' ') . \PHP_EOL;
return $errorMessage;
return wordwrap($requirement->getTestMessage(), $this->width - 3, PHP_EOL . ' ') . PHP_EOL;
}
public function block($title, $message, $verbosity, $style = null)
public function block(string $title, string $message, int $verbosity, ?string $style = null) : void
{
$prefix = ' [' . $title . '] ';
$lineLength = $this->width - \strlen($prefix) - 1;
$lineLength = $this->width - strlen($prefix) - 1;
if ($lineLength < 0) {
$lineLength = 0;
}
$message = $prefix . \trim($message);
$lines = array();
$message = $prefix . trim($message);
$lines = [];
$remainingMessage = $message;
$wrapped = \wordwrap($remainingMessage, $lineLength, '¬');
$wrapped = \explode('¬', $wrapped);
$wrapped = wordwrap($remainingMessage, $lineLength, '¬');
$wrapped = explode('¬', $wrapped);
do {
$line = \array_shift($wrapped);
$line = array_shift($wrapped);
if ($lines && $lineLength > 0) {
$line = \str_repeat(' ', \strlen($prefix)) . \ltrim($line);
$line = str_repeat(' ', strlen($prefix)) . ltrim($line);
}
$lines[] = \str_pad($line, $this->width, ' ', \STR_PAD_RIGHT);
} while (\count($wrapped));
$lines[] = str_pad($line, $this->width, ' ', \STR_PAD_RIGHT);
} while (count($wrapped));
$this->printvln('', $verbosity);
$this->printvln(\str_repeat(' ', $this->width), $verbosity, $style);
$this->printvln(str_repeat(' ', $this->width), $verbosity, $style);
foreach ($lines as $line) {
$this->printvln($line, $verbosity, $style);
}
$this->printv(\str_repeat(' ', $this->width), $verbosity, $style);
$this->printv(str_repeat(' ', $this->width), $verbosity, $style);
$this->printvln('', $verbosity);
}
public function printvln($message, $verbosity, $style = null)
public function printvln(string $message, int $verbosity, ?string $style = null) : void
{
$this->printv($message, $verbosity, $style);
$this->printv(\PHP_EOL, $verbosity, null);
$this->printv(PHP_EOL, $verbosity, null);
}
public function printv($message, $verbosity, $style = null)
public function printv(string $message, int $verbosity, ?string $style = null) : void
{
if ($verbosity > $this->verbosity) {
return;
}
$message = \wordwrap($message, $this->width);
$message = \sprintf('%s%s%s', $this->supportColors && isset($this->styles[$style]) ? $this->styles[$style] : '', $message, $this->supportColors ? $this->styles['reset'] : '');
$message = wordwrap($message, $this->width);
$message = sprintf('%s%s%s', $this->supportColors && isset($this->styles[$style]) ? $this->styles[$style] : '', $message, $this->supportColors ? $this->styles['reset'] : '');
echo $message;
}
}
Loading

0 comments on commit a6182b4

Please sign in to comment.