home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / IniFromScratch.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.5 KB  |  80 lines

  1. <?php
  2. /**
  3. * Config.php example
  4. * Lots of different manipulations to show Config features.
  5. *
  6. * @author     Bertrand Mansion <bmansion@mamasam.com>
  7. * @package    Config
  8. */
  9. // $Id: IniFromScratch.php,v 1.2 2003/03/21 18:04:21 mansion Exp $
  10.  
  11. require_once('Config.php');
  12.  
  13. // Creates a PHPArray config with attributes, from scratch
  14.  
  15. $dsn = array('type' => 'mysql',
  16.              'host' => 'localhost',
  17.              'user' => 'mamasam',
  18.              'pass' => 'foobar');
  19.  
  20. $c = new Config_Container('section', 'root');
  21.   $c->createComment('DB Config');
  22.   $db =& $c->createSection('DB', $dsn);
  23.     $fields =& $db->createSection('fields');
  24.     $fields->createDirective('username', 'USERNAME', array('type' => 'varchar', 'size' => 32));
  25.     $fields->createDirective('password', 'PASSWD', array('type' => 'varchar', 'size' => 32));
  26.   $c->createBlank();
  27.   $c->createComment('Support config');
  28.   $c->createDirective('support', 'See my wishlist...');
  29.  
  30. echo '<pre>'. $c->toString('phparray') .'</pre>';
  31. unset($c);
  32.  
  33. // Parses and writes an existing php array $conf
  34.  
  35. $conf['storage']['driver'] = 'sql';
  36. $conf['storage']['params']['phptype']  = 'mysql';
  37. $conf['storage']['params']['hostspec'] = 'localhost';
  38. $conf['storage']['params']['username'] = 'mamasam';
  39. $conf['storage']['params']['password'] = 'foobar';
  40. $conf['menu']['apps'] = array('imp', 'turba');
  41. $conf['stdcontent']['para'][0] = 'This is really cool !';
  42. $conf['stdcontent']['para'][1] = 'It just rocks...';
  43.  
  44. $c = new Config();
  45. $root =& $c->parseConfig($conf, 'phparray');
  46.  
  47. $storage =& $root->getItem('section', 'storage');
  48. $storage->removeItem();
  49. $root->addItem($storage);
  50.  
  51. echo '<pre>'. $root->toString('phparray', array('name' => 'test')) .'</pre>';
  52.  
  53. if ($c->writeConfig('/tmp/Config_Test.php', 'phparray', array('name' => 'test')) === true) {
  54.     echo 'Config written into /tmp/Config_Test.php';
  55. }
  56.  
  57. // Making a php ini file with $storage only
  58.  
  59. $ini = new Config();
  60. $iniRoot =& $ini->getRoot();
  61. $iniRoot->addItem($storage);
  62.  
  63. $comment =& new Config_Container('comment', null, 'This is the php ini version of storage');
  64. $iniRoot->addItem($comment, 'top');
  65. $iniRoot->createBlank('after', $comment);
  66. echo '<pre>'. $iniRoot->toString('inicommented') .'</pre>';
  67.  
  68. // Gonna make an array with it
  69.  
  70. echo '<pre>'; var_dump($iniRoot->toArray()); echo '</pre>';
  71.  
  72. // Now, I'll parse you php.ini file and make it a php array
  73.  
  74. $phpIni = new Config();
  75. $phpIni->parseConfig('/usr/local/lib/php.ini', 'inifile');
  76. $root =& $phpIni->getRoot();
  77. echo '<pre>'.$root->toString('phparray', array('name' => 'php_ini')).'</pre>';
  78.  
  79. ?>