Skip to content

Commit

Permalink
Dump the requirement checker (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Nov 8, 2018
1 parent a70c5cc commit 4b4b069
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 525 deletions.
4 changes: 2 additions & 2 deletions .requirement-checker/bin/check-requirements.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace _HumbugBox9d880d18ae09\KevinGH\RequirementChecker;
namespace _HumbugBoxacafcfe30294\KevinGH\RequirementChecker;

require __DIR__ . '/../vendor/autoload.php';
if (\PHP_SAPI !== 'cli' && \PHP_SAPI !== 'phpdbg') {
echo \PHP_EOL . 'The application may only be invoked from a command line' . \PHP_EOL;
exit(1);
}
$checkPassed = \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\Checker::checkRequirements();
$checkPassed = \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\Checker::checkRequirements();
if (\false === $checkPassed) {
exit(1);
}
46 changes: 17 additions & 29 deletions .requirement-checker/src/Checker.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
<?php

namespace _HumbugBox9d880d18ae09\KevinGH\RequirementChecker;
namespace _HumbugBoxacafcfe30294\KevinGH\RequirementChecker;

/**
@private
@see
@license
@symfony
*/
final class Checker
{
/**
@var */
private static $requirementsConfig;
/**
@return
*/
public static function checkRequirements()
{
$requirements = self::retrieveRequirements();
$checkPassed = $requirements->evaluateRequirements();
$io = new \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO();
self::printCheck($checkPassed, new \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\Printer($io->getVerbosity(), $io->hasColorSupport()), $requirements);
$io = new \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO();
self::printCheck($checkPassed, new \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\Printer($io->getVerbosity(), $io->hasColorSupport()), $requirements);
return $checkPassed;
}
public static function printCheck($checkPassed, \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\Printer $printer, \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\RequirementCollection $requirements)
public static function printCheck($checkPassed, \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\Printer $printer, \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\RequirementCollection $requirements)
{
if (\false === $checkPassed && \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) {
$printer->setVerbosity(\_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE);
if (\false === $checkPassed && \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) {
$printer->setVerbosity(\_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE);
}
$verbosity = \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE;
$verbosity = \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE;
$iniPath = $requirements->getPhpIniPath();
$printer->title('Box Requirements Checker', $verbosity);
$printer->printv('> Using PHP ', $verbosity);
Expand All @@ -49,24 +42,24 @@ public static function printCheck($checkPassed, \_HumbugBox9d880d18ae09\KevinGH\
$errorMessages = array();
foreach ($requirements->getRequirements() as $requirement) {
if ($errorMessage = $printer->getRequirementErrorMessage($requirement)) {
if (\_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getTestMessage(), \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'red');
$printer->printv(' ', \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG);
if (\_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getTestMessage(), \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'red');
$printer->printv(' ', \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG);
$errorMessages[] = $errorMessage;
} else {
$printer->printv('E', $verbosity, 'red');
$errorMessages[] = $errorMessage;
}
continue;
}
if (\_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getHelpText(), \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'green');
$printer->printv(' ', \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG);
if (\_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getHelpText(), \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'green');
$printer->printv(' ', \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG);
} else {
$printer->printv('.', $verbosity, 'green');
}
}
if (\_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG !== $printer->getVerbosity() && \count($requirements) > 0) {
if (\_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG !== $printer->getVerbosity() && \count($requirements) > 0) {
$printer->printvln('', $verbosity);
}
if ($requirements->evaluateRequirements()) {
Expand All @@ -80,20 +73,15 @@ public static function printCheck($checkPassed, \_HumbugBox9d880d18ae09\KevinGH\
}
$printer->printvln('', $verbosity);
}
/**
@return
*/
private static function retrieveRequirements()
{
if (null === self::$requirementsConfig) {
self::$requirementsConfig = __DIR__ . '/../.requirements.php';
}
/**
@var */
$config = (require self::$requirementsConfig);
$requirements = new \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\RequirementCollection();
$requirements = new \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\RequirementCollection();
foreach ($config as $constraint) {
$requirements->addRequirement('php' === $constraint['type'] ? new \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IsPhpVersionFulfilled($constraint['condition']) : new \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IsExtensionFulfilled($constraint['condition']), $constraint['message'], $constraint['helpMessage']);
$requirements->addRequirement('php' === $constraint['type'] ? new \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IsPhpVersionFulfilled($constraint['condition']) : new \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IsExtensionFulfilled($constraint['condition']), $constraint['message'], $constraint['helpMessage']);
}
return $requirements;
}
Expand Down
30 changes: 2 additions & 28 deletions .requirement-checker/src/IO.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?php

namespace _HumbugBox9d880d18ae09\KevinGH\RequirementChecker;
namespace _HumbugBoxacafcfe30294\KevinGH\RequirementChecker;

/**
@private
*/
final class IO
{
const VERBOSITY_QUIET = 16;
Expand All @@ -23,32 +20,18 @@ public function __construct()
$this->interactive = $this->checkInteractivity($shellVerbosity);
$this->colorSupport = $this->checkColorSupport();
}
/**
@return
*/
public function isInteractive()
{
return $this->interactive;
}
/**
@return
*/
public function getVerbosity()
{
return $this->verbosity;
}
/**
@return
*/
public function hasColorSupport()
{
return $this->colorSupport;
}
/**
@param
@param
@return
*/
public function hasParameter($values)
{
$values = (array) $values;
Expand All @@ -60,10 +43,6 @@ public function hasParameter($values)
}
return \false;
}
/**
@param
@return
*/
private function checkInteractivity($shellVerbosity)
{
if (-1 === $shellVerbosity) {
Expand All @@ -79,9 +58,6 @@ private function checkInteractivity($shellVerbosity)
}
return \true;
}
/**
@return
*/
private function configureVerbosity()
{
switch ($shellVerbosity = (int) \getenv('SHELL_VERBOSITY')) {
Expand Down Expand Up @@ -119,9 +95,7 @@ private function configureVerbosity()
return $shellVerbosity;
}
/**
@return
@see
@license
@symfony
*/
private function checkColorSupport()
{
Expand Down
10 changes: 2 additions & 8 deletions .requirement-checker/src/IsExtensionFulfilled.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<?php

namespace _HumbugBox9d880d18ae09\KevinGH\RequirementChecker;
namespace _HumbugBoxacafcfe30294\KevinGH\RequirementChecker;

/**
@private
*/
final class IsExtensionFulfilled implements \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IsFulfilled
final class IsExtensionFulfilled implements \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IsFulfilled
{
private $requiredExtension;
/**
@param
*/
public function __construct($requiredExtension)
{
$this->requiredExtension = $requiredExtension;
Expand Down
8 changes: 1 addition & 7 deletions .requirement-checker/src/IsFulfilled.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<?php

namespace _HumbugBox9d880d18ae09\KevinGH\RequirementChecker;
namespace _HumbugBoxacafcfe30294\KevinGH\RequirementChecker;

/**
@private
*/
interface IsFulfilled
{
/**
@return
*/
public function __invoke();
}
14 changes: 4 additions & 10 deletions .requirement-checker/src/IsPhpVersionFulfilled.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
<?php

namespace _HumbugBox9d880d18ae09\KevinGH\RequirementChecker;
namespace _HumbugBoxacafcfe30294\KevinGH\RequirementChecker;

use _HumbugBox9d880d18ae09\Composer\Semver\Semver;
/**
@private
*/
final class IsPhpVersionFulfilled implements \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\IsFulfilled
use _HumbugBoxacafcfe30294\Composer\Semver\Semver;
final class IsPhpVersionFulfilled implements \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\IsFulfilled
{
private $requiredPhpVersion;
/**
@param
*/
public function __construct($requiredPhpVersion)
{
$this->requiredPhpVersion = $requiredPhpVersion;
}
public function __invoke()
{
return \_HumbugBox9d880d18ae09\Composer\Semver\Semver::satisfies(\sprintf('%d.%d.%d', \PHP_MAJOR_VERSION, \PHP_MINOR_VERSION, \PHP_RELEASE_VERSION), $this->requiredPhpVersion);
return \_HumbugBoxacafcfe30294\Composer\Semver\Semver::satisfies(\sprintf('%d.%d.%d', \PHP_MAJOR_VERSION, \PHP_MINOR_VERSION, \PHP_RELEASE_VERSION), $this->requiredPhpVersion);
}
}
45 changes: 3 additions & 42 deletions .requirement-checker/src/Printer.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,31 @@
<?php

namespace _HumbugBox9d880d18ae09\KevinGH\RequirementChecker;
namespace _HumbugBoxacafcfe30294\KevinGH\RequirementChecker;

/**
@private
*/
final class Printer
{
private $styles = array('reset' => "\33[0m", 'red' => "\33[31m", 'green' => "\33[32m", 'yellow' => "\33[33m", 'title' => "\33[33m", 'error' => "\33[37;41m", 'success' => "\33[30;42m");
private $verbosity;
private $supportColors;
private $width;
/**
@param
@param
@param
*/
public function __construct($verbosity, $supportColors, $width = null)
{
if (null === $width) {
$terminal = new \_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\Terminal();
$terminal = new \_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\Terminal();
$width = \min($terminal->getWidth(), 80);
}
$this->verbosity = $verbosity;
$this->supportColors = $supportColors;
$this->width = $width;
}
/**
@return
*/
public function getVerbosity()
{
return $this->verbosity;
}
/**
@param
*/
public function setVerbosity($verbosity)
{
$this->verbosity = $verbosity;
}
/**
@param
@param
@param
*/
public function title($title, $verbosity, $style = null)
{
if (null === $style) {
Expand All @@ -55,24 +36,14 @@ public function title($title, $verbosity, $style = null)
$this->printvln(\str_repeat('=', \min(\strlen($title), $this->width)), $verbosity, $style);
$this->printvln('', $verbosity, $style);
}
/**
@param
@return
*/
public function getRequirementErrorMessage(\_HumbugBox9d880d18ae09\KevinGH\RequirementChecker\Requirement $requirement)
public function getRequirementErrorMessage(\_HumbugBoxacafcfe30294\KevinGH\RequirementChecker\Requirement $requirement)
{
if ($requirement->isFulfilled()) {
return null;
}
$errorMessage = \wordwrap($requirement->getTestMessage(), $this->width - 3, \PHP_EOL . ' ') . \PHP_EOL;
return $errorMessage;
}
/**
@param
@param
@param
@param
*/
public function block($title, $message, $verbosity, $style = null)
{
$prefix = ' [' . $title . '] ';
Expand All @@ -97,21 +68,11 @@ public function block($title, $message, $verbosity, $style = null)
$this->printv(\str_repeat(' ', $this->width), $verbosity, $style);
$this->printvln('', $verbosity);
}
/**
@param
@param
@param
*/
public function printvln($message, $verbosity, $style = null)
{
$this->printv($message, $verbosity, $style);
$this->printv(\PHP_EOL, $verbosity, null);
}
/**
@param
@param
@param
*/
public function printv($message, $verbosity, $style = null)
{
if ($verbosity > $this->verbosity) {
Expand Down
Loading

0 comments on commit 4b4b069

Please sign in to comment.