| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\App\Requirements;
- /**
- * Description of Handler
- *
- * @autor ThurData <info@thrudata.ch>
- */
- class Checker
- {
- /**
- * \ThurData\Servers\KerioEmail\Core\FileReader\PathValidator
- * @var type null|\ThurData\Servers\KerioEmail\Core\FileReader\|\ThurData\Servers\KerioEmail\Core\FileReader\Directory
- */
- protected $directoryHandler = null;
-
- protected $requirementsList = [];
-
- protected $checkResaults = [];
-
- /**
- * Paths for Requirements class to be placed in
- * @var type array
- */
- const PATHS = [
- 'app' . DIRECTORY_SEPARATOR . 'Configuration' . DIRECTORY_SEPARATOR . 'Requirements',
- 'core' . DIRECTORY_SEPARATOR . 'Configuration' . DIRECTORY_SEPARATOR . 'Requirements'
- ];
-
- public function __construct()
- {
- $this->directoryHandler = new \ThurData\Servers\KerioEmail\Core\FileReader\Directory();
- $this->loadRequirements();
-
- $this->checkRequirements();
- }
-
- protected function loadRequirements()
- {
- foreach (self::PATHS as $path)
- {
- $this->loadClassesByPath($path);
- }
- }
-
- protected function loadClassesByPath($path)
- {
- $fullPath = \ThurData\Servers\KerioEmail\Core\ModuleConstants::getModuleRootDir() . DIRECTORY_SEPARATOR . $path;
- $files = $this->directoryHandler->getFilesList($fullPath, '.php', true);
- $classNamespace = $this->getClassNamespaceByPath($path);
- foreach ($files as $file)
- {
- $className = $classNamespace . $file;
- if (!class_exists($className) || !is_subclass_of($className, RequirementInterface::class))
- {
- continue;
- }
-
- $this->requirementsList[] = $className;
- }
- }
-
- protected function getClassNamespaceByPath($path)
- {
- $contextParts = explode('\\', self::class);
- $coreParts = explode(DIRECTORY_SEPARATOR, $path);
- $allParts = array_merge([$contextParts[0], $contextParts[1]], $coreParts);
- array_walk($allParts, function(&$item){
- $item = ucfirst($item);
- });
-
- return '\\' . implode('\\', $allParts) . '\\';
- }
-
- protected function checkRequirements()
- {
- foreach ($this->requirementsList as $requirement)
- {
- $instance = \ThurData\Servers\KerioEmail\Core\DependencyInjection\DependencyInjection::call($requirement);
- $handler = $instance->getHandlerInstance();
-
- $this->checkResaults = array_merge($this->checkResaults, $handler->getUnfulfilledRequirements());
- }
- }
-
- public function getUnfulfilledRequirements()
- {
- return $this->checkResaults;
- }
- }
|