Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix compilation of projects using dev composer plugins #879

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Next Next commit
WIP
  • Loading branch information
theofidry committed Feb 13, 2023
commit d47945b57f9ebdcd93bdb0de9597d53f305247cf
11 changes: 11 additions & 0 deletions Box54346/.box/.requirements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return array (
0 =>
array (
'type' => 'php',
'condition' => '^8.1',
'message' => 'The application requires a version matching "^8.1".',
'helpMessage' => 'The application requires a version matching "^8.1".',
),
);
24 changes: 24 additions & 0 deletions Box54346/.box/bin/check-requirements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace HumbugBox420\KevinGH\RequirementChecker;

if (isset($_SERVER['BOX_REQUIREMENT_CHECKER'])) {
$enableRequirementChecker = $_SERVER['BOX_REQUIREMENT_CHECKER'];
if (\is_bool($enableRequirementChecker) && !$enableRequirementChecker) {
return;
}
if (\is_string($enableRequirementChecker) && \in_array(\strtolower($enableRequirementChecker), ['false', '0'], \true)) {
return;
}
if (!\is_bool($enableRequirementChecker) && !\is_string($enableRequirementChecker)) {
echo \PHP_EOL . 'Unhandled value type for "BOX_REQUIREMENT_CHECKER". Got "' . \gettype($enableRequirementChecker) . '". Proceeding with the requirement checks.' . \PHP_EOL;
}
}
if (\false === \in_array(\PHP_SAPI, array('cli', 'phpdbg', 'embed', 'micro'), \true)) {
echo \PHP_EOL . 'The application may only be invoked from a command line, got "' . \PHP_SAPI . '"' . \PHP_EOL;
exit(1);
}
require __DIR__ . '/../vendor/autoload.php';
if (!Checker::checkRequirements()) {
exit(1);
}
102 changes: 102 additions & 0 deletions Box54346/.box/src/Checker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare (strict_types=1);
namespace HumbugBox420\KevinGH\RequirementChecker;

use InvalidArgumentException;
use function count;
use function sprintf;
final class Checker
{
private static $requirementsConfig;
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) : void
{
if (\false === $checkPassed && IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) {
$printer->setVerbosity(IO::VERBOSITY_VERY_VERBOSE);
}
$verbosity = IO::VERBOSITY_VERY_VERBOSE;
$iniPath = $requirements->getPhpIniPath();
$printer->title('Box Requirements Checker', $verbosity);
$printer->printv('> Using PHP ', $verbosity);
$printer->printvln(\PHP_VERSION, $verbosity, 'green');
$printer->printvln('> PHP is using the following php.ini file:', $verbosity);
if ($iniPath) {
$printer->printvln(' ' . $iniPath, $verbosity, 'green');
} else {
$printer->printvln(' WARNING: No configuration file (php.ini) used by PHP!', $verbosity, 'yellow');
}
$printer->printvln('', $verbosity);
if (count($requirements) > 0) {
$printer->printvln('> Checking Box requirements:', $verbosity);
$printer->printv(' ', $verbosity);
} else {
$printer->printvln('> No requirements found.', $verbosity);
}
$errorMessages = [];
foreach ($requirements->getRequirements() as $requirement) {
if ($errorMessage = $printer->getRequirementErrorMessage($requirement)) {
if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('✘ ' . $requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'red');
$printer->printv(' ', IO::VERBOSITY_DEBUG);
$errorMessages[] = $errorMessage;
} else {
$printer->printv('E', $verbosity, 'red');
$errorMessages[] = $errorMessage;
}
continue;
}
if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('✔ ' . $requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'green');
$printer->printv(' ', IO::VERBOSITY_DEBUG);
} else {
$printer->printv('.', $verbosity, 'green');
}
}
if (IO::VERBOSITY_DEBUG !== $printer->getVerbosity() && count($requirements) > 0) {
$printer->printvln('', $verbosity);
}
if ($requirements->evaluateRequirements()) {
$printer->block('OK', 'Your system is ready to run the application.', $verbosity, 'success');
} else {
$printer->block('ERROR', 'Your system is not ready to run the application.', $verbosity, 'error');
$printer->title('Fix the following mandatory requirements:', $verbosity, 'red');
foreach ($errorMessages as $errorMessage) {
$printer->printv(' * ' . $errorMessage, $verbosity);
}
}
$printer->printvln('', $verbosity);
}
private static function retrieveRequirements() : RequirementCollection
{
if (null === self::$requirementsConfig) {
self::$requirementsConfig = __DIR__ . '/../.requirements.php';
}
$config = (require self::$requirementsConfig);
$requirements = new RequirementCollection();
foreach ($config as $constraint) {
$requirements->addRequirement(self::createCondition($constraint['type'], $constraint['condition']), $constraint['message'], $constraint['helpMessage']);
}
return $requirements;
}
private static function createCondition($type, $condition) : IsFulfilled
{
switch ($type) {
case 'php':
return new IsPhpVersionFulfilled($condition);
case 'extension':
return new IsExtensionFulfilled($condition);
case 'extension-conflict':
return new IsExtensionConflictFulfilled($condition);
default:
throw new InvalidArgumentException(sprintf('Unknown requirement type "%s".', $type));
}
}
}
127 changes: 127 additions & 0 deletions Box54346/.box/src/IO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

declare (strict_types=1);
namespace HumbugBox420\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 DIRECTORY_SEPARATOR;
use const STDOUT;
final class IO
{
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']);
$shellVerbosity = $this->configureVerbosity();
$this->interactive = $this->checkInteractivity($shellVerbosity);
$this->colorSupport = $this->checkColorSupport();
}
public function isInteractive() : bool
{
return $this->interactive;
}
public function getVerbosity() : int
{
return $this->verbosity;
}
public function hasColorSupport() : bool
{
return $this->colorSupport;
}
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)) {
return \true;
}
}
return \false;
}
private function checkInteractivity(int $shellVerbosity) : bool
{
if (-1 === $shellVerbosity) {
return \false;
}
if (\true === $this->hasParameter(['--no-interaction', '-n'])) {
return \false;
}
if (function_exists('posix_isatty') && !@posix_isatty(STDOUT) && \false === getenv('SHELL_INTERACTIVE')) {
return \false;
}
return \true;
}
private function configureVerbosity() : int
{
switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {
case -1:
$this->verbosity = self::VERBOSITY_QUIET;
break;
case 1:
$this->verbosity = self::VERBOSITY_VERBOSE;
break;
case 2:
$this->verbosity = self::VERBOSITY_VERY_VERBOSE;
break;
case 3:
$this->verbosity = self::VERBOSITY_DEBUG;
break;
default:
$shellVerbosity = 0;
break;
}
if ($this->hasParameter(['--quiet', '-q'])) {
$this->verbosity = self::VERBOSITY_QUIET;
$shellVerbosity = -1;
} elseif ($this->hasParameter(['-vvv', '--verbose=3', '--verbose 3'])) {
$this->verbosity = self::VERBOSITY_DEBUG;
$shellVerbosity = 3;
} elseif ($this->hasParameter(['-vv', '--verbose=2', '--verbose 2'])) {
$this->verbosity = self::VERBOSITY_VERY_VERBOSE;
$shellVerbosity = 2;
} elseif ($this->hasParameter(['-v', '--verbose=1', '--verbose 1', '--verbose'])) {
$this->verbosity = self::VERBOSITY_VERBOSE;
$shellVerbosity = 1;
}
return $shellVerbosity;
}
private function checkColorSupport() : bool
{
if ($this->hasParameter(['--ansi'])) {
return \true;
}
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');
}
if (function_exists('stream_isatty')) {
return stream_isatty(STDOUT);
}
if (function_exists('posix_isatty')) {
return posix_isatty(STDOUT);
}
$stat = fstat(STDOUT);
return $stat ? 020000 === ($stat['mode'] & 0170000) : \false;
}
}
18 changes: 18 additions & 0 deletions Box54346/.box/src/IsExtensionConflictFulfilled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare (strict_types=1);
namespace HumbugBox420\KevinGH\RequirementChecker;

use function extension_loaded;
final class IsExtensionConflictFulfilled implements IsFulfilled
{
private $conflictingExtension;
public function __construct(string $requiredExtension)
{
$this->conflictingExtension = $requiredExtension;
}
public function __invoke() : bool
{
return !extension_loaded($this->conflictingExtension);
}
}
18 changes: 18 additions & 0 deletions Box54346/.box/src/IsExtensionFulfilled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare (strict_types=1);
namespace HumbugBox420\KevinGH\RequirementChecker;

use function extension_loaded;
final class IsExtensionFulfilled implements IsFulfilled
{
private $requiredExtension;
public function __construct(string $requiredExtension)
{
$this->requiredExtension = $requiredExtension;
}
public function __invoke() : bool
{
return extension_loaded($this->requiredExtension);
}
}
9 changes: 9 additions & 0 deletions Box54346/.box/src/IsFulfilled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare (strict_types=1);
namespace HumbugBox420\KevinGH\RequirementChecker;

interface IsFulfilled
{
public function __invoke() : bool;
}
22 changes: 22 additions & 0 deletions Box54346/.box/src/IsPhpVersionFulfilled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare (strict_types=1);
namespace HumbugBox420\KevinGH\RequirementChecker;

use HumbugBox420\Composer\Semver\Semver;
use function sprintf;
use const PHP_MAJOR_VERSION;
use const PHP_MINOR_VERSION;
use const PHP_RELEASE_VERSION;
final class IsPhpVersionFulfilled implements IsFulfilled
{
private $requiredPhpVersion;
public function __construct(string $requiredPhpVersion)
{
$this->requiredPhpVersion = $requiredPhpVersion;
}
public function __invoke() : bool
{
return Semver::satisfies(sprintf('%d.%d.%d', PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION), $this->requiredPhpVersion);
}
}
Loading