public function run() { // retrieve the type of entry point we want to create $type = $this->getOption('-type'); if (!$type) { $type = 'classic'; } else { if (!in_array($type, array('classic', 'jsonrpc', 'xmlrpc', 'rdf', 'soap', 'cmdline'))) { throw new Exception("invalid type"); } } // retrieve the name of the entry point $name = $this->getParam('name'); if (preg_match('/(.*)\\.php$/', $name, $m)) { $name = $m[1]; } // the full path of the entry point if ($type == 'cmdline') { $entryPointFullPath = jApp::scriptsPath($name . '.php'); $entryPointTemplate = 'scripts/cmdline.php.tpl'; } else { $entryPointFullPath = jApp::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->loadProjectXml(); // retrieve the config file name $configFile = $this->getParam('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 = jApp::configPath($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 = $this->getOption('-copy-config'); if ($originalConfig) { if (!file_exists(jApp::configPath($originalConfig))) { throw new Exception("unknown original configuration file"); } file_put_contents($configFilePath, file_get_contents(jApp::configPath($originalConfig))); } else { // else we create a new config file, with the startmodule of the default // config as a module name. $defaultConfig = parse_ini_file(jApp::configPath('defaultconfig.ini.php'), true); $param = array(); if (isset($defaultConfig['startModule'])) { $param['modulename'] = $defaultConfig['startModule']; } else { $param['modulename'] = 'jelix'; } $this->createFile($configFilePath, 'var/config/index/config.ini.php.tpl', $param); } } require_once JELIX_LIB_PATH . 'utils/jIniMultiFilesModifier.class.php'; $inifile = new jIniMultiFilesModifier(jApp::configPath('defaultconfig.ini.php'), $configFilePath); $param = array(); $param['modulename'] = $inifile->getValue('startModule'); // creation of the entry point $this->createDir($entryPointDir); $param['rp_app'] = $this->getRelativePath($entryPointDir, jApp::appPath()); $param['config_file'] = $configFile; $this->createFile($entryPointFullPath, $entryPointTemplate, $param); if ($type != 'cmdline') { if (null === $inifile->getValue($name, 'simple_urlengine_entrypoints', null, true)) { $inifile->setValue($name, '', 'simple_urlengine_entrypoints', null, true); } if (null === $inifile->getValue($name, 'basic_significant_urlengine_entrypoints', null, true)) { $inifile->setValue($name, '1', 'basic_significant_urlengine_entrypoints', null, true); } $inifile->save(); } $this->updateProjectXml($name . ".php", $configFile, $type); require_once JELIX_LIB_PATH . 'installer/jInstaller.class.php'; $installer = new jInstaller(new textInstallReporter('warning')); $installer->installEntryPoint($name . ".php"); }