/** * load and read the configuration of the application * The combination of all configuration files (the given file * and the mainconfig.ini.php) is stored * in a single temporary file. So it calls the jConfigCompiler * class if needed * @param string $configFile the config file name * @return object it contains all configuration options * @see jConfigCompiler */ public static function load($configFile) { $config = array(); $file = jApp::tempPath() . str_replace('/', '~', $configFile); if (BYTECODE_CACHE_EXISTS) { $file .= '.conf.php'; } else { $file .= '.resultini.php'; } self::$fromCache = true; if (!file_exists($file)) { // no cache, let's compile self::$fromCache = false; } else { $t = filemtime($file); $dc = jApp::mainConfigFile(); $lc = jApp::configPath('localconfig.ini.php'); if (file_exists($dc) && filemtime($dc) > $t || filemtime(jApp::configPath($configFile)) > $t || file_exists($lc) && filemtime($lc) > $t) { // one of the config files have been modified: let's compile self::$fromCache = false; } else { // let's read the cache file if (BYTECODE_CACHE_EXISTS) { include $file; $config = (object) $config; } else { $config = jelix_read_ini($file); } // we check all directories to see if it has been modified if ($config->compilation['checkCacheFiletime']) { foreach ($config->_allBasePath as $path) { if (!file_exists($path) || filemtime($path) > $t) { self::$fromCache = false; break; } } } } } if (!self::$fromCache) { require_once JELIX_LIB_CORE_PATH . 'jConfigCompiler.class.php'; return jConfigCompiler::readAndCache($configFile); } else { return $config; } }
function getDocumentRoot() { if (isset($_SERVER['DOCUMENT_ROOT'])) { return $_SERVER['DOCUMENT_ROOT']; } require_once JELIX_LIB_PATH . "core/jConfigCompiler.class.php"; $config = parse_ini_file(jApp::mainConfigFile()); $urlengine = $config['urlengine']; if ($urlengine['scriptNameServerVariable'] == '') { $urlengine['scriptNameServerVariable'] = jConfigCompiler::findServerName('.php'); } $urlScript = $_SERVER[$urlengine['scriptNameServerVariable']]; $lastslash = strrpos($urlScript, '/'); $urlScriptPath = substr($urlScript, 0, $lastslash) . '/'; $basepath = $urlengine['basePath']; if ($basepath == '') { // for beginners or simple site, we "guess" the base path $basepath = $urlScriptPath; } elseif ($basepath != '/') { if ($basepath[0] != '/') { $basepath = '/' . $basepath; } if (substr($basepath, -1) != '/') { $basepath .= '/'; } if (strpos($urlScriptPath, $basepath) !== 0) { throw new Exception('Jelix Error: basePath (' . $basepath . ') in config file doesn\'t correspond to current base path. You should setup it to ' . $urlengine['urlScriptPath']); } } if ($basepath == '/') { return jApp::wwwPath(); } if (strpos(jApp::wwwPath(), $basepath) === false) { return jApp::wwwPath(); } return substr(jApp::wwwPath(), 0, -strlen($basepath)); }
/** * read the given ini file, for the current entry point, or for the entrypoint given * in $pseudoScriptName. Merge it with the content of mainconfig.ini.php * It also calculates some options. * If you are in a CLI script but you want to load a configuration file for a web entry point * or vice-versa, you need to indicate the $pseudoScriptName parameter with the name of the entry point * @param string $configFile the config file name * @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 * @param boolean $isCli indicate if the configuration to read is for a CLI script or no * @param string $pseudoScriptName the name of the entry point, relative to the base path, * corresponding to the readed configuration * @return object an object which contains configuration values */ public static function read($configFile, $allModuleInfo = false, $isCli = false, $pseudoScriptName = '') { $tempPath = jApp::tempBasePath(); $configPath = jApp::configPath(); if ($tempPath == '/') { // if it equals to '/', this is because realpath has returned false in the application.init.php // so this is because the path doesn't exist. throw new Exception('Application temp directory doesn\'t exist !', 3); } if (!is_writable($tempPath)) { throw new Exception('Application temp base directory is not writable -- (' . $tempPath . ')', 4); } if (!is_writable(jApp::logPath())) { throw new Exception('Application log directory is not writable -- (' . jApp::logPath() . ')', 4); } // this is the defaultconfig file of JELIX itself $config = jelix_read_ini(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); self::$commonConfig = clone $config; // read the main configuration of the app @jelix_read_ini(jApp::mainConfigFile(), $config); // read the local configuration of the app if (file_exists($configPath . 'localconfig.ini.php')) { @jelix_read_ini($configPath . 'localconfig.ini.php', $config); } // read the configuration specific to the entry point if ($configFile != 'mainconfig.ini.php' && $configFile != 'defaultconfig.ini.php') { if (!file_exists($configPath . $configFile)) { throw new Exception("Configuration file is missing -- {$configFile}", 5); } if (false === @jelix_read_ini($configPath . $configFile, $config)) { throw new Exception("Syntax error in the configuration file -- {$configFile}", 6); } } self::prepareConfig($config, $allModuleInfo, $isCli, $pseudoScriptName); self::$commonConfig = null; return $config; }
public function getEntryPointsList() { if ($this->entryPointList !== null) { return $this->entryPointList; } $listEps = $this->projectXml->documentElement->getElementsByTagName("entrypoints"); if (!$listEps->length) { $this->entryPointList = array(); return $this->entryPointList; } $listEp = $listEps->item(0)->getElementsByTagName("entry"); if (!$listEp->length) { $this->entryPointList = array(); return $this->entryPointList; } $mainConfig = new jIniFileModifier(jApp::mainConfigFile()); $this->entryPointList = array(); for ($i = 0; $i < $listEp->length; $i++) { $epElt = $listEp->item($i); $ep = new jInstallerEntryPoint($mainConfig, $epElt->getAttribute("config"), $epElt->getAttribute("file"), $epElt->getAttribute("type")); $this->entryPointList[] = $ep; } return $this->entryPointList; }
function checkAppPaths() { $ok = true; if (!defined('JELIX_LIB_PATH') || !jApp::isInit()) { throw new Exception($this->messages->get('path.core')); } if (!file_exists(jApp::tempBasePath()) || !is_writable(jApp::tempBasePath())) { $this->error('path.temp'); $ok = false; } if (!file_exists(jApp::logPath()) || !is_writable(jApp::logPath())) { $this->error('path.log'); $ok = false; } if (!file_exists(jApp::varPath())) { $this->error('path.var'); $ok = false; } if (!file_exists(jApp::configPath())) { $this->error('path.config'); $ok = false; } elseif ($this->checkForInstallation) { if (!is_writable(jApp::configPath())) { $this->error('path.config.writable'); $ok = false; } if (file_exists(jApp::configPath('profiles.ini.php')) && !is_writable(jApp::configPath('profiles.ini.php'))) { $this->error('path.profiles.writable'); $ok = false; } if (file_exists(jApp::mainConfigFile()) && !is_writable(jApp::mainConfigFile())) { $this->error('path.mainconfig.writable'); $ok = false; } elseif (file_exists(jApp::configPath('defaultconfig.ini.php')) && !is_writable(jApp::configPath('defaultconfig.ini.php'))) { $this->error('path.mainconfig.writable'); $ok = false; } if (file_exists(jApp::configPath('installer.ini.php')) && !is_writable(jApp::configPath('installer.ini.php'))) { $this->error('path.installer.writable'); $ok = false; } } if (!file_exists(jApp::wwwPath())) { $this->error('path.www'); $ok = false; } foreach ($this->otherPaths as $path) { $realPath = jFile::parseJelixPath($path); if (!file_exists($realPath)) { $this->error('path.custom.not.exists', array($path)); $ok = false; } else { if (!is_writable($realPath)) { $this->error('path.custom.writable', array($path)); $ok = false; } else { $this->ok('path.custom.ok', array($path)); } } } if ($ok) { $this->ok('paths.ok'); } else { throw new Exception($this->messages->get('too.critical.error')); } /*if(!isset($GLOBALS['config_file']) || empty($GLOBALS['config_file']) || !file_exists(jApp::configPath($GLOBALS['config_file']))){ throw new Exception($this->messages->get('config.file')); }*/ return $ok; }
public function run() { $this->loadAppConfig(); $module = $this->getParam('module'); $initialVersion = $this->getOption('-ver'); if ($initialVersion === false) { $initialVersion = '0.1pre'; } // note: since module name are used for name of generated name, // only this characters are allowed if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) { throw new Exception("'" . $module . "' is not a valid name for a module"); } // check if the module already exist or not $path = ''; try { $path = $this->getModulePath($module); } catch (Exception $e) { } if ($path != '') { throw new Exception("module '" . $module . "' already exists"); } // verify the given repository $repository = $this->getParam('repository', 'app:modules/'); if (substr($repository, -1) != '/') { $repository .= '/'; } $repositoryPath = jFile::parseJelixPath($repository); $iniDefault = new jIniFileModifier(jApp::mainConfigFile()); $this->updateModulePath($iniDefault, $iniDefault->getValue('modulesPath'), $repository, $repositoryPath); if ($this->verbose()) { echo "modulePath updated in the main configuration\n"; } if (!$this->allEntryPoint) { $list = $this->getEntryPointsList(); foreach ($list as $k => $entryPoint) { if ($entryPoint['file'] == $this->entryPointName) { $ini = new jIniFileModifier(jApp::configPath($entryPoint['config'])); break; } } if (!$ini) { throw new Exception("entry point is unknown"); } $this->updateModulePath($ini, jApp::config()->modulesPath, $repository, $repositoryPath); if ($this->verbose()) { echo "modulePath updated in the configuration " . $entryPoint['config'] . "\n"; } } $path = $repositoryPath . $module . '/'; $this->createDir($path); jApp::setConfig(null); if ($this->getOption('-admin')) { $this->removeOption('-nosubdir'); $this->removeOption('-addinstallzone'); } $param = array(); $param['module'] = $module; $param['default_id'] = $module . $this->config->infoIDSuffix; $param['version'] = $initialVersion; $this->createFile($path . 'module.xml', 'module/module.xml.tpl', $param); // create all sub directories of a module if (!$this->getOption('-nosubdir')) { $this->createDir($path . 'classes/'); $this->createDir($path . 'zones/'); $this->createDir($path . 'controllers/'); $this->createDir($path . 'templates/'); $this->createDir($path . 'classes/'); $this->createDir($path . 'daos/'); $this->createDir($path . 'forms/'); $this->createDir($path . 'locales/'); $this->createDir($path . 'locales/en_US/'); $this->createDir($path . 'locales/fr_FR/'); $this->createDir($path . 'install/'); if ($this->verbose()) { echo "Sub directories have been created in the new module {$module}.\n"; } $this->createFile($path . 'install/install.php', 'module/install.tpl', $param); $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array()); } $isdefault = $this->getOption('-defaultmodule'); // activate the module in the application if ($isdefault) { $iniDefault->setValue('startModule', $module); $iniDefault->setValue('startAction', 'default:index'); if ($this->verbose()) { echo "The new module {$module} becomes the default module\n"; } } $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules'); $iniDefault->save(); $list = $this->getEntryPointsList(); $install = new jIniFileModifier(jApp::configPath('installer.ini.php')); // install the module for all needed entry points foreach ($list as $k => $entryPoint) { $configFile = jApp::configPath($entryPoint['config']); $epconfig = new jIniFileModifier($configFile); if ($this->allEntryPoint) { $access = 2; } else { $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0; } $epconfig->setValue($module . '.access', $access, 'modules'); $epconfig->save(); if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) { $install->setValue($module . '.installed', 1, $entryPoint['id']); $install->setValue($module . '.version', $initialVersion, $entryPoint['id']); } if ($isdefault) { // we set the module as default module for one or all entry points. // we set the startModule option for all entry points except // if an entry point is indicated on the command line if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) { if ($epconfig->getValue('startModule') != '') { $epconfig->setValue('startModule', $module); $epconfig->setValue('startAction', 'default:index'); $epconfig->save(); } } } if ($this->verbose()) { echo "The module is initialized for the entry point " . $entryPoint['file'] . ".\n"; } } $install->save(); // create a default controller if (!$this->getOption('-nocontroller')) { $agcommand = JelixScript::getCommand('createctrl', $this->config); $options = $this->getCommonActiveOption(); if ($this->getOption('-cmdline')) { $options['-cmdline'] = true; } if ($this->getOption('-addinstallzone')) { $options['-addinstallzone'] = true; } $agcommand->initOptParam($options, array('module' => $module, 'name' => 'default', 'method' => 'index')); $agcommand->run(); } if ($this->getOption('-admin')) { $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener"); $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param); file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module); file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module); } }
public function run() { $this->loadAppConfig(); $entrypoint = $this->getParam('entrypoint'); if (($p = strpos($entrypoint, '.php')) !== false) { $entrypoint = substr($entrypoint, 0, $p); } $ep = $this->getEntryPointInfo($entrypoint); if ($ep == null) { try { $cmd = JelixScript::getCommand('createentrypoint', $this->config); $cmd->initOptParam(array(), array('name' => $entrypoint)); $cmd->run(); $this->projectXml = null; $ep = $this->getEntryPointInfo($entrypoint); } catch (Exception $e) { throw new Exception("The entrypoint has not been created because of this error: " . $e->getMessage() . ". No other files have been created.\n"); } } $installConfig = new jIniFileModifier(jApp::configPath('installer.ini.php')); $inifile = new jIniMultiFilesModifier(jApp::mainConfigFile(), jApp::configPath($ep['config'])); $params = array(); $this->createFile(jApp::appPath('responses/adminHtmlResponse.class.php'), 'responses/adminHtmlResponse.class.php.tpl', $params, "Response for admin interface"); $this->createFile(jApp::appPath('responses/adminLoginHtmlResponse.class.php'), 'responses/adminLoginHtmlResponse.class.php.tpl', $params, "Response for login page"); $inifile->setValue('html', 'adminHtmlResponse', 'responses'); $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses'); $inifile->setValue('startModule', 'master_admin'); $inifile->setValue('startAction', 'default:index'); $modulePath = $inifile->getValue("modulesPath", 0, null, true); if (strpos($modulePath, 'lib:jelix-admin-modules') === false) { // we set it on mainconfig.ini.php, so if the url engine is "significant" // it could know the admin modules during the parsing of modules $inifile->setValue('modulesPath', 'lib:jelix-admin-modules/,' . $modulePath, 0, null, true); } $installConfig->setValue('jacl.installed', '0', $entrypoint); $inifile->setValue('jacl.access', '0', 'modules'); $installConfig->setValue('jacldb.installed', '0', $entrypoint); $inifile->setValue('jacldb.access', '0', 'modules'); $installConfig->setValue('junittests.installed', '0', $entrypoint); $inifile->setValue('junittests.access', '0', 'modules'); $installConfig->setValue('jsoap.installed', '0', $entrypoint); $inifile->setValue('jsoap.access', '0', 'modules'); $urlconf = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints', null, true); if ($urlconf === null || $urlconf == '') { // in defaultconfig $inifile->setValue($entrypoint, 'jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic, jpref_admin~*@classic', 'simple_urlengine_entrypoints', null, true); // in the config of the entry point $inifile->setValue($entrypoint, 'jacl2db~*@classic, jauth~*@classic, jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic, jpref_admin~*@classic', 'simple_urlengine_entrypoints'); } else { $urlconf2 = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints'); if (strpos($urlconf, 'jacl2db_admin~*@classic') === false) { $urlconf .= ',jacl2db_admin~*@classic'; } if (strpos($urlconf, 'jauthdb_admin~*@classic') === false) { $urlconf .= ',jauthdb_admin~*@classic'; } if (strpos($urlconf, 'master_admin~*@classic') === false) { $urlconf .= ',master_admin~*@classic'; } if (strpos($urlconf2, 'jacl2db_admin~*@classic') === false) { $urlconf2 .= ',jacl2db_admin~*@classic'; } if (strpos($urlconf2, 'jauthdb_admin~*@classic') === false) { $urlconf2 .= ',jauthdb_admin~*@classic'; } if (strpos($urlconf2, 'master_admin~*@classic') === false) { $urlconf2 .= ',master_admin~*@classic'; } if (strpos($urlconf2, 'jacl2db~*@classic') === false) { $urlconf2 .= ',jacl2db~*@classic'; } if (strpos($urlconf2, 'jauth~*@classic') === false) { $urlconf2 .= ',jauth~*@classic'; } if (strpos($urlconf2, 'jpref_admin~*@classic') === false) { $urlconf2 .= ',jpref_admin~*@classic'; } $inifile->setValue($entrypoint, $urlconf, 'simple_urlengine_entrypoints', null, true); $inifile->setValue($entrypoint, $urlconf2, 'simple_urlengine_entrypoints'); } if (null == $inifile->getValue($entrypoint, 'basic_significant_urlengine_entrypoints', null, true)) { $inifile->setValue($entrypoint, '1', 'basic_significant_urlengine_entrypoints', null, true); } $inifile->save(); require_once JELIX_LIB_PATH . 'installer/jInstaller.class.php'; $verbose = $this->verbose(); $reporter = new textInstallReporter($verbose ? 'notice' : 'warning'); $installer = new jInstaller($reporter); $installer->installModules(array('master_admin'), $entrypoint . '.php'); $authini = new jIniFileModifier(jApp::configPath($entrypoint . '/auth.coord.ini.php')); $authini->setValue('after_login', 'master_admin~default:index'); $authini->setValue('timeout', '30'); $authini->save(); $profile = $this->getOption('-profile'); if (!$this->getOption('-noauthdb')) { if ($profile != '') { $authini->setValue('profile', $profile, 'Db'); } $authini->save(); $installer->setModuleParameters('jauthdb', array('defaultuser' => true)); $installer->installModules(array('jauthdb', 'jauthdb_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jauthdb_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jauthdb_admin.access', '0', 'modules'); $inifile->save(); } if (!$this->getOption('-noacl2db')) { if ($profile != '') { $dbini = new jIniFileModifier(jApp::configPath('profiles.ini.php')); $dbini->setValue('jacl2_profile', $profile, 'jdb'); $dbini->save(); } $installer = new jInstaller($reporter); $installer->setModuleParameters('jacl2db', array('defaultuser' => true)); $installer->installModules(array('jacl2db', 'jacl2db_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jacl2db_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jacl2db_admin.access', '0', 'modules'); $inifile->save(); } $installer->installModules(array('jpref_admin'), $entrypoint . '.php'); }
protected function handleCustomTestSuite() { $modulesTests = -1; /* $this->options[0] is an array of all options '--xxx'. each values is an array(0=>'optionname', 1=>'value if given') $this->options[1] is a list of parameters given after options it can be array(0=>'test name', 1=>'filename') */ foreach ($this->options[0] as $option) { switch ($option[0]) { case '--entrypoint': $this->entryPoint = $option[1]; break; case '--all-modules': $modulesTests = 0; break; case '--module': $modulesTests = 1; // test is the module name // testFile is the test file inside the module break; case '--testtype': $this->testType = $option[1]; break; } } if (isset($this->options[1][1]) && $modulesTests != 0) { // a specifique test file $this->arguments['testFile'] = $this->options[1][1]; } else { $this->arguments['testFile'] = ''; } $appInfos = new \Jelix\Core\Infos\AppInfos(); $ep = $appInfos->getEntryPointInfo($this->entryPoint); $mainConfig = new \Jelix\IniFile\IniModifier(jApp::mainConfigFile()); $this->epInfo = new \Jelix\Installer\EntryPoint($mainConfig, $ep["config"], $ep["file"], $ep["type"]); // let's load configuration now, and coordinator. it could be needed by tests // (during load of their php files or during execution) jApp::setConfig(jConfigCompiler::readAndCache($this->epInfo->configFile, null, $this->entryPoint)); jApp::setCoord(new jCoordinator('', false)); if ($modulesTests == 0) { // we add all modules in the test list $suite = $this->getAllModulesTestSuites(); if (count($suite)) { $this->arguments['test'] = $suite; unset($this->arguments['testFile']); } else { $this->showMessage("Error: no tests in modules\n"); exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } } else { if ($modulesTests == 1 && !$this->version36) { $suite = $this->getModuleTestSuite($this->options[1][0]); if (count($suite)) { $this->arguments['test'] = $suite; if (isset($this->options[1][1])) { // a specifique test file $this->arguments['testFile'] = $this->options[1][1]; } else { $this->arguments['testFile'] = ''; } } else { $this->showMessage("Error: no tests in the module\n"); exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } } else { if ($modulesTests == 1) { if (isset($this->options[1][1])) { // a specifique test file $suite = $this->getModuleTestSuite($this->options[1][0], $this->options[1][1]); } else { $suite = $this->getModuleTestSuite($this->options[1][0]); } if (count($suite)) { $this->arguments['test'] = $suite; } else { $this->showMessage("Error: no tests in the module\n"); exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } } } } }
protected function loadconf() { $ini = new \Jelix\IniFile\IniModifier(jApp::mainConfigFile()); $emailConfig = array('webmasterEmail' => $ini->getValue('webmasterEmail', 'mailer'), 'webmasterName' => $ini->getValue('webmasterName', 'mailer'), 'mailerType' => $ini->getValue('mailerType', 'mailer'), 'hostname' => $ini->getValue('hostname', 'mailer'), 'sendmailPath' => $ini->getValue('sendmailPath', 'mailer'), 'smtpHost' => $ini->getValue('smtpHost', 'mailer'), 'smtpPort' => $ini->getValue('smtpPort', 'mailer'), 'smtpSecure' => $ini->getValue('smtpSecure', 'mailer'), 'smtpHelo' => $ini->getValue('smtpHelo', 'mailer'), 'smtpAuth' => $ini->getValue('smtpAuth', 'mailer'), 'smtpUsername' => $ini->getValue('smtpUsername', 'mailer'), 'smtpPassword' => $ini->getValue('smtpPassword', 'mailer'), 'smtpTimeout' => $ini->getValue('smtpTimeout', 'mailer'), 'errors' => array()); if (!in_array($emailConfig['mailerType'], array('mail', 'sendmail', 'smtp'))) { $emailConfig['mailerType'] = 'mail'; } return $emailConfig; }
/** * */ public function compile($aSelector) { $sourceFile = $aSelector->getPath(); $cachefile = $aSelector->getCompiledFilePath(); $xml = simplexml_load_file($sourceFile); if (!$xml) { return false; } /* <urls> <classicentrypoint name="index" default="true"> <url pathinfo="/test/:mois/:annee" module="" action=""> <param name="mois" escape="true" regexp="\d{4}"/> <param name="annee" escape="false" /> <static name="bla" value="cequejeveux" /> </url> <url handler="" module="" action="" /> </classicentrypoint> </urls> The compiler generates two files. It generates a php file for each entrypoint. A file contains a $PARSE_URL array: $PARSE_URL = array($isDefault, $infoparser, $infoparser, ... ) where: $isDefault: true if it is the default entry point. In this case and where the url parser doesn't find a corresponding action, it will ignore else it will generate an error $infoparser = array('module','action', 'regexp_pathinfo', 'handler selector', array('secondaries','actions'), false // needs https or not ) or $infoparser = array('module','action','regexp_pathinfo', array('year','month'), // list of dynamic value included in the url, // alphabetical ascendant order array(true, false), // list of boolean which indicates for each // dynamic value, if it is an escaped value or not array('bla'=>'whatIWant' ), // list of static values array('secondaries','actions'), false // need https or not ) It generates an other file common to all entry point. It contains an array which contains informations to create urls $CREATE_URL = array( 'news~show@classic' => // the action selector array(0,'entrypoint', https true/false, 'handler selector') or array(1,'entrypoint', https true/false, array('year','month',), // list of dynamic values included in the url array(0, 1..), // list of integer which indicates for each // dynamic value: 0: urlencode, 1:urlencode except '/', 2:escape, 4: lang, 8: locale "/news/%1/%2/", // the url array('bla'=>'whatIWant' ) // list of static values ) or When there are several urls to the same action, it is an array of this kind of the previous array: array(4, array(1,...), array(1,...)...) or array(2,'entrypoint', https true/false), // for the patterns "@request" or array(3,'entrypoint', https true/false), // for the patterns "module~@request" */ $this->createUrlInfos = array(); $this->createUrlContent = "<?php \nif (jApp::config()->compilation['checkCacheFiletime'] &&( \n"; $this->createUrlContent .= "filemtime('" . $sourceFile . '\') > ' . filemtime($sourceFile); $this->createUrlContentInc = ''; $this->readProjectXml(); $this->retrieveModulePaths(basename(jApp::mainConfigFile())); // for an app on a simple http server behind an https proxy, we shouldn't check HTTPS $this->checkHttps = jApp::config()->urlengine['checkHttpsOnParsing']; foreach ($xml->children() as $tagname => $tag) { if (!preg_match("/^(.*)entrypoint\$/", $tagname, $m)) { //TODO : error continue; } $type = $m[1]; if ($type == '') { if (isset($tag['type'])) { $type = (string) $tag['type']; } if ($type == '') { $type = 'classic'; } } $this->defaultUrl = new significantUrlInfoParsing($type, (string) $tag['name'], isset($tag['default']) ? (string) $tag['default'] == 'true' : false, isset($tag['https']) ? (string) $tag['https'] == 'true' : false); if (isset($tag['noentrypoint']) && (string) $tag['noentrypoint'] == 'true') { $this->defaultUrl->entryPointUrl = ''; } $optionalTrailingSlash = isset($tag['optionalTrailingSlash']) && $tag['optionalTrailingSlash'] == 'true'; $this->parseInfos = array($this->defaultUrl->isDefault); //let's read the modulesPath of the entry point $this->retrieveModulePaths($this->getEntryPointConfig($this->defaultUrl->entryPoint), $this->defaultUrl->entryPoint); // if this is the default entry point for the request type, // then we add a rule which will match urls which are not // defined. if ($this->defaultUrl->isDefault) { $this->createUrlInfos['@' . $this->defaultUrl->requestType] = array(2, $this->defaultUrl->entryPoint, $this->defaultUrl->isHttps); } $createUrlInfosDedicatedModules = array(); $parseContent = "<?php \n"; foreach ($tag->children() as $tagname => $url) { $u = clone $this->defaultUrl; $u->module = (string) $url['module']; if (isset($url['https'])) { $u->isHttps = (string) $url['https'] == 'true'; } if (isset($url['noentrypoint']) && (string) $url['noentrypoint'] == 'true') { $u->entryPointUrl = ''; } if (isset($url['include'])) { $this->readInclude($url, $u); continue; } // in the case of a non default entry point, if there is just an // <url module="" />, so all actions of this module will be assigned // to this entry point. if (!$u->isDefault && !isset($url['action']) && !isset($url['handler'])) { $this->parseInfos[] = array($u->module, '', '/.*/', array(), array(), array(), false, $this->checkHttps && $u->isHttps); $createUrlInfosDedicatedModules[$u->getFullSel()] = array(3, $u->entryPointUrl, $u->isHttps, true); continue; } $u->action = (string) $url['action']; if (strpos($u->action, ':') === false) { $u->action = 'default:' . $u->action; } if (isset($url['actionoverride'])) { $u->actionOverride = preg_split("/[\\s,]+/", (string) $url['actionoverride']); foreach ($u->actionOverride as &$each) { if (strpos($each, ':') === false) { $each = 'default:' . $each; } } } // if there is an indicated handler, so, for the given module // (and optional action), we should call the given handler to // parse or create an url if (isset($url['handler'])) { $this->newHandler($u, $url); continue; } // parse dynamic parameters if (isset($url['pathinfo'])) { $path = (string) $url['pathinfo']; $regexppath = $this->extractDynamicParams($url, $path, $u); } else { $regexppath = '.*'; $path = ''; } $tempOptionalTrailingSlash = $optionalTrailingSlash; if (isset($url['optionalTrailingSlash'])) { $tempOptionalTrailingSlash = $url['optionalTrailingSlash'] == 'true'; } if ($tempOptionalTrailingSlash) { if (substr($regexppath, -1) == '/') { $regexppath .= '?'; } else { $regexppath .= '\\/?'; } } // parse static parameters foreach ($url->static as $var) { $t = ""; if (isset($var['type'])) { switch ((string) $var['type']) { case 'lang': $t = '$l'; break; case 'locale': $t = '$L'; break; default: throw new Exception('urls definition: invalid type on a <static> element'); } } $u->statics[(string) $var['name']] = $t . (string) $var['value']; } $this->parseInfos[] = array($u->module, $u->action, '!^' . $regexppath . '$!', $u->params, $u->escapes, $u->statics, $u->actionOverride, $this->checkHttps && $u->isHttps); $this->appendUrlInfo($u, $path, false); if ($u->actionOverride) { foreach ($u->actionOverride as $ao) { $u->action = $ao; $this->appendUrlInfo($u, $path, true); } } } $c = count($createUrlInfosDedicatedModules); foreach ($createUrlInfosDedicatedModules as $k => $inf) { if ($c > 1) { $inf[3] = false; } $this->createUrlInfos[$k] = $inf; } $parseContent .= '$GLOBALS[\'SIGNIFICANT_PARSEURL\'][\'' . rawurlencode($this->defaultUrl->entryPoint) . '\'] = ' . var_export($this->parseInfos, true) . ";\n?>"; jFile::write(jApp::tempPath('compiled/urlsig/' . $aSelector->file . '.' . rawurlencode($this->defaultUrl->entryPoint) . '.entrypoint.php'), $parseContent); } $this->createUrlContent .= ")) { return false; } else {\n"; $this->createUrlContent .= $this->createUrlContentInc; $this->createUrlContent .= '$GLOBALS[\'SIGNIFICANT_CREATEURL\'] =' . var_export($this->createUrlInfos, true) . ";\nreturn true;"; $this->createUrlContent .= "\n}\n"; jFile::write(jApp::tempPath('compiled/urlsig/' . $aSelector->file . '.creationinfos_15.php'), $this->createUrlContent); return true; }
/** * initialize the installation * * it reads configurations files of all entry points, and prepare object for * each module, needed to install/upgrade modules. * @param jIInstallReporter $reporter object which is responsible to process messages (display, storage or other..) * @param string $lang the language code for messages */ function __construct($reporter, $lang = '') { $this->reporter = $reporter; $this->messages = new jInstallerMessageProvider($lang); $this->mainConfig = new jIniFileModifier(jApp::mainConfigFile()); $localConfig = jApp::configPath('localconfig.ini.php'); if (!file_exists($localConfig)) { $localConfigDist = jApp::configPath('localconfig.ini.php.dist'); if (file_exists($localConfigDist)) { copy($localConfigDist, $localConfig); } else { file_put_contents($localConfig, ';<' . '?php die(\'\');?' . '>'); } } $this->localConfig = new jIniMultiFilesModifier($this->mainConfig, $localConfig); $this->installerIni = $this->getInstallerIni(); $this->readEntryPointData(simplexml_load_file(jApp::appPath('project.xml'))); $this->installerIni->save(); }
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', '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))); if ($this->verbose()) { echo "Configuration file {$configFile} has been created from the config file {$originalConfig}.\n"; } } else { // else we create a new config file, with the startmodule of the default // config as a module name. $mainConfig = parse_ini_file(jApp::mainConfigFile(), true); $param = array(); if (isset($mainConfig['startModule'])) { $param['modulename'] = $mainConfig['startModule']; } else { $param['modulename'] = 'jelix'; } $this->createFile($configFilePath, 'var/config/index/config.ini.php.tpl', $param, "Configuration file"); } } require_once JELIX_LIB_PATH . 'utils/jIniMultiFilesModifier.class.php'; $inifile = new jIniMultiFilesModifier(jApp::mainConfigFile(), $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, "Entry point"); 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); if ($this->verbose()) { echo "Project.xml has been updated.\n"; } require_once JELIX_LIB_PATH . 'installer/jInstaller.class.php'; $installer = new jInstaller(new textInstallReporter('warning')); $installer->installEntryPoint($name . ".php"); if ($this->verbose()) { echo "All modules have been initialized for the new entry point.\n"; } }
/** * initialize the installation * * it reads configurations files of all entry points, and prepare object for * each module, needed to install/upgrade modules. * @param jIInstallReporter $reporter object which is responsible to process messages (display, storage or other..) * @param string $lang the language code for messages */ function __construct($reporter, $lang = '') { $this->reporter = $reporter; $this->messages = new jInstallerMessageProvider($lang); $this->mainConfig = new jIniFileModifier(jApp::mainConfigFile()); $this->installerIni = $this->getInstallerIni(); $this->readEntryPointData(simplexml_load_file(jApp::appPath('project.xml'))); $this->installerIni->save(); }