public static function normalizeDir($dirpath) { $dir = rtrim(\Jelix\FileUtilities\Path::normalizePath($dirpath), '/'); if ($dir == '') { return ''; } return $dir . '/'; }
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>'); } } } }
protected function execute(InputInterface $input, OutputInterface $output) { // retrieve the type of entry point we want to create $type = $input->getOption('type'); if (!in_array($type, array('classic', 'jsonrpc', 'xmlrpc', 'soap', 'cmdline'))) { throw new \Exception("invalid type"); } // retrieve the name of the entry point $name = $input->getArgument('entrypoint'); if (preg_match('/(.*)\\.php$/', $name, $m)) { $name = $m[1]; } // the full path of the entry point if ($type == 'cmdline') { $entryPointFullPath = App::scriptsPath($name . '.php'); $entryPointTemplate = 'scripts/cmdline.php.tpl'; } else { $entryPointFullPath = App::wwwPath($name . '.php'); $entryPointTemplate = 'www/' . ($type == 'classic' ? 'index' : $type) . '.php.tpl'; } if (file_exists($entryPointFullPath)) { throw new \Exception("the entry point already exists"); } $entryPointDir = dirname($entryPointFullPath) . '/'; $this->loadAppInfos(); // retrieve the config file name $configFile = $input->getArgument('config'); if ($configFile == null) { if ($type == 'cmdline') { $configFile = 'cmdline/' . $name . '.ini.php'; } else { $configFile = $name . '/config.ini.php'; } } // let's create the config file if needed $configFilePath = App::appConfigPath($configFile); if (!file_exists($configFilePath)) { $this->createDir(dirname($configFilePath)); // the file doesn't exists // if there is a -copy-config parameter, we copy this file $originalConfig = $input->getOption('copy-config'); if ($originalConfig) { if (!file_exists(App::appConfigPath($originalConfig))) { throw new \Exception("unknown original configuration file"); } file_put_contents($configFilePath, file_get_contents(App::appConfigPath($originalConfig))); if ($this->verbose()) { $output->writeln("Configuration file {$configFile} has been created from the config file {$originalConfig}."); } } else { // else we create a new config file $param = array(); $this->createFile($configFilePath, 'app/config/index/config.ini.php.tpl', $param, "Configuration file"); } } $inifile = new \Jelix\IniFile\MultiIniModifier(App::mainConfigFile(), $configFilePath); $urlsFile = App::appConfigPath($inifile->getValue('significantFile', 'urlengine')); $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true); $param = array(); // creation of the entry point $this->createDir($entryPointDir); $param['rp_app'] = Path::shortestPath($entryPointDir, App::appPath()); $param['config_file'] = $configFile; $this->createFile($entryPointFullPath, $entryPointTemplate, $param, "Entry point"); if ($type != 'cmdline') { $xmlEp = $xmlMap->addEntryPoint($name, $type); /*if ($type == 'classic') { $xmlEp->addUrlAction('/', $module, $action); }*/ $xmlMap->save(); } $this->appInfos->addEntryPointInfo($name . ".php", $configFile, $type); if ($this->verbose()) { $output->writeln($this->appInfos->getFile() . " has been updated."); } $installer = new \Jelix\Installer\Installer(new \Jelix\Installer\Reporter\Console('warning')); $installer->installEntryPoint($name . ".php"); if ($this->verbose()) { $output->writeln("All modules have been initialized for the new entry point."); } }
/** * normalize a path : translate '..', '.', replace '\' by '/' and so on.. * support windows path. * @param string $path * @return string the normalized path * @deprecated Use \Jelix\FileUtilities\Path::normalizePath() instead */ public static function normalizePath($path) { trigger_error("jFile::normalizePath is deprecated. Use \\Jelix\\FileUtilities\\Path::normalizePath() instead.", E_USER_DEPRECATED); return Path::normalizePath($path); }
protected function _createSkeleton($appPath, $appName, $wwwpath, InputInterface $input) { $this->createDir($appPath); $this->createDir(App::tempBasePath()); $this->createDir($wwwpath); $varPath = App::varPath(); $configPath = App::configPath(); $this->createDir($varPath); $this->createDir(App::logPath()); $this->createDir(App::appConfigPath()); $this->createDir($configPath); $this->createDir(App::appConfigPath('index/')); $this->createDir(App::appPath('app/overloads/')); $this->createDir(App::appPath('app/themes')); $this->createDir(App::appPath('app/themes/default/')); $this->createDir($varPath . 'uploads/'); $this->createDir($varPath . 'sessions/'); $this->createDir($varPath . 'mails/'); $this->createDir($appPath . 'install'); $this->createDir($appPath . 'modules'); $this->createDir($appPath . 'plugins'); $this->createDir(App::appPath('app/responses')); $this->createDir($appPath . 'tests'); $this->createDir(App::scriptsPath()); $param = array(); if ($input->getOption('nodefaultmodule')) { $param['tplname'] = 'jelix~defaultmain'; $param['modulename'] = 'jelix'; } else { $moduleName = $input->getOption('modulename'); if (!$moduleName) { // note: since module name are used for name of generated name, // only this characters are allowed $moduleName = preg_replace('/([^a-zA-Z_0-9])/', '_', $appName); } $param['modulename'] = $moduleName; $param['tplname'] = $moduleName . '~main'; } $param['config_file'] = 'index/config.ini.php'; $param['rp_temp'] = Path::shortestPath($appPath, App::tempBasePath()) . '/'; $param['rp_var'] = Path::shortestPath($appPath, App::varPath()) . '/'; $param['rp_log'] = Path::shortestPath($appPath, App::logPath()) . '/'; $param['rp_conf'] = Path::shortestPath($appPath, $configPath) . '/'; $param['rp_www'] = Path::shortestPath($appPath, $wwwpath) . '/'; $param['rp_cmd'] = Path::shortestPath($appPath, App::scriptsPath()) . '/'; $param['rp_jelix'] = Path::shortestPath($appPath, JELIX_LIB_PATH) . '/'; $param['rp_lib'] = Path::shortestPath($appPath, LIB_PATH) . '/'; $param['rp_vendor'] = ''; foreach (array(LIB_PATH . 'vendor/', LIB_PATH . '../vendor/', LIB_PATH . '../../../') as $path) { if (file_exists($path)) { $param['rp_vendor'] = Path::shortestPath($appPath, realpath($path) . '/') . '/'; break; } } $param['rp_app'] = Path::shortestPath($wwwpath, $appPath) . '/'; $this->createFile(App::logPath() . '.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'mails/.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'sessions/.dummy', 'dummy.tpl', array()); $this->createFile(App::appPath() . 'app/overloads/.dummy', 'dummy.tpl', array()); $this->createFile(App::appPath() . 'app/themes/default/.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'uploads/.dummy', 'dummy.tpl', array()); $this->createFile($appPath . 'plugins/.dummy', 'dummy.tpl', array()); $this->createFile(App::scriptsPath() . '.dummy', 'dummy.tpl', array()); $this->createFile(App::tempBasePath() . '.dummy', 'dummy.tpl', array()); $this->createFile($appPath . '.htaccess', 'htaccess_deny', $param, "Configuration file for Apache"); $this->createFile($appPath . '.gitignore', 'git_ignore.tpl', $param, ".gitignore"); $this->createFile($appPath . 'jelix-app.json', 'jelix-app.json.tpl', $param, "Project description file"); $this->createFile($appPath . 'composer.json', 'composer.json.tpl', $param, "Composer file"); $this->createFile($appPath . 'cmd.php', 'cmd.php.tpl', $param, "Script for developer commands"); $this->createFile(App::appConfigPath('mainconfig.ini.php'), 'app/config/mainconfig.ini.php.tpl', $param, "Main configuration file"); $this->createFile($configPath . 'localconfig.ini.php.dist', 'var/config/localconfig.ini.php.tpl', $param, "Configuration file for specific environment"); $this->createFile($configPath . 'profiles.ini.php', 'var/config/profiles.ini.php.tpl', $param, "Profiles file"); $this->createFile($configPath . 'profiles.ini.php.dist', 'var/config/profiles.ini.php.tpl', $param, "Profiles file for your repository"); $this->createFile($configPath . 'preferences.ini.php', 'var/config/preferences.ini.php.tpl', $param, "Preferences file"); $this->createFile(App::appConfigPath('urls.xml'), 'app/config/urls.xml.tpl', $param, "URLs mapping file"); $this->createFile(App::appConfigPath('index/config.ini.php'), 'app/config/index/config.ini.php.tpl', $param, "Entry point configuration file"); $this->createFile($appPath . 'app/responses/myHtmlResponse.class.php', 'app/responses/myHtmlResponse.class.php.tpl', $param, "Main response class"); $this->createFile($appPath . 'install/installer.php', 'installer/installer.php.tpl', $param, "Installer script"); $this->createFile($appPath . 'tests/runtests.php', 'tests/runtests.php', $param, "Tests script"); $temp = dirname(rtrim(App::tempBasePath(), '/')); if ($temp != rtrim($appPath, '/')) { if (file_exists($temp . '/.gitignore')) { $gitignore = file_get_contents($temp . '/.gitignore') . "\n" . $appName . "/*\n"; file_put_contents($temp . '/.gitignore', $gitignore); } else { file_put_contents($temp . '/.gitignore', $appName . "/*\n"); } } else { $gitignore = file_get_contents($appPath . '.gitignore') . "\n" . basename(rtrim(App::tempBasePath(), '/')) . "/*\n"; file_put_contents($appPath . '.gitignore', $gitignore); } $this->createFile($wwwpath . 'index.php', 'www/index.php.tpl', $param, "Main entry point"); $this->createFile($wwwpath . '.htaccess', 'htaccess_allow', $param, "Configuration file for Apache"); $param['php_rp_temp'] = $this->convertRp($param['rp_temp']); $param['php_rp_var'] = $this->convertRp($param['rp_var']); $param['php_rp_log'] = $this->convertRp($param['rp_log']); $param['php_rp_conf'] = $this->convertRp($param['rp_conf']); $param['php_rp_www'] = $this->convertRp($param['rp_www']); $param['php_rp_cmd'] = $this->convertRp($param['rp_cmd']); $param['php_rp_jelix'] = $this->convertRp($param['rp_jelix']); if ($param['rp_vendor']) { $param['php_rp_vendor'] = $this->convertRp($param['rp_vendor']); $this->createFile($appPath . 'application.init.php', 'application2.init.php.tpl', $param, "Bootstrap file"); } else { $this->createFile($appPath . 'application.init.php', 'application.init.php.tpl', $param, "Bootstrap file"); } return $param; }