LiveUser configuration considerations

From: Date: Mon, 14 Apr 2003 12:24:26 +0000
Subject: LiveUser configuration considerations
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-15163@lists.php.net to get a copy of this message
Hi, I have some ideas about the way LiveUser uses its configuration files. At the moment, there are two formats supported PHP and XML. Because the XML format uses attributes, this cannot be easily translated to a PHP array. And because the PHP array don't have attributes, it cannot be translated neither. This makes both formats incompatible. In the package Config I have written, we translate XML attributes to a '@' indexed array and values to '#'. So, an XML configuration for Auth in LiveUser will look like this once it is translated to a PHP array: $liveuserAuthXML['user'][0]['userId'] = "c4ca4238a0b923820dcc509a6f75849b"; $liveuserAuthXML['user'][0]['handle'] = "father"; $liveuserAuthXML['user'][0]['password'] = "password..."; $liveuserAuthXML['user'][0]['currentLogin'] = "1047658848"; $liveuserAuthXML['user'][0]['lastLogin'] = "1047564897"; $liveuserAuthXML['user'][0]['isActive'] = "Y"; $liveuserAuthXML['user'][1]['userId'] = "c81e728d9d4c2f636f067f89cc14862c"; $liveuserAuthXML['user'][1]['handle'] = "mother"; $liveuserAuthXML['user'][1]['password'] = "password..."; $liveuserAuthXML['user'][1]['currentLogin'] = "1047658859"; $liveuserAuthXML['user'][1]['lastLogin'] = "1047564685"; $liveuserAuthXML['user'][1]['isActive'] = "Y"; $liveuserAuthXML['user'][2]['userId'] = "eccbc87e4b5ce2fe28308fd9f2a7baf3"; $liveuserAuthXML['user'][2]['handle'] = "child"; $liveuserAuthXML['user'][2]['password'] = "password..."; $liveuserAuthXML['user'][2]['currentLogin'] = "1047565777"; $liveuserAuthXML['user'][2]['lastLogin'] = "1047565686"; $liveuserAuthXML['user'][2]['isActive'] = "Y"; This is a translated version of the Auth_XML.xml file found in the examples. As you can see, it is readable, there are no attributes for XML nodes. Now with attributes. I used the conf.xml found in the same example: $liveuserConfig['sessionName'] = "PHPSESSION"; $liveuserConfig['sessionVarName'] = "loginInfo"; $liveuserConfig['handleParamName'] = "handle"; $liveuserConfig['passwdParamName'] = "passwd"; $liveuserConfig['loginInputType'] = "POST"; $liveuserConfig['logoutParamName'] = "logout"; $liveuserConfig['cookieName'] = "loginInfo"; $liveuserConfig['allowCookies'] = "1"; $liveuserConfig['cookieParamName'] = "rememberMe"; $liveuserConfig['cookieLifetime'] = "30"; $liveuserConfig['cookieDomain'] = "localhost"; $liveuserConfig['cookiePath'] = "/"; $liveuserConfig['authContainers']['container']['@']['type'] = "XML"; $liveuserConfig['authContainers']['container']['@']['file'] = "/Auth_XML.xml"; $liveuserConfig['authContainers']['container']['options']['@']['loginTimeout '] = "0"; $liveuserConfig['authContainers']['container']['options']['@']['expireTime'] = "3600"; $liveuserConfig['authContainers']['container']['options']['@']['idleTime'] = "1800"; $liveuserConfig['authContainers']['container']['options']['@']['allowDuplica teHandles'] = "0"; OK, this is still readable but a bit more difficult to write because you have to know were the attributes are. The main adavantage to use a PHP array over an XML file is that it is parsed a lot faster. Config allows to take an XML file and have it converted to a PHP array and to take a PHP array and convert it to an XML file. I think it would be interesting to have both file types compatible through the use of Config. At the moment, there is a dependency for XML_Tree and XML_Parser. Config has a dependency for XML_Parser just like XML_Tree. So if you use Config instead of XML_Tree, it won't add a new dependency and you will gain more flexibility because Config was made to deal with configuration files, not XML_Tree. So I would like you to please consider using Config instead of XML_Tree. I am not pushing for that. It is only because I feel that in the future, you might need it. Indeed, I have noticed that you can store rights and areas information in the configuration files. When you will want to provide the user with a front end to create/modify areas and rights, you will need to be able to write these configuration changes to a file in both formats. If both are not compatible, the user will be stuck with one format, plus you will have to write 2 parsers and 2 writers. This is already dealt with in Config, it works well and there is an easy API to create new sections with attributes and directives. So using it will make your developer's life easier. If you want to give it a try to imagine how it could help, here is the code I used to get a PHP array: <?php require_once('Config.php'); $conf = new Config(); $root =& $conf->parseConfig('conf.xml', 'xml'); echo '<pre>'; echo $root->toString('phparray'); var_dump($root->toArray()); echo '</pre>'; ?> To get the XML version: <?php require_once('Config.php'); $conf = new Config(); $root =& $conf->parseConfig('conf.xml', 'xml'); echo '<pre>'; echo $root->toString('xml'); var_dump($root->toArray()); echo '</pre>'; ?> Please let me know what you think of this idea. If you are interested, I can try to implement the use of Config in loginManager.php Bertrand Mansion Mamasam

« previous php.pear.dev (#15163) next »