public function run() { if (file_exists(JELIX_APP_PATH)) { throw new Exception("this application is already created"); } $this->createDir(JELIX_APP_PATH); if ($p = $this->getOption('-wwwpath')) { $wwwpath = path::real(JELIX_APP_PATH . $p, false) . '/'; } else { $wwwpath = JELIX_APP_WWW_PATH; } $this->createDir(JELIX_APP_REAL_TEMP_PATH); $this->createDir(JELIX_APP_CLI_TEMP_PATH); $this->createDir(JELIX_APP_TEMP_PATH); $this->createDir($wwwpath); $this->createDir(JELIX_APP_VAR_PATH); $this->createDir(JELIX_APP_LOG_PATH); $this->createDir(JELIX_APP_CONFIG_PATH); $this->createDir(JELIX_APP_CONFIG_PATH . 'index/'); $this->createDir(JELIX_APP_VAR_PATH . 'overloads/'); $this->createDir(JELIX_APP_VAR_PATH . 'themes/'); $this->createDir(JELIX_APP_VAR_PATH . 'themes/default/'); $this->createDir(JELIX_APP_VAR_PATH . 'uploads/'); $this->createDir(JELIX_APP_VAR_PATH . 'sessions/'); $this->createDir(JELIX_APP_PATH . 'modules'); $this->createDir(JELIX_APP_PATH . 'plugins'); $this->createDir(JELIX_APP_PATH . 'plugins/coord/'); $this->createDir(JELIX_APP_PATH . 'plugins/tpl/'); $this->createDir(JELIX_APP_PATH . 'plugins/tpl/common'); $this->createDir(JELIX_APP_PATH . 'plugins/tpl/html'); $this->createDir(JELIX_APP_PATH . 'plugins/tpl/text'); $this->createDir(JELIX_APP_PATH . 'plugins/db/'); $this->createDir(JELIX_APP_PATH . 'plugins/auth/'); $this->createDir(JELIX_APP_PATH . 'responses'); $this->createDir(JELIX_APP_PATH . 'scripts'); $param = array(); $param['default_id'] = $GLOBALS['APPNAME'] . JELIXS_INFO_DEFAULT_IDSUFFIX; if ($this->getOption('-nodefaultmodule')) { $param['tplname'] = 'jelix~defaultmain'; $param['modulename'] = 'jelix'; } else { // note: since module name are used for name of generated name, // only this characters are allowed $param['modulename'] = preg_replace('/([^a-zA-Z_0-9])/', '_', $GLOBALS['APPNAME']); $param['tplname'] = $param['modulename'] . '~main'; } $param['config_file'] = 'index/config.ini.php'; $param['rp_temp'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_REAL_TEMP_PATH, true); $param['rp_var'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_VAR_PATH, true); $param['rp_log'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_LOG_PATH, true); $param['rp_conf'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_CONFIG_PATH, true); $param['rp_www'] = jxs_getRelativePath(JELIX_APP_PATH, $wwwpath, true); $param['rp_cmd'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_CMD_PATH, true); $param['rp_jelix'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_LIB_PATH, true); $param['rp_app'] = jxs_getRelativePath($wwwpath, JELIX_APP_PATH, true); $this->createFile(JELIX_APP_PATH . '.htaccess', 'htaccess_deny', $param); $this->createFile(JELIX_APP_PATH . 'project.xml', 'project.xml.tpl', $param); $this->createFile(JELIX_APP_CONFIG_PATH . 'defaultconfig.ini.php', 'var/config/defaultconfig.ini.php.tpl', $param); $this->createFile(JELIX_APP_CONFIG_PATH . 'dbprofils.ini.php', 'var/config/dbprofils.ini.php.tpl', $param); $this->createFile(JELIX_APP_CONFIG_PATH . 'index/config.ini.php', 'var/config/index/config.ini.php.tpl', $param); $this->createFile(JELIX_APP_PATH . 'responses/myHtmlResponse.class.php', 'myHtmlResponse.class.php.tpl', $param); $this->createFile($wwwpath . 'index.php', 'www/index.php.tpl', $param); $this->createFile($wwwpath . '.htaccess', 'htaccess_allow', $param); $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']); $this->createFile(JELIX_APP_PATH . 'application.init.php', 'application.init.php.tpl', $param); $param['rp_temp_app'] = $param['rp_temp']; $param['php_rp_temp_app'] = $param['php_rp_temp']; $param['rp_temp'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_TEMP_PATH, true); $param['rp_temp_cli'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_CLI_TEMP_PATH, true); $param['php_rp_temp'] = $this->convertRp($param['rp_temp']); $param['php_rp_temp_cli'] = $this->convertRp($param['rp_temp_cli']); $this->createFile(JELIX_APP_PATH . 'jelix-scripts.init.php', 'jelix-scripts.init.php.tpl', $param); $param['rp_temp'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_CLI_TEMP_PATH, true); $param['php_rp_temp'] = $this->convertRp($param['rp_temp']); $this->createFile(JELIX_APP_PATH . 'application-cli.init.php', 'application.init.php.tpl', $param); $moduleok = true; if (!$this->getOption('-nodefaultmodule')) { try { $cmd = jxs_load_command('createmodule'); $cmd->init(array('-addinstallzone' => true), array('module' => $param['modulename'])); $cmd->run(); $this->createFile(JELIX_APP_PATH . 'modules/' . $param['modulename'] . '/templates/main.tpl', 'main.tpl.tpl', $param); } catch (Exception $e) { $moduleok = false; echo "The module has not been created because of this error: " . $e->getMessage() . "\nHowever the application has been created\n"; } } if ($this->getOption('-withcmdline')) { if (!$this->getOption('-nodefaultmodule') && $moduleok) { $agcommand = jxs_load_command('createctrl'); $options = array('-cmdline' => true); $agcommand->init($options, array('module' => $GLOBALS['APPNAME'], 'name' => 'default', 'method' => 'index')); $agcommand->run(); } $agcommand = jxs_load_command('createentrypoint'); $options = array('-type' => 'cmdline'); $parameters = array('name' => $GLOBALS['APPNAME']); $agcommand->init($options, $parameters); $agcommand->run(); } }
public function run() { jxs_init_jelix_env(); $type = $this->getOption('-type'); if (!$type) { $type = 'classic'; } if (!in_array($type, array('classic', 'jsonrpc', 'xmlrpc', 'rdf', 'soap', 'cmdline'))) { throw new Exception("invalid type"); } if ($type == 'classic') { $type = 'index'; } $name = $this->getParam('name'); $inifile = new jIniMultiFilesModifier(JELIX_APP_CONFIG_PATH . 'defaultconfig.ini.php', JELIX_APP_CONFIG_PATH . 'index/config.ini.php'); $param = array(); $param['modulename'] = $inifile->getValue('startModule'); if ($type == 'cmdline') { if (file_exists(JELIX_APP_CMD_PATH . $name . '.php')) { throw new Exception("the entry point already exists"); } if (!file_exists(JELIX_APP_PATH . 'application-cli.init.php')) { $this->createDir(substr(JELIX_APP_TEMP_PATH, -1) . '-cli'); $param2['rp_temp'] = jxs_getRelativePath(JELIX_APP_PATH, substr(JELIX_APP_TEMP_PATH, 0, -1) . '-cli', true); $param2['rp_var'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_VAR_PATH, true); $param2['rp_log'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_LOG_PATH, true); $param2['rp_conf'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_CONFIG_PATH, true); $param2['rp_www'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_WWW_PATH, true); $param2['rp_cmd'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_APP_CMD_PATH, true); $param2['rp_jelix'] = jxs_getRelativePath(JELIX_APP_PATH, JELIX_LIB_PATH, true); $param2['rp_app'] = jxs_getRelativePath(JELIX_APP_WWW_PATH, JELIX_APP_PATH, true); $param2['php_rp_temp'] = $this->convertRp($param2['rp_temp']); $param2['php_rp_var'] = $this->convertRp($param2['rp_var']); $param2['php_rp_log'] = $this->convertRp($param2['rp_log']); $param2['php_rp_conf'] = $this->convertRp($param2['rp_conf']); $param2['php_rp_www'] = $this->convertRp($param2['rp_www']); $param2['php_rp_cmd'] = $this->convertRp($param2['rp_cmd']); $this->createFile(JELIX_APP_PATH . 'application-cli.init.php', 'application.init.php.tpl', $param2); } $this->createDir(JELIX_APP_CONFIG_PATH . 'cmdline'); $this->createDir(JELIX_APP_CMD_PATH); $this->createFile(JELIX_APP_CONFIG_PATH . 'cmdline/' . $name . '.ini.php', 'var/config/cmdline/config.ini.php.tpl', $param); $param['rp_cmd'] = jxs_getRelativePath(JELIX_APP_CMD_PATH, JELIX_APP_PATH, true); $param['config_file'] = 'cmdline/' . $name . '.ini.php'; $this->createFile(JELIX_APP_CMD_PATH . $name . '.php', 'scripts/cmdline.php.tpl', $param); return; } if (file_exists(JELIX_APP_WWW_PATH . $name . '.php')) { throw new Exception("the entry point already exists"); } $param['rp_app'] = jxs_getRelativePath(JELIX_APP_WWW_PATH, JELIX_APP_PATH, true); $param['config_file'] = $name . '/config.ini.php'; $this->createDir(JELIX_APP_CONFIG_PATH . $name); $this->createFile(JELIX_APP_CONFIG_PATH . $name . '/config.ini.php', 'var/config/index/config.ini.php.tpl', $param); $this->createFile(JELIX_APP_WWW_PATH . $name . '.php', 'www/' . $type . '.php.tpl', $param); $inifile = new jIniFileModifier(JELIX_APP_CONFIG_PATH . 'defaultconfig.ini.php'); if (null === $inifile->getValue($name, 'simple_urlengine_entrypoints')) { $inifile->setValue($name, '', 'simple_urlengine_entrypoints'); } if (null === $inifile->getValue($name, 'basic_significant_urlengine_entrypoints')) { $inifile->setValue($name, '1', 'basic_significant_urlengine_entrypoints'); } $doc = new DOMDocument(); if (!$doc->load(JELIX_APP_PATH . 'project.xml')) { throw new Exception("cannot load project.xml"); } if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'project/1.0') { throw new Exception("bad namespace in project.xml"); } $elem = $doc->createElementNS(JELIX_NAMESPACE_BASE . 'project/1.0', 'entry'); $elem->setAttribute("file", $name . ".php"); $elem->setAttribute("config", $name . "/config.ini.php"); $ep = $doc->documentElement->getElementsByTagName("entrypoints"); if (!$ep->length) { $ep = $doc->createElementNS(JELIX_NAMESPACE_BASE . 'project/1.0', 'entrypoints'); $doc->documentElement->appendChild($ep); $ep->appendChild($elem); } else { $ep->item(0)->appendChild($elem); } $doc->save(JELIX_APP_PATH . 'project.xml'); }