-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The JSON files should be decode with `assoc` set to true. Otherwise encoding it again may change the schema as if `assoc` is set to false, both `[]` and `{}` will be decoded as an empty array so encoding it again may change an empty object into an empty array which may screw up a JSON schema validation.
- Loading branch information
Showing
6 changed files
with
110 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the humbug/php-scoper package. | ||
* | ||
* Copyright (c) 2017 Théo FIDRY <[email protected]>, | ||
* Pádraic Brady <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Humbug\PhpScoper\Autoload; | ||
|
||
use Symfony\Requirements\RequirementCollection; | ||
|
||
/** | ||
* Collect the list of requirements for running the project. Code in this file must be PHP 5.3+ compatible as is used | ||
* to know if PHP-Scoper can be run or not. | ||
*/ | ||
final class Requirements extends RequirementCollection | ||
{ | ||
public function __construct($composerJson) | ||
{ | ||
$composerConfig = $this->readComposer($composerJson); | ||
|
||
$this->addPhpVersionRequirement($composerConfig); | ||
$this->addExtensionRequirements($composerConfig); | ||
} | ||
|
||
private function readComposer($composerJson) | ||
{ | ||
$composer = json_decode(file_get_contents($composerJson), true); | ||
|
||
return $composer['require']; | ||
} | ||
|
||
private function addPhpVersionRequirement(array $composerConfig) | ||
{ | ||
$installedPhpVersion = phpversion(); | ||
$requiredPhpVersion = $composerConfig['php']; | ||
|
||
$this->addRequirement( | ||
version_compare(phpversion(), $requiredPhpVersion, '>='), | ||
sprintf( | ||
'PHP version must satisfy "%s" ("%s" installed)', | ||
$requiredPhpVersion, | ||
$installedPhpVersion | ||
), | ||
'' | ||
); | ||
} | ||
|
||
private function addExtensionRequirements(array $composerConfig) | ||
{ | ||
foreach ($composerConfig as $package => $constraint) { | ||
if (preg_match('/^ext-(?<extension>.+)$/', $package, $matches)) { | ||
$this->addExtensionRequirement($matches['extension']); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param string $extension Extension name, e.g. `iconv`. | ||
*/ | ||
private function addExtensionRequirement($extension) | ||
{ | ||
$this->addRequirement( | ||
extension_loaded($extension), | ||
sprintf( | ||
'The extension "%s" must be enabled.', | ||
$extension | ||
), | ||
'' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters