|
目录
配置文件介绍Seagull 使用许多配置文件给应用程序提供信息,两个主要类型是
seagull/var/<your-hostname>_<port-number>.conf.php
seagull/modules/$module/conf.ini 系统配置文件是在安装的时候根据下面的模板创建的 seagull/etc/default.conf.dist.ini 你所运行地机器的主机名被加在你的配置文件名前。所以如果你的主机名是: 你的配置文件名就是 如果你使用8080端口 那你的配置文件名将是 这样,你就可以在多台主机上运行你的代码,并且可以加载相应服务器的配置文件。 配置文件格式配置文件默认使用的格式是在以php为扩展名的文件中的使用php数组,然而你可以使用你喜欢的任何数据格式,目前支持下面这些格式: • ini 格式 • xml • PHP 数组 读取全局配置文件习惯用这种方式来读取全局配置文件: $c = &SGL_Config::singleton(); $conf = $c->getAll(); 无论什么时候你调用config的singleton()函数,你将得到一个指向已经载入的数据的参考,而不用去重复读取这个文件。 Config对象有一个指向ParamHandler对象的参考变量。ParamHandler对象是文件解析策略,它是以从$configFile参数中读取的文件扩展名为依据进行分析的。由于文件类型是自动地处理,所以也就不需要程序员干预。 读取其他配置文件,如模块配置文件在这种情况下你不想使用已经存在的指向全局配置数据的参考变量,所以需要创建一个新的config实例来加载你指定的文件: $myConf = new SGL_Config();
$data = $myConf->load('/path/to/file')
如果你要修改$data,首先得让它跟config对象关联: $myConf->replace($data); 设置某些属性值: $myConf->set('tuples', array('version' => SGL_SEAGULL_VERSION));
$myConf->set('foo', array('bar' => $myValue));
然后保存这个对象: $ok = $myConf->save('/path/to/file');
配置信息的缓存从0.6.2版本开始所有的模块配置文件被缓存在var目录中。
模块的配置文件,用ini格式明显比xml快,因为用PHP的parse_ini_file()解析比xml快很多,而且conf.ini通常是没有敏感信息。 查看php手册获得ini文件的例子。 加载, 保存并合并配置数据要修改全局配置信息,把它内容读到一个变量中: $c = &SGL_Config::singleton(); $data = $c->load($configFile) 你可以读多个配置文件,并把结果合并在一个配置对象里: $c->merge($data); 设置一些其他关键字: $c->set('tuples', array('version' => SGL_SEAGULL_VERSION));
$c->set('foo', array('bar' => $myValue));
最后再保存这个对象: $ok = $c->save('/path/to/file');
和加载一样,你指定的文件扩展名确定了被保存数据的格式。 如果你想要用一个独立的数据源来覆盖内容对象中现有的数据,那么使用replace方法: $c->replace($data); 访问配置数据配置变量可以像下面这样调用: 在任何一个manager里, $this→conf 都是通过继续SGL_Manager 这个父类得到的: $c = &SGL_Config::singleton(); $this->conf = $c->getAll(); 所以可以这样调用某个键值: if ($this->conf['banIpEnabled']['enabled']) { // do something }
或 if ($c->get(array('banIpEnabled' => 'enabled'))) { // do something }
不要使用数组的参考变量$this→conf来设定某个键值,它只是一个存放配置数值的只读副本,而应该用: $c->set('tuples', array('version' => SGL_SEAGULL_VERSION));
安全测试布尔型变量的值如果你需要测试配置信息中的一个简单布尔型变量,你可以使用empty()来实现: if (!empty($this->conf['FaqMgr']['commentsEnabled'])) { .. }
相当于 if (isset($this->conf['FaqMgr']['commentsEnabled']) && $this->conf['FaqMgr']['commentsEnabled'] == true) { .. }
所以,如果你测试的键值不存在,你也不会得到empty()测试的notice1)。 模块配置如上所述,所有模块都有一个配置文件位于 seagull/modules/$module/conf.ini 这个配置文件默认是ini格式,当一个模块被加载时,它与系统配置文件合并。它的值可以用上面一样的方法来调用。这个文件用来设置模块特殊配置信息。 使用浏览器编辑模块配置文件至于0.6.0版本,你可以通过浏览器修改配置文件,以管理员登录后默认进入到的模块列表页面,点击模块的标题来修改该模块的配置文件。 加载自定义的设置文件在Seagull 0.6.1中,你可以从一个指定位置加载额外配置文件。在全局配置文件中简单地指定文件路径就可以了。如果$conf[path][pathToCustomConfigFile]的值不为空, SGL_Task_LoadCustomConfig任务就会试图加载这个文件,这对于给指定角色设置常量等是有用的。 例子返回的$config数组的值通常是这样的: Array ( [db] => Array
(
[type] => mysql_SGL
[host] => localhost
[protocol] => unix
[socket] =>
[port] => 3306
[user] => root
[pass] =>
[name] => seagull_bugfix
[postConnect] =>
[prefix] => not implemented yet
)
[site] => Array
(
[outputUrlHandler] => SGL_UrlParser_SefStrategy
[name] => Seagull Framework
[showLogo] => logo.gif
[compression] => 0
[outputBuffering] => 0
[banIpEnabled] => 0
[denyList] =>
[allowList] =>
[tidyhtml] => 0
[blocksEnabled] => 1
[safeDelete] => 1
[frontScriptName] => index.php
[defaultModule] => default
[defaultManager] => default
[defaultArticleViewType] => 1
[defaultParams] =>
[templateEngine] => flexy
[wysiwygEditor] => tinyfck
[extendedLocale] => 0
[localeCategory] => 'LC_ALL'
[adminGuiTheme] => default_admin
[defaultTheme] => default
[serverTimeOffset] => UTC
[baseUrl] => http://localhost/seagull/branches/0.6-bugfix/www
[description] => Coming soon to a webserver near you.
[keywords] => seagull, php, framework, cms, content management
)
[cookie] => Array
(
[path] => /
[domain] =>
[secure] => 0
[name] => SGLSESSID
)
[session] => Array
(
[maxLifetime] => 0
[extended] => 0
[singleUser] => 0
[handler] => file
[allowedInUri] => 1
)
[cache] => Array
(
[enabled] => 0
[lifetime] => 86400
)
[debug] => Array
(
[authorisationEnabled] => 1
[sessionDebugAllowed] => 1
[customErrorHandler] => 1
[production] => 0
[showBacktrace] => 0
[profiling] => 0
[emailAdminThreshold] => PEAR_LOG_EMERG
[showBugReporterLink] => 1
[showUntranslated] => 1
)
[translation] => Array
(
[addMissingTrans] => 0
[fallbackLang] => en_iso_8859_15
[container] => file
[installedLanguages] => pt_br_iso_8859_1,zh_tw,zh,zh_utf_8,zh_tw_utf_8,cs_iso_8859_2,en_iso_8859_15,fr_iso_8859_1,fr_utf_8,de_iso_8859_1,it_iso_8859_1,no_iso_8859_1,pl_iso_8859_2,pt_iso_8859_1,ru_win1251,es_iso_8859_1,es_utf_8,sv_iso_8859_1,tr_iso_8859_9,tr_utf_8
)
[navigation] => Array
(
[enabled] => 1
[renderer] => SimpleRenderer
[driver] => SimpleDriver
[stylesheet] => SglDefault_TwoLevel
)
[log] => Array
(
[enabled] => 0
[type] => file
[name] => var/log/php_log.txt
[priority] => PEAR_LOG_EMERG
[ident] => Seagull
[paramsUsername] =>
[paramsPassword] =>
)
[mta] => Array
(
[backend] => mail
[sendmailPath] => /usr/sbin/sendmail
[sendmailArgs] => -t -i
[smtpHost] => 127.0.0.1
[smtpLocalHost] => seagull.phpkitchen.com
[smtpPort] => 25
[smtpAuth] => 0
[smtpUsername] =>
[smtpPassword] =>
)
[email] => Array
(
[admin] => demian@muse23.com
[support] => demian@muse23.com
[info] => demian@muse23.com
)
[popup] => Array
(
[winHeight] => 500
[winWidth] => 600
)
[censor] => Array
(
[mode] => 0
[replaceString] => *censored*
[badWords] => your,bad,words,here
)
[p3p] => Array
(
[policies] => 1
[policyLocation] =>
[compactPolicy] => CUR ADM OUR NOR STA NID
)
[tuples] => Array
(
[version] => 0.6.0RC2
)
[path] => Array
(
[installRoot] => /var/www/html/seagull/branches/0.6-bugfix
[webRoot] => /var/www/html/seagull/branches/0.6-bugfix/www
)
[table] => Array
(
[block] => block
[block_role] => block_role
[block_assignment] => block_assignment
[contact_us] => contact_us
[module] => module
[sequence] => sequence
[translation] => translation
[uri_alias] => uri_alias
[faq] => faq
[guestbook] => guestbook
[instant_message] => instant_message
[contact] => contact
[section] => section
[newsletter] => newsletter
[category] => category
[document] => document
[document_type] => document_type
[item] => item
[item_addition] => item_addition
[item_type] => item_type
[item_type_mapping] => item_type_mapping
[rndmsg_message] => rndmsg_message
[login] => login
[organisation] => organisation
[organisation_type] => organisation_type
[org_preference] => org_preference
[permission] => permission
[preference] => preference
[role] => role
[role_permission] => role_permission
[user] => usr
[user_permission] => user_permission
[user_preference] => user_preference
[user_session] => user_session
)
[ConfigMgr] => Array
(
[requiresAuth] => 1
[adminGuiAllowed] => 1
)
[DefaultMgr] => Array
(
[requiresAuth] =>
)
[ModuleConfigMgr] => Array
(
[requiresAuth] =>
)
[ModuleMgr] => Array
(
[requiresAuth] => 1
[adminGuiAllowed] => 1
)
[BugMgr] => Array
(
[requiresAuth] =>
)
[MaintenanceMgr] => Array
(
[requiresAuth] => 1
[adminGuiAllowed] => 1
)
[PearMgr] => Array
(
[requiresAuth] => 1
[adminGuiAllowed] => 1
)
[ModuleGenerationMgr] => Array
(
[requiresAuth] => 1
[adminGuiAllowed] => 1
)
[TranslationMgr] => Array
(
[requiresAuth] => 1
[adminGuiAllowed] => 1
)
[localConfig] => Array
(
[moduleName] => default
)
) 1)
关闭notice有几种方法,详情请看PHP Mannual
|