This patch introduces the concept of wrappers to the configuration system. It works by adding a wrapper argument to the config->set() method.
$html = '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>';
$config = config('test.wrapper');
$test = array(
'test' => $html,
'test2' => array(
'test3' => $html,
),
);
$config->set('test_cdata', $html, CONFIG_HTML_WRAPPER);
$config->set('test_cdata_array',$test, CONFIG_HTML_WRAPPER);
$config->save();
This produces xml like this:
<?xml version="1.0"?>
<config>
<test_cdata><![CDATA[<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>]]></test_cdata>
<test_cdata_array>
<test><![CDATA[<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>]]></test>
<test2>
<test3><![CDATA[<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>]]></test3>
</test2>
</test_cdata_array>
</config>
Currently we have xml like this:
<?xml version="1.0"?>
<config>
<test_no_cdata><a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul></test_no_cdata>
<test_no_cdata_array>
<test><a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul></test>
<test2>
<test3><a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul></test3>
</test2>
</test_no_cdata_array>
</config>
The obvious downside of this approach is that we will always have to save the files on config->save() as the wrapper mapping to config keys is only stored in memory.
The upside of this approach is that through using the LIBXML_NOCDATA flag on simplexml_load_string() we don't have to do anything on $config->get().
Comments
Comment #1
alexpottUpdating tag...
Comment #3
alexpottNew patch to resolve issues when nested keys like biff.bang
Comment #4
sunObsoleted by #1470824: XML encoder can only handle a small subset of PHP arrays, so switch to YAML