Exemple #1
0
 protected function getBaseDirectory()
 {
     if (empty($this->entityData['baseDirectory'])) {
         $this->entityData['baseDirectory'] = loader::getLoader()->findFile($this->entityData['module']);
     }
     return $this->entityData['baseDirectory'];
 }
Exemple #2
0
            $gitCommit = trim(file_get_contents($gitFile));
        }
        $cacheKey = "{$gitCommit}.loader";
        if (!($paths = cache::getCached($cacheKey))) {
            $paths = ['modules' => [APP_ROOT . '/system/modules', CORE_ROOT . '/system/modules'], 'system' => []];
            $appsDir = APP_ROOT . '/apps';
            if (file_exists($appsDir)) {
                foreach (scandir($appsDir) as $appName) {
                    if ($appName[0] === '.') {
                        continue;
                    }
                    $currentModulesDir = "{$appsDir}/{$appName}/modules";
                    if (file_exists($currentModulesDir)) {
                        $paths['modules'][] = $currentModulesDir;
                    }
                    $currentModulesSystemDir = "{$appsDir}/{$appName}/system";
                    if (file_exists($currentModulesSystemDir)) {
                        $paths['system'][] = $currentModulesSystemDir;
                    }
                }
            }
            cache::setCached($cacheKey, $paths);
        }
        $loader->addPsr4('mpcmf\\modules\\', $paths['modules'], false);
        $loader->register(false);
        $loader->addPsr4('mpcmf\\system\\', $paths['system'], true);
        $loader->addPsr4('mpcmf\\', [APP_ROOT, CORE_ROOT], true);
    }
}
loader::load();
 /**
  * @return array
  */
 protected function getBundlesModulesDirs()
 {
     $searchModulesDir = [];
     foreach (loader::getLoader()->getPrefixesPsr4() as $psr4Prefix => $psr4Dir) {
         if (strpos($psr4Prefix, APP_NAME . '\\modules') !== 0) {
             continue;
         }
         foreach ($psr4Dir as $dir) {
             if (!file_exists($dir)) {
                 continue;
             }
             foreach (scandir($dir) as $moduleDir) {
                 if ($moduleDir[0] === '.') {
                     continue;
                 }
                 $searchModulesDir[] = $moduleDir;
             }
         }
     }
     return $searchModulesDir;
 }
Exemple #4
0
 /**
  * Get application directory
  *
  * @return string
  * @throws moduleException
  */
 public function getModuleDirectory()
 {
     static $directory;
     if ($directory === null) {
         $calledClass = get_called_class();
         $file = loader::getLoader()->findFile($calledClass);
         if (!$file) {
             throw new moduleException("File for class {$calledClass} not found!");
         }
         $directory = dirname($file);
     }
     return $directory;
 }
Exemple #5
0
 protected static function getModuleBasePath($packageName)
 {
     static $cached = [];
     if (!array_key_exists($packageName, $cached)) {
         $className = self::getClassName($packageName);
         $filePath = loader::getLoader()->findFile($className);
         $modulePath = null;
         $currentPath = dirname($filePath);
         while (($parentPath = dirname($currentPath)) !== $currentPath) {
             $currentPath = $parentPath;
             if (in_array('composer.json', scandir($currentPath), true)) {
                 $modulePath = $currentPath;
                 break;
             }
         }
         $cached[$packageName] = null;
         if ($modulePath !== null) {
             $pathPattern = '%s' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'config.d';
             $cached[$packageName] = sprintf($pathPattern, $modulePath);
         }
     }
     return $cached[$packageName];
 }
 /**
  * Get module instance for current entity
  *
  * @return moduleBase
  * @throws modulePartsHelperException
  */
 public function getModule()
 {
     if (!isset($this->moduleInstance)) {
         $entityUniqName = $this->getEntityUniqueName();
         if (!isset(modulePartsStorage::$moduleInstances[$entityUniqName])) {
             /** @var moduleBase $class */
             $class = "{$this->getModuleNamespace()}\\module";
             $file = loader::getLoader()->findFile($class);
             if (!$file) {
                 self::log()->addCritical("File for class {$class} not found!", [__METHOD__]);
                 throw new modulePartsHelperException("File for class {$class} not found!");
             }
             modulePartsStorage::$moduleInstances[$entityUniqName] = $class::getInstance();
         }
         $this->moduleInstance = modulePartsStorage::$moduleInstances[$entityUniqName];
     }
     return $this->moduleInstance;
 }