svn: /pear/peardoc/trunk/en/package/configuration/config/ avail-container.xml examples/test-features.php

[email protected] (Christian Weiske) Thu, 10 Mar 2011 22:01:54 +0000
Newsgroups php.pear.doc
Message-ID <[email protected]>
cweiske                                  Thu, 10 Mar 2011 22:01:54 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=309094

Log:
comparison of config containers

Changed paths:
    U   pear/peardoc/trunk/en/package/configuration/config/avail-container.xml
    A   pear/peardoc/trunk/en/package/configuration/config/examples/test-features.php

Modified: pear/peardoc/trunk/en/package/configuration/config/avail-container.xml
===================================================================
--- pear/peardoc/trunk/en/package/configuration/config/avail-container.xml	2011-03-10 20:50:16 UTC (rev 309093)
+++ pear/peardoc/trunk/en/package/configuration/config/avail-container.xml	2011-03-10 22:01:54 UTC (rev 309094)
@@ -16,6 +16,107 @@
   Ini-style configuration files are very common.
  </para>

+
+ <table>
+  <title>Feature comparison</title>
+
+  <tgroup cols="8">
+   <thead>
+    <row>
+     <entry>Container</entry>
+     <entry>Comments</entry>
+     <entry>Sections</entry>
+     <entry>Nested sections</entry>
+     <entry>Multiline strings</entry>
+     <entry>Boolean</entry>
+     <entry>Int/float</entry>
+     <entry>Null</entry>
+    </row>
+   </thead>
+
+   <tbody>
+    <row>
+     <entry>Apache</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>-</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+    </row>
+    <row>
+     <entry>GenericConf</entry>
+     <entry>yes</entry>
+     <entry>-</entry>
+     <entry>-</entry>
+     <entry>yes</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+    </row>
+    <row>
+     <entry>IniCommented</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>-</entry>
+     <entry>-</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+    </row>
+    <row>
+     <entry>IniFile</entry>
+     <entry>-</entry>
+     <entry>yes</entry>
+     <entry>-</entry>
+     <entry>yes</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+    </row>
+    <row>
+     <entry>PHPArray</entry>
+     <entry>-</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+    </row>
+    <row>
+     <entry>PHPConstants</entry>
+     <entry>yes</entry>
+     <entry>-</entry>
+     <entry>-</entry>
+     <entry>-</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+    </row>
+    <row>
+     <entry>XML</entry>
+     <entry>no</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>yes</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+     <entry>(yes)*</entry>
+    </row>
+   </tbody>
+  </tgroup>
+ </table>
+
+ <note>
+  <para>
+   <literal>(yes)*</literal> indicates that saving and loading those types
+   does work, but the type of the variable is "string" after
+   reading the config file.
+  </para>
+ </note>
+
  &package.configuration.config.avail-container.apache;
  &package.configuration.config.avail-container.generic-conf;
  &package.configuration.config.avail-container.ini-commented;

Added: pear/peardoc/trunk/en/package/configuration/config/examples/test-features.php
===================================================================
--- pear/peardoc/trunk/en/package/configuration/config/examples/test-features.php	                        (rev 0)
+++ pear/peardoc/trunk/en/package/configuration/config/examples/test-features.php	2011-03-10 22:01:54 UTC (rev 309094)
@@ -0,0 +1,62 @@
+<?php
+/* this script was used to test which features the single container formats support */
+require_once 'Config.php';
+
+$conf = new Config();
+$root = $conf->getRoot();
+$root->createComment('Feature test script');
+
+$root->createDirective('testString', 'This is a string');
+$root->createDirective('testStringSpecialChars', 'Oh : = > <\'" & ; ==');
+//$root->createDirective('testStringMultiline', "line1'\"><?&=\nline2\n  line3");
+$root->createDirective('testBoolTrue', true);
+$root->createDirective('testBoolFalse', false);
+$root->createDirective('testInt', 8);
+$root->createDirective('testFloat', 8.92);
+//nobody supports arrays
+//$root->createDirective('testArray', array(1, 2, 'foo' => 'bar'));
+$root->createDirective('testNull', null);
+
+
+$root->createBlank();
+$sect = $root->createSection('section');
+$sect->createDirective('content', 'section-1');
+
+$sect2 = $sect->createSection('section');
+$sect2->createDirective('content', 'section-2');
+
+$sect3 = $sect2->createSection('section');
+$sect3->createDirective('content', 'section-3');
+
+$containers = array(
+    'apache', 'genericconf', 'inicommented', 'inifile',
+    'phparray', 'phpconstants', 'xml'
+);
+foreach ($containers as $container) {
+    $file = 'test-' . $container . '-out.txt';
+    $r = $conf->writeConfig(
+        $file,
+        $container
+    );
+    if (PEAR::isError($r)) {
+        echo 'Error saving as ' . $container . ': ' . $r->getMessage() . "\n";
+    }
+
+    //read it
+    $rconf = new Config();
+    $rroot = $rconf->parseConfig($file, $container);
+    if (PEAR::isError($rroot)) {
+        echo 'Error loading as ' . $container . ': ' . $rroot->getMessage() . "\n";
+        continue;
+    }
+    $rcfg = $rroot->toArray();
+    echo $container . "\n";
+    $comment = $rroot->getItem('comment');
+    if ($comment instanceof Config_Container) {
+        echo 'Comment: ' . $comment->content . "\n";
+    } else {
+        echo "No comment\n";
+    }
+    var_dump($rcfg);
+}
+?>
\ No newline at end of file