2021-05-08 21:09:48 +00:00
|
|
|
<?php
|
2021-05-08 22:50:26 +00:00
|
|
|
|
2021-05-08 21:09:48 +00:00
|
|
|
declare(strict_types=1);
|
2021-05-08 22:50:26 +00:00
|
|
|
|
2021-05-08 21:09:48 +00:00
|
|
|
namespace Fbrinker\ExtensionCheck\Extension;
|
|
|
|
|
|
|
|
use ReflectionExtension;
|
|
|
|
|
2021-05-08 22:50:26 +00:00
|
|
|
class ExtensionDetails
|
|
|
|
{
|
2021-05-08 21:09:48 +00:00
|
|
|
private $loadedExtensions;
|
2021-05-08 22:50:26 +00:00
|
|
|
|
|
|
|
/** @var ExtensionMap|null */
|
|
|
|
private $extensionMap;
|
2021-05-08 21:09:48 +00:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->loadedExtensions = array_map('strtolower', get_loaded_extensions());
|
2022-05-25 10:10:23 +00:00
|
|
|
natcasesort($this->loadedExtensions);
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:50:26 +00:00
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getLoadedExtensions(): array
|
|
|
|
{
|
2021-05-08 21:09:48 +00:00
|
|
|
return $this->loadedExtensions;
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:50:26 +00:00
|
|
|
public function getLoadedExtensionsCount(): int
|
|
|
|
{
|
2022-05-25 10:10:23 +00:00
|
|
|
return count($this->getLoadedExtensions());
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:50:26 +00:00
|
|
|
/**
|
2021-05-08 23:57:02 +00:00
|
|
|
* @param string[] $excludedExtensions
|
2021-05-08 22:50:26 +00:00
|
|
|
*/
|
2021-05-08 23:57:02 +00:00
|
|
|
public function getExtensionMap(array $excludedExtensions): ExtensionMap
|
2021-05-08 22:50:26 +00:00
|
|
|
{
|
2021-05-08 23:57:02 +00:00
|
|
|
if ($this->extensionMap === null) {
|
|
|
|
$this->extensionMap = $this->buildExtensionMaps($excludedExtensions);
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-08 23:57:02 +00:00
|
|
|
return $this->extensionMap;
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 10:10:23 +00:00
|
|
|
public function getExtensionInfo(string $extensionInfo): ExtensionInfo
|
|
|
|
{
|
|
|
|
return new ExtensionInfo($extensionInfo);
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:50:26 +00:00
|
|
|
/**
|
2021-05-08 23:57:02 +00:00
|
|
|
* @param string[] $excludedExtensions
|
2021-05-08 22:50:26 +00:00
|
|
|
*/
|
2021-05-08 23:57:02 +00:00
|
|
|
private function buildExtensionMaps(array $excludedExtensions): ExtensionMap
|
2021-05-08 22:50:26 +00:00
|
|
|
{
|
2021-05-08 21:09:48 +00:00
|
|
|
$extensionClasses = $extensionFunctions = $extensionConstants = $extensionDependencies = $uncheckedExtensions = [];
|
2022-05-25 10:10:23 +00:00
|
|
|
|
|
|
|
$loadedExtensions = $this->getLoadedExtensions();
|
|
|
|
foreach ($loadedExtensions as $loadedExtension) {
|
2021-05-08 23:57:02 +00:00
|
|
|
if (in_array($loadedExtension, $excludedExtensions, true)) {
|
2021-05-08 21:09:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-05-25 10:10:23 +00:00
|
|
|
$extensionInfo = $this->getExtensionInfo($loadedExtension);
|
2021-05-08 21:09:48 +00:00
|
|
|
|
2022-05-25 10:10:23 +00:00
|
|
|
$classes = $extensionInfo->getClasses();
|
2021-05-08 21:09:48 +00:00
|
|
|
if (!empty($classes)) {
|
2022-05-25 10:10:23 +00:00
|
|
|
$extensionClasses = array_merge($extensionClasses, array_map(function () use ($loadedExtension) {
|
|
|
|
return $loadedExtension;
|
|
|
|
}, array_flip($classes)));
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 10:10:23 +00:00
|
|
|
$functions = $extensionInfo->getFunctions();
|
2021-05-08 21:09:48 +00:00
|
|
|
if (!empty($functions)) {
|
2022-05-25 10:10:23 +00:00
|
|
|
$extensionFunctions = array_merge($extensionFunctions, array_map(function () use ($loadedExtension) {
|
|
|
|
return $loadedExtension;
|
|
|
|
}, array_flip($functions)));
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 10:10:23 +00:00
|
|
|
$constants = $extensionInfo->getConstants();
|
2021-05-08 21:09:48 +00:00
|
|
|
if (!empty($constants)) {
|
2022-05-25 10:10:23 +00:00
|
|
|
$extensionConstants = array_merge($extensionConstants, array_map(function () use ($loadedExtension) {
|
|
|
|
return $loadedExtension;
|
|
|
|
}, array_flip($constants)));
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 10:10:23 +00:00
|
|
|
/*$dependencies = $extensionInfo->getRequiredDependencies();
|
2021-05-08 21:09:48 +00:00
|
|
|
if (!empty($dependencies)) {
|
|
|
|
natcasesort($dependencies);
|
|
|
|
foreach ($dependencies as $dependency => $status) {
|
2021-05-08 23:57:02 +00:00
|
|
|
if (in_array($dependency, $excludedExtensions, true)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-08 21:09:48 +00:00
|
|
|
if (!isset($extensionDependencies[$loadedExtension][strtolower($status)])) {
|
|
|
|
$extensionDependencies[$loadedExtension][strtolower($status)] = [];
|
|
|
|
}
|
2021-05-08 23:57:02 +00:00
|
|
|
|
2021-05-08 21:09:48 +00:00
|
|
|
$extensionDependencies[$loadedExtension][strtolower($status)][] = $dependency;
|
|
|
|
}
|
2022-05-25 10:10:23 +00:00
|
|
|
}*/
|
2021-05-08 21:09:48 +00:00
|
|
|
|
2022-05-25 10:10:23 +00:00
|
|
|
if (empty($classes) && empty($functions) && empty($constants) && empty($dependencies)) {
|
|
|
|
$uncheckedExtensions[] = $loadedExtension;
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 23:57:02 +00:00
|
|
|
return new ExtensionMap(
|
2021-05-08 22:50:26 +00:00
|
|
|
$extensionClasses,
|
|
|
|
$extensionFunctions,
|
|
|
|
$extensionConstants,
|
|
|
|
$extensionDependencies,
|
|
|
|
$uncheckedExtensions
|
|
|
|
);
|
2021-05-08 21:09:48 +00:00
|
|
|
}
|
2021-05-08 22:50:26 +00:00
|
|
|
}
|