Esempio n. 1
0
 protected function registerModulesDir($repository, $repositoryPath)
 {
     $allDirs = \Jelix\Core\App::getDeclaredModulesDir();
     $path = realpath($repositoryPath);
     if ($path == '') {
         throw new \Exception('The modules dir ' . $repository . ' is not a valid path');
     }
     $path = \Jelix\FileUtilities\Path::shortestPath(\Jelix\Core\App::appPath(), $path);
     $found = false;
     foreach ($allDirs as $dir) {
         $dir = \Jelix\FileUtilities\Path::shortestPath(\Jelix\Core\App::appPath(), $dir);
         if ($dir == $path) {
             $found = true;
             break;
         }
     }
     // the modules dir is not known, we should register it.
     if (!$found) {
         $this->createDir($repositoryPath);
         if (file_exists(\Jelix\Core\App::appPath('composer.json')) && file_exists(\Jelix\Core\App::appPath('vendor'))) {
             // we update composer.json
             $json = json_decode(file_get_contents(\Jelix\Core\App::appPath('composer.json')), true);
             if (!$json) {
                 throw new \Exception('composer.json has bad json format');
             }
             if (!isset($json['extra'])) {
                 $json['extra'] = array('jelix' => array('modules-dir' => array()));
             } elseif (!isset($json['extra']['jelix'])) {
                 $json['extra']['jelix'] = array('modules-dir' => array());
             } elseif (!isset($json['extra']['jelix']['modules-dir'])) {
                 $json['extra']['jelix']['modules-dir'] = array();
             }
             $json['extra']['jelix']['modules-dir'][] = $path;
             file_put_contents(\Jelix\Core\App::appPath('composer.json'), json_encode($json, JSON_PRETTY_PRINT));
             if ($this->verbose()) {
                 $this->output->writeln('<notice>The given modules dir has been added into your composer.json.</notice>');
             }
             $this->output->writeln('<notice>You should launch \'composer update\' to have your module repository recognized.</notice>');
         } elseif (file_exists(\Jelix\Core\App::appPath('application.init.php'))) {
             // we modify the application.init.php directly
             $content = file_get_contents(\Jelix\Core\App::appPath('application.init.php'));
             $content .= "\njApp::declareModulesDir(__DIR__.'/" . $path . "');\n";
             file_put_contents(\Jelix\Core\App::appPath('application.init.php'), $content);
             if ($this->verbose()) {
                 $this->output->writeln('<notice>The given modules dir has been added into your application.init.php.</notice>');
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Find all activated modules and check their status
  * @param object $config  the config object
  * @param boolean $allModuleInfo may be true for the installer, which needs all informations
  *                               else should be false, these extra informations are
  *                               not needed to run the application
  * @return \Jelix\Core\Infos\ModuleInfos[]
  */
 protected function _loadModulesInfo($config, $allModuleInfo)
 {
     $installerFile = App::configPath('installer.ini.php');
     if ($config->disableInstallers) {
         $installation = array();
     } else {
         if (file_exists($installerFile)) {
             $installation = parse_ini_file($installerFile, true);
         } else {
             if ($allModuleInfo) {
                 $installation = array();
             } else {
                 throw new Exception("The application is not installed -- installer.ini.php doesn't exist!\n", 9);
             }
         }
     }
     $section = $config->urlengine['urlScriptId'];
     if (!isset($installation[$section])) {
         $installation[$section] = array();
     }
     if ($config->compilation['checkCacheFiletime']) {
         $config->_allBasePath = App::getDeclaredModulesDir();
     } else {
         $config->_allBasePath = array();
     }
     $modules = array();
     $list = App::getAllModulesPath();
     foreach ($list as $k => $path) {
         $module = $this->_readModuleInfo($config, $allModuleInfo, $path, $installation, $section);
         if ($module !== null) {
             $modules[$module->name] = $module;
         }
     }
     return $modules;
 }
Esempio n. 3
0
 public static function getDeclaredModulesDir()
 {
     return \Jelix\Core\App::getDeclaredModulesDir();
 }