Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

init

  • Loading branch information...
commit b5cc5486256d7ac69bc9cbe8f90feeec61228f15 1 parent 5e6ec99
sunshine1988 authored February 27, 2013

Showing 112 changed files with 36,890 additions and 0 deletions. Show diff stats Hide diff stats

  1. 33  Config/Exception.php
  2. 309  Config/Ini.php
  3. 240  Config/Json.php
  4. 101  Config/Writer.php
  5. 55  Config/Writer/Array.php
  6. 134  Config/Writer/FileAbstract.php
  7. 193  Config/Writer/Ini.php
  8. 106  Config/Writer/Json.php
  9. 127  Config/Writer/Xml.php
  10. 144  Config/Writer/Yaml.php
  11. 296  Config/Xml.php
  12. 381  Config/Yaml.php
  13. 692  Controller/Action.php
  14. 38  Controller/Action/Exception.php
  15. 156  Controller/Action/Helper/Abstract.php
  16. 138  Controller/Action/Helper/ActionStack.php
  17. 80  Controller/Action/Helper/AjaxContext.php
  18. 149  Controller/Action/Helper/AutoComplete/Abstract.php
  19. 87  Controller/Action/Helper/AutoCompleteDojo.php
  20. 82  Controller/Action/Helper/AutoCompleteScriptaculous.php
  21. 279  Controller/Action/Helper/Cache.php
  22. 1,394  Controller/Action/Helper/ContextSwitch.php
  23. 266  Controller/Action/Helper/FlashMessenger.php
  24. 130  Controller/Action/Helper/Json.php
  25. 534  Controller/Action/Helper/Redirector.php
  26. 117  Controller/Action/Helper/Url.php
  27. 997  Controller/Action/Helper/ViewRenderer.php
  28. 383  Controller/Action/HelperBroker.php
  29. 280  Controller/Action/HelperBroker/PriorityStack.php
  30. 69  Controller/Action/Interface.php
  31. 440  Controller/Dispatcher/Abstract.php
  32. 37  Controller/Dispatcher/Exception.php
  33. 206  Controller/Dispatcher/Interface.php
  34. 506  Controller/Dispatcher/Standard.php
  35. 35  Controller/Exception.php
  36. 1,013  Controller/Front.php
  37. 151  Controller/Plugin/Abstract.php
  38. 280  Controller/Plugin/ActionStack.php
  39. 373  Controller/Plugin/Broker.php
  40. 303  Controller/Plugin/ErrorHandler.php
  41. 60  Controller/Plugin/PutHandler.php
  42. 356  Controller/Request/Abstract.php
  43. 82  Controller/Request/Apache404.php
  44. 37  Controller/Request/Exception.php
  45. 1,074  Controller/Request/Http.php
  46. 276  Controller/Request/HttpTestCase.php
  47. 55  Controller/Request/Simple.php
  48. 798  Controller/Response/Abstract.php
  49. 68  Controller/Response/Cli.php
  50. 36  Controller/Response/Exception.php
  51. 38  Controller/Response/Http.php
  52. 130  Controller/Response/HttpTestCase.php
  53. 175  Controller/Router/Abstract.php
  54. 36  Controller/Router/Exception.php
  55. 124  Controller/Router/Interface.php
  56. 551  Controller/Router/Rewrite.php
  57. 565  Controller/Router/Route.php
  58. 122  Controller/Router/Route/Abstract.php
  59. 173  Controller/Router/Route/Chain.php
  60. 341  Controller/Router/Route/Hostname.php
  61. 37  Controller/Router/Route/Interface.php
  62. 290  Controller/Router/Route/Module.php
  63. 269  Controller/Router/Route/Regex.php
  64. 127  Controller/Router/Route/Static.php
  65. 4,957  Date.php
  66. 322  Date/Cities.php
  67. 1,089  Date/DateObject.php
  68. 49  Date/Exception.php
  69. 286  Db.php
  70. 1,280  Db/Adapter/Abstract.php
  71. 840  Db/Adapter/Db2.php
  72. 45  Db/Adapter/Db2/Exception.php
  73. 57  Db/Adapter/Exception.php
  74. 549  Db/Adapter/Mysqli.php
  75. 40  Db/Adapter/Mysqli/Exception.php
  76. 643  Db/Adapter/Oracle.php
  77. 60  Db/Adapter/Oracle/Exception.php
  78. 401  Db/Adapter/Pdo/Abstract.php
  79. 360  Db/Adapter/Pdo/Ibm.php
  80. 228  Db/Adapter/Pdo/Ibm/Db2.php
  81. 301  Db/Adapter/Pdo/Ibm/Ids.php
  82. 423  Db/Adapter/Pdo/Mssql.php
  83. 270  Db/Adapter/Pdo/Mysql.php
  84. 378  Db/Adapter/Pdo/Oci.php
  85. 336  Db/Adapter/Pdo/Pgsql.php
  86. 297  Db/Adapter/Pdo/Sqlite.php
  87. 673  Db/Adapter/Sqlsrv.php
  88. 63  Db/Adapter/Sqlsrv/Exception.php
  89. 35  Db/Exception.php
  90. 77  Db/Expr.php
  91. 471  Db/Profiler.php
  92. 40  Db/Profiler/Exception.php
  93. 161  Db/Profiler/Firebug.php
  94. 213  Db/Profiler/Query.php
  95. 1,351  Db/Select.php
  96. 39  Db/Select/Exception.php
  97. 485  Db/Statement.php
  98. 360  Db/Statement/Db2.php
  99. 58  Db/Statement/Db2/Exception.php
  100. 56  Db/Statement/Exception.php
  101. 203  Db/Statement/Interface.php
  102. 362  Db/Statement/Mysqli.php
  103. 38  Db/Statement/Mysqli/Exception.php
  104. 577  Db/Statement/Oracle.php
  105. 59  Db/Statement/Oracle/Exception.php
  106. 439  Db/Statement/Pdo.php
  107. 94  Db/Statement/Pdo/Ibm.php
  108. 91  Db/Statement/Pdo/Oci.php
  109. 440  Db/Statement/Sqlsrv.php
  110. 61  Db/Statement/Sqlsrv/Exception.php
  111. 79  Db/Table.php
33  Config/Exception.php
... ...
@@ -0,0 +1,33 @@
  1
+<?php
  2
+/**
  3
+ * Zend Framework
  4
+ *
  5
+ * LICENSE
  6
+ *
  7
+ * This source file is subject to the new BSD license that is bundled
  8
+ * with this package in the file LICENSE.txt.
  9
+ * It is also available through the world-wide-web at this URL:
  10
+ * http://framework.zend.com/license/new-bsd
  11
+ * If you did not receive a copy of the license and are unable to
  12
+ * obtain it through the world-wide-web, please send an email
  13
+ * to license@zend.com so we can send you a copy immediately.
  14
+ *
  15
+ * @category   Zend
  16
+ * @package    Zend_Config
  17
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19
+ * @version    $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
  20
+ */
  21
+
  22
+/**
  23
+ * @see Zend_Exception
  24
+ */
  25
+require_once 'Zend/Exception.php';
  26
+
  27
+/**
  28
+ * @category   Zend
  29
+ * @package    Zend_Config
  30
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  31
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  32
+ */
  33
+class Zend_Config_Exception extends Zend_Exception {}
309  Config/Ini.php
... ...
@@ -0,0 +1,309 @@
  1
+<?php
  2
+/**
  3
+ * Zend Framework
  4
+ *
  5
+ * LICENSE
  6
+ *
  7
+ * This source file is subject to the new BSD license that is bundled
  8
+ * with this package in the file LICENSE.txt.
  9
+ * It is also available through the world-wide-web at this URL:
  10
+ * http://framework.zend.com/license/new-bsd
  11
+ * If you did not receive a copy of the license and are unable to
  12
+ * obtain it through the world-wide-web, please send an email
  13
+ * to license@zend.com so we can send you a copy immediately.
  14
+ *
  15
+ * @category   Zend
  16
+ * @package    Zend_Config
  17
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19
+ * @version    $Id: Ini.php 24045 2011-05-23 12:45:11Z rob $
  20
+ */
  21
+
  22
+
  23
+/**
  24
+ * @see Zend_Config
  25
+ */
  26
+require_once 'Zend/Config.php';
  27
+
  28
+
  29
+/**
  30
+ * @category   Zend
  31
+ * @package    Zend_Config
  32
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  33
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  34
+ */
  35
+class Zend_Config_Ini extends Zend_Config
  36
+{
  37
+    /**
  38
+     * String that separates nesting levels of configuration data identifiers
  39
+     *
  40
+     * @var string
  41
+     */
  42
+    protected $_nestSeparator = '.';
  43
+
  44
+    /**
  45
+     * String that separates the parent section name
  46
+     *
  47
+     * @var string
  48
+     */
  49
+    protected $_sectionSeparator = ':';
  50
+
  51
+    /**
  52
+     * Whether to skip extends or not
  53
+     *
  54
+     * @var boolean
  55
+     */
  56
+    protected $_skipExtends = false;
  57
+
  58
+    /**
  59
+     * Loads the section $section from the config file $filename for
  60
+     * access facilitated by nested object properties.
  61
+     *
  62
+     * If the section name contains a ":" then the section name to the right
  63
+     * is loaded and included into the properties. Note that the keys in
  64
+     * this $section will override any keys of the same
  65
+     * name in the sections that have been included via ":".
  66
+     *
  67
+     * If the $section is null, then all sections in the ini file are loaded.
  68
+     *
  69
+     * If any key includes a ".", then this will act as a separator to
  70
+     * create a sub-property.
  71
+     *
  72
+     * example ini file:
  73
+     *      [all]
  74
+     *      db.connection = database
  75
+     *      hostname = live
  76
+     *
  77
+     *      [staging : all]
  78
+     *      hostname = staging
  79
+     *
  80
+     * after calling $data = new Zend_Config_Ini($file, 'staging'); then
  81
+     *      $data->hostname === "staging"
  82
+     *      $data->db->connection === "database"
  83
+     *
  84
+     * The $options parameter may be provided as either a boolean or an array.
  85
+     * If provided as a boolean, this sets the $allowModifications option of
  86
+     * Zend_Config. If provided as an array, there are three configuration
  87
+     * directives that may be set. For example:
  88
+     *
  89
+     * $options = array(
  90
+     *     'allowModifications' => false,
  91
+     *     'nestSeparator'      => ':',
  92
+     *     'skipExtends'        => false,
  93
+     *      );
  94
+     *
  95
+     * @param  string        $filename
  96
+     * @param  mixed         $section
  97
+     * @param  boolean|array $options
  98
+     * @throws Zend_Config_Exception
  99
+     * @return void
  100
+     */
  101
+    public function __construct($filename, $section = null, $options = false)
  102
+    {
  103
+        if (empty($filename)) {
  104
+            /**
  105
+             * @see Zend_Config_Exception
  106
+             */
  107
+            require_once 'Zend/Config/Exception.php';
  108
+            throw new Zend_Config_Exception('Filename is not set');
  109
+        }
  110
+
  111
+        $allowModifications = false;
  112
+        if (is_bool($options)) {
  113
+            $allowModifications = $options;
  114
+        } elseif (is_array($options)) {
  115
+            if (isset($options['allowModifications'])) {
  116
+                $allowModifications = (bool) $options['allowModifications'];
  117
+            }
  118
+            if (isset($options['nestSeparator'])) {
  119
+                $this->_nestSeparator = (string) $options['nestSeparator'];
  120
+            }
  121
+            if (isset($options['skipExtends'])) {
  122
+                $this->_skipExtends = (bool) $options['skipExtends'];
  123
+            }
  124
+        }
  125
+
  126
+        $iniArray = $this->_loadIniFile($filename);
  127
+
  128
+        if (null === $section) {
  129
+            // Load entire file
  130
+            $dataArray = array();
  131
+            foreach ($iniArray as $sectionName => $sectionData) {
  132
+                if(!is_array($sectionData)) {
  133
+                    $dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
  134
+                } else {
  135
+                    $dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName);
  136
+                }
  137
+            }
  138
+            parent::__construct($dataArray, $allowModifications);
  139
+        } else {
  140
+            // Load one or more sections
  141
+            if (!is_array($section)) {
  142
+                $section = array($section);
  143
+            }
  144
+            $dataArray = array();
  145
+            foreach ($section as $sectionName) {
  146
+                if (!isset($iniArray[$sectionName])) {
  147
+                    /**
  148
+                     * @see Zend_Config_Exception
  149
+                     */
  150
+                    require_once 'Zend/Config/Exception.php';
  151
+                    throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename");
  152
+                }
  153
+                $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray);
  154
+
  155
+            }
  156
+            parent::__construct($dataArray, $allowModifications);
  157
+        }
  158
+
  159
+        $this->_loadedSection = $section;
  160
+    }
  161
+
  162
+    /**
  163
+     * Load the INI file from disk using parse_ini_file(). Use a private error
  164
+     * handler to convert any loading errors into a Zend_Config_Exception
  165
+     *
  166
+     * @param string $filename
  167
+     * @throws Zend_Config_Exception
  168
+     * @return array
  169
+     */
  170
+    protected function _parseIniFile($filename)
  171
+    {
  172
+        set_error_handler(array($this, '_loadFileErrorHandler'));
  173
+        $iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed
  174
+        restore_error_handler();
  175
+
  176
+        // Check if there was a error while loading file
  177
+        if ($this->_loadFileErrorStr !== null) {
  178
+            /**
  179
+             * @see Zend_Config_Exception
  180
+             */
  181
+            require_once 'Zend/Config/Exception.php';
  182
+            throw new Zend_Config_Exception($this->_loadFileErrorStr);
  183
+        }
  184
+
  185
+        return $iniArray;
  186
+    }
  187
+
  188
+    /**
  189
+     * Load the ini file and preprocess the section separator (':' in the
  190
+     * section name (that is used for section extension) so that the resultant
  191
+     * array has the correct section names and the extension information is
  192
+     * stored in a sub-key called ';extends'. We use ';extends' as this can
  193
+     * never be a valid key name in an INI file that has been loaded using
  194
+     * parse_ini_file().
  195
+     *
  196
+     * @param string $filename
  197
+     * @throws Zend_Config_Exception
  198
+     * @return array
  199
+     */
  200
+    protected function _loadIniFile($filename)
  201
+    {
  202
+        $loaded = $this->_parseIniFile($filename);
  203
+        $iniArray = array();
  204
+        foreach ($loaded as $key => $data)
  205
+        {
  206
+            $pieces = explode($this->_sectionSeparator, $key);
  207
+            $thisSection = trim($pieces[0]);
  208
+            switch (count($pieces)) {
  209
+                case 1:
  210
+                    $iniArray[$thisSection] = $data;
  211
+                    break;
  212
+
  213
+                case 2:
  214
+                    $extendedSection = trim($pieces[1]);
  215
+                    $iniArray[$thisSection] = array_merge(array(';extends'=>$extendedSection), $data);
  216
+                    break;
  217
+
  218
+                default:
  219
+                    /**
  220
+                     * @see Zend_Config_Exception
  221
+                     */
  222
+                    require_once 'Zend/Config/Exception.php';
  223
+                    throw new Zend_Config_Exception("Section '$thisSection' may not extend multiple sections in $filename");
  224
+            }
  225
+        }
  226
+
  227
+        return $iniArray;
  228
+    }
  229
+
  230
+    /**
  231
+     * Process each element in the section and handle the ";extends" inheritance
  232
+     * key. Passes control to _processKey() to handle the nest separator
  233
+     * sub-property syntax that may be used within the key name.
  234
+     *
  235
+     * @param  array  $iniArray
  236
+     * @param  string $section
  237
+     * @param  array  $config
  238
+     * @throws Zend_Config_Exception
  239
+     * @return array
  240
+     */
  241
+    protected function _processSection($iniArray, $section, $config = array())
  242
+    {
  243
+        $thisSection = $iniArray[$section];
  244
+
  245
+        foreach ($thisSection as $key => $value) {
  246
+            if (strtolower($key) == ';extends') {
  247
+                if (isset($iniArray[$value])) {
  248
+                    $this->_assertValidExtend($section, $value);
  249
+
  250
+                    if (!$this->_skipExtends) {
  251
+                        $config = $this->_processSection($iniArray, $value, $config);
  252
+                    }
  253
+                } else {
  254
+                    /**
  255
+                     * @see Zend_Config_Exception
  256
+                     */
  257
+                    require_once 'Zend/Config/Exception.php';
  258
+                    throw new Zend_Config_Exception("Parent section '$section' cannot be found");
  259
+                }
  260
+            } else {
  261
+                $config = $this->_processKey($config, $key, $value);
  262
+            }
  263
+        }
  264
+        return $config;
  265
+    }
  266
+
  267
+    /**
  268
+     * Assign the key's value to the property list. Handles the
  269
+     * nest separator for sub-properties.
  270
+     *
  271
+     * @param  array  $config
  272
+     * @param  string $key
  273
+     * @param  string $value
  274
+     * @throws Zend_Config_Exception
  275
+     * @return array
  276
+     */
  277
+    protected function _processKey($config, $key, $value)
  278
+    {
  279
+        if (strpos($key, $this->_nestSeparator) !== false) {
  280
+            $pieces = explode($this->_nestSeparator, $key, 2);
  281
+            if (strlen($pieces[0]) && strlen($pieces[1])) {
  282
+                if (!isset($config[$pieces[0]])) {
  283
+                    if ($pieces[0] === '0' && !empty($config)) {
  284
+                        // convert the current values in $config into an array
  285
+                        $config = array($pieces[0] => $config);
  286
+                    } else {
  287
+                        $config[$pieces[0]] = array();
  288
+                    }
  289
+                } elseif (!is_array($config[$pieces[0]])) {
  290
+                    /**
  291
+                     * @see Zend_Config_Exception
  292
+                     */
  293
+                    require_once 'Zend/Config/Exception.php';
  294
+                    throw new Zend_Config_Exception("Cannot create sub-key for '{$pieces[0]}' as key already exists");
  295
+                }
  296
+                $config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value);
  297
+            } else {
  298
+                /**
  299
+                 * @see Zend_Config_Exception
  300
+                 */
  301
+                require_once 'Zend/Config/Exception.php';
  302
+                throw new Zend_Config_Exception("Invalid key '$key'");
  303
+            }
  304
+        } else {
  305
+            $config[$key] = $value;
  306
+        }
  307
+        return $config;
  308
+    }
  309
+}
240  Config/Json.php
... ...
@@ -0,0 +1,240 @@
  1
+<?php
  2
+/**
  3
+ * Zend Framework
  4
+ *
  5
+ * LICENSE
  6
+ *
  7
+ * This source file is subject to the new BSD license that is bundled
  8
+ * with this package in the file LICENSE.txt.
  9
+ * It is also available through the world-wide-web at this URL:
  10
+ * http://framework.zend.com/license/new-bsd
  11
+ * If you did not receive a copy of the license and are unable to
  12
+ * obtain it through the world-wide-web, please send an email
  13
+ * to license@zend.com so we can send you a copy immediately.
  14
+ *
  15
+ * @category  Zend
  16
+ * @package   Zend_Config
  17
+ * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18
+ * @license   http://framework.zend.com/license/new-bsd     New BSD License
  19
+ * @version   $Id: Json.php 23294 2010-11-05 00:27:34Z ramon $
  20
+ */
  21
+
  22
+/**
  23
+ * @see Zend_Config
  24
+ */
  25
+require_once 'Zend/Config.php';
  26
+
  27
+/**
  28
+ * @see Zend_Json
  29
+ */
  30
+require_once 'Zend/Json.php';
  31
+
  32
+/**
  33
+ * JSON Adapter for Zend_Config
  34
+ *
  35
+ * @category  Zend
  36
+ * @package   Zend_Config
  37
+ * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  38
+ * @license   http://framework.zend.com/license/new-bsd     New BSD License
  39
+ */
  40
+class Zend_Config_Json extends Zend_Config
  41
+{
  42
+    /**
  43
+     * Name of object key indicating section current section extends
  44
+     */
  45
+    const EXTENDS_NAME = "_extends";
  46
+
  47
+    /**
  48
+     * Whether or not to ignore constants in the JSON string
  49
+     *
  50
+     * Note: if you do not have constant names in quotations in your JSON
  51
+     * string, they may lead to syntax errors when parsing.
  52
+     *
  53
+     * @var bool
  54
+     */
  55
+    protected $_ignoreConstants = false;
  56
+
  57
+    /**
  58
+     * Whether to skip extends or not
  59
+     *
  60
+     * @var boolean
  61
+     */
  62
+    protected $_skipExtends = false;
  63
+
  64
+    /**
  65
+     * Loads the section $section from the config file encoded as JSON
  66
+     *
  67
+     * Sections are defined as properties of the main object
  68
+     *
  69
+     * In order to extend another section, a section defines the "_extends"
  70
+     * property having a value of the section name from which the extending
  71
+     * section inherits values.
  72
+     *
  73
+     * Note that the keys in $section will override any keys of the same
  74
+     * name in the sections that have been included via "_extends".
  75
+     *
  76
+     * @param  string  $json     JSON file or string to process
  77
+     * @param  mixed   $section Section to process
  78
+     * @param  boolean $options Whether modifiacations are allowed at runtime
  79
+     * @throws Zend_Config_Exception When JSON text is not set or cannot be loaded
  80
+     * @throws Zend_Config_Exception When section $sectionName cannot be found in $json
  81
+     */
  82
+    public function __construct($json, $section = null, $options = false)
  83
+    {
  84
+        if (empty($json)) {
  85
+            require_once 'Zend/Config/Exception.php';
  86
+            throw new Zend_Config_Exception('Filename is not set');
  87
+        }
  88
+
  89
+        $allowModifications = false;
  90
+        if (is_bool($options)) {
  91
+            $allowModifications = $options;
  92
+        } elseif (is_array($options)) {
  93
+            foreach ($options as $key => $value) {
  94
+                switch (strtolower($key)) {
  95
+                    case 'allow_modifications':
  96
+                    case 'allowmodifications':
  97
+                        $allowModifications = (bool) $value;
  98
+                        break;
  99
+                    case 'skip_extends':
  100
+                    case 'skipextends':
  101
+                        $this->_skipExtends = (bool) $value;
  102
+                        break;
  103
+                    case 'ignore_constants':
  104
+                    case 'ignoreconstants':
  105
+                        $this->_ignoreConstants = (bool) $value;
  106
+                        break;
  107
+                    default:
  108
+                        break;
  109
+                }
  110
+            }
  111
+        }
  112
+
  113
+        set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed
  114
+        if ($json[0] != '{') {
  115
+            $json = file_get_contents($json);
  116
+        }
  117
+        restore_error_handler();
  118
+
  119
+        // Check if there was a error while loading file
  120
+        if ($this->_loadFileErrorStr !== null) {
  121
+            require_once 'Zend/Config/Exception.php';
  122
+            throw new Zend_Config_Exception($this->_loadFileErrorStr);
  123
+        }
  124
+
  125
+        // Replace constants
  126
+        if (!$this->_ignoreConstants) {
  127
+            $json = $this->_replaceConstants($json);
  128
+        }
  129
+
  130
+        // Parse/decode
  131
+        $config = Zend_Json::decode($json);
  132
+
  133
+        if (null === $config) {
  134
+            // decode failed
  135
+            require_once 'Zend/Config/Exception.php';
  136
+            throw new Zend_Config_Exception("Error parsing JSON data");
  137
+        }
  138
+
  139
+        if ($section === null) {
  140
+            $dataArray = array();
  141
+            foreach ($config as $sectionName => $sectionData) {
  142
+                $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
  143
+            }
  144
+
  145
+            parent::__construct($dataArray, $allowModifications);
  146
+        } elseif (is_array($section)) {
  147
+            $dataArray = array();
  148
+            foreach ($section as $sectionName) {
  149
+                if (!isset($config[$sectionName])) {
  150
+                    require_once 'Zend/Config/Exception.php';
  151
+                    throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $sectionName));
  152
+                }
  153
+
  154
+                $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
  155
+            }
  156
+
  157
+            parent::__construct($dataArray, $allowModifications);
  158
+        } else {
  159
+            if (!isset($config[$section])) {
  160
+                require_once 'Zend/Config/Exception.php';
  161
+                throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
  162
+            }
  163
+
  164
+            $dataArray = $this->_processExtends($config, $section);
  165
+            if (!is_array($dataArray)) {
  166
+                // Section in the JSON data contains just one top level string
  167
+                $dataArray = array($section => $dataArray);
  168
+            }
  169
+
  170
+            parent::__construct($dataArray, $allowModifications);
  171
+        }
  172
+
  173
+        $this->_loadedSection = $section;
  174
+    }
  175
+
  176
+    /**
  177
+     * Helper function to process each element in the section and handle
  178
+     * the "_extends" inheritance attribute.
  179
+     *
  180
+     * @param  array            $data Data array to process
  181
+     * @param  string           $section Section to process
  182
+     * @param  array            $config  Configuration which was parsed yet
  183
+     * @throws Zend_Config_Exception When $section cannot be found
  184
+     * @return array
  185
+     */
  186
+    protected function _processExtends(array $data, $section, array $config = array())
  187
+    {
  188
+        if (!isset($data[$section])) {
  189
+            require_once 'Zend/Config/Exception.php';
  190
+            throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
  191
+        }
  192
+
  193
+        $thisSection  = $data[$section];
  194
+
  195
+        if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) {
  196
+            if (is_array($thisSection[self::EXTENDS_NAME])) {
  197
+                require_once 'Zend/Config/Exception.php';
  198
+                throw new Zend_Config_Exception('Invalid extends clause: must be a string; array received');
  199
+            }
  200
+            $this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]);
  201
+
  202
+            if (!$this->_skipExtends) {
  203
+                $config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config);
  204
+            }
  205
+            unset($thisSection[self::EXTENDS_NAME]);
  206
+        }
  207
+
  208
+        $config = $this->_arrayMergeRecursive($config, $thisSection);
  209
+
  210
+        return $config;
  211
+    }
  212
+
  213
+    /**
  214
+     * Replace any constants referenced in a string with their values
  215
+     *
  216
+     * @param  string $value
  217
+     * @return string
  218
+     */
  219
+    protected function _replaceConstants($value)
  220
+    {
  221
+        foreach ($this->_getConstants() as $constant) {
  222
+            if (strstr($value, $constant)) {
  223
+                $value = str_replace($constant, constant($constant), $value);
  224
+            }
  225
+        }
  226
+        return $value;
  227
+    }
  228
+
  229
+    /**
  230
+     * Get (reverse) sorted list of defined constant names
  231
+     *
  232
+     * @return array
  233
+     */
  234
+    protected function _getConstants()
  235
+    {
  236
+        $constants = array_keys(get_defined_constants());
  237
+        rsort($constants, SORT_STRING);
  238
+        return $constants;
  239
+    }
  240
+}
101  Config/Writer.php
... ...
@@ -0,0 +1,101 @@
  1
+<?php
  2
+/**
  3
+ * Zend Framework
  4
+ *
  5
+ * LICENSE
  6
+ *
  7
+ * This source file is subject to the new BSD license that is bundled
  8
+ * with this package in the file LICENSE.txt.
  9
+ * It is also available through the world-wide-web at this URL:
  10
+ * http://framework.zend.com/license/new-bsd
  11
+ * If you did not receive a copy of the license and are unable to
  12
+ * obtain it through the world-wide-web, please send an email
  13
+ * to license@zend.com so we can send you a copy immediately.
  14
+ *
  15
+ * @category   Zend
  16
+ * @package    Zend_Config
  17
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19
+ * @version    $Id: Writer.php 23953 2011-05-03 05:47:39Z ralph $
  20
+ */
  21
+
  22
+/**
  23
+ * @category   Zend
  24
+ * @package    Zend_Config
  25
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  26
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  27
+ */
  28
+abstract class Zend_Config_Writer
  29
+{
  30
+    /**
  31
+     * Option keys to skip when calling setOptions()
  32
+     *
  33
+     * @var array
  34
+     */
  35
+    protected $_skipOptions = array(
  36
+        'options'
  37
+    );
  38
+
  39
+    /**
  40
+     * Config object to write
  41
+     *
  42
+     * @var Zend_Config
  43
+     */
  44
+    protected $_config = null;
  45
+
  46
+    /**
  47
+     * Create a new adapter
  48
+     *
  49
+     * $options can only be passed as array or be omitted
  50
+     *
  51
+     * @param null|array $options
  52
+     */
  53
+    public function __construct(array $options = null)
  54
+    {
  55
+        if (is_array($options)) {
  56
+            $this->setOptions($options);
  57
+        }
  58
+    }
  59
+
  60
+    /**
  61
+     * Set options via a Zend_Config instance
  62
+     *
  63
+     * @param  Zend_Config $config
  64
+     * @return Zend_Config_Writer
  65
+     */
  66
+    public function setConfig(Zend_Config $config)
  67
+    {
  68
+        $this->_config = $config;
  69
+
  70
+        return $this;
  71
+    }
  72
+
  73
+    /**
  74
+     * Set options via an array
  75
+     *
  76
+     * @param  array $options
  77
+     * @return Zend_Config_Writer
  78
+     */
  79
+    public function setOptions(array $options)
  80
+    {
  81
+        foreach ($options as $key => $value) {
  82
+            if (in_array(strtolower($key), $this->_skipOptions)) {
  83
+                continue;
  84
+            }
  85
+
  86
+            $method = 'set' . ucfirst($key);
  87
+            if (method_exists($this, $method)) {
  88
+                $this->$method($value);
  89
+            }
  90
+        }
  91
+
  92
+        return $this;
  93
+    }
  94
+
  95
+    /**
  96
+     * Write a Zend_Config object to it's target
  97
+     *
  98
+     * @return void
  99
+     */
  100
+    abstract public function write();
  101
+}
55  Config/Writer/Array.php
... ...
@@ -0,0 +1,55 @@
  1
+<?php
  2
+/**
  3
+ * Zend Framework
  4
+ *
  5
+ * LICENSE
  6
+ *
  7
+ * This source file is subject to the new BSD license that is bundled
  8
+ * with this package in the file LICENSE.txt.
  9
+ * It is also available through the world-wide-web at this URL:
  10
+ * http://framework.zend.com/license/new-bsd
  11
+ * If you did not receive a copy of the license and are unable to
  12
+ * obtain it through the world-wide-web, please send an email
  13
+ * to license@zend.com so we can send you a copy immediately.
  14
+ *
  15
+ * @category   Zend
  16
+ * @package    Zend_Config
  17
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19
+ * @version    $Id: Array.php 23775 2011-03-01 17:25:24Z ralph $
  20
+ */
  21
+
  22
+/**
  23
+ * @see Zend_Config_Writer
  24
+ */
  25
+require_once 'Zend/Config/Writer/FileAbstract.php';
  26
+
  27
+/**
  28
+ * @category   Zend
  29
+ * @package    Zend_Config
  30
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  31
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  32
+ */
  33
+class Zend_Config_Writer_Array extends Zend_Config_Writer_FileAbstract
  34
+{
  35
+    /**
  36
+     * Render a Zend_Config into a PHP Array config string.
  37
+     *
  38
+     * @since 1.10
  39
+     * @return string
  40
+     */
  41
+    public function render()
  42
+    {
  43
+        $data        = $this->_config->toArray();
  44
+        $sectionName = $this->_config->getSectionName();
  45
+
  46
+        if (is_string($sectionName)) {
  47
+            $data = array($sectionName => $data);
  48
+        }
  49
+
  50
+        $arrayString = "<?php\n"
  51
+                     . "return " . var_export($data, true) . ";\n";
  52
+
  53
+        return $arrayString;
  54
+    }
  55
+}
134  Config/Writer/FileAbstract.php
... ...
@@ -0,0 +1,134 @@
  1
+<?php
  2
+/**
  3
+ * Zend Framework
  4
+ *
  5
+ * LICENSE
  6
+ *
  7
+ * This source file is subject to the new BSD license that is bundled
  8
+ * with this package in the file LICENSE.txt.
  9
+ * It is also available through the world-wide-web at this URL:
  10
+ * http://framework.zend.com/license/new-bsd
  11
+ * If you did not receive a copy of the license and are unable to
  12
+ * obtain it through the world-wide-web, please send an email
  13
+ * to license@zend.com so we can send you a copy immediately.
  14
+ *
  15
+ * @category   Zend
  16
+ * @package    Zend_Config
  17
+ * @package    Writer
  18
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20
+ */
  21
+
  22
+require_once "Zend/Config/Writer.php";
  23
+
  24
+/**
  25
+ * Abstract File Writer
  26
+ *
  27
+ * @category   Zend
  28
+ * @package    Zend_package
  29
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  31
+ * @version    $Id: FileAbstract.php 23775 2011-03-01 17:25:24Z ralph $
  32
+ */
  33
+class Zend_Config_Writer_FileAbstract extends Zend_Config_Writer
  34
+{
  35
+    /**
  36
+     * Filename to write to
  37
+     *
  38
+     * @var string
  39
+     */
  40
+    protected $_filename = null;
  41
+
  42
+    /**
  43
+     * Wether to exclusively lock the file or not
  44
+     *
  45
+     * @var boolean
  46
+     */
  47
+    protected $_exclusiveLock = false;
  48
+
  49
+    /**
  50
+     * Set the target filename
  51
+     *
  52
+     * @param  string $filename
  53
+     * @return Zend_Config_Writer_Array
  54
+     */
  55
+    public function setFilename($filename)
  56
+    {
  57
+        $this->_filename = $filename;
  58
+
  59
+        return $this;
  60
+    }
  61
+
  62
+    /**
  63
+     * Set wether to exclusively lock the file or not
  64
+     *
  65
+     * @param  boolean     $exclusiveLock
  66
+     * @return Zend_Config_Writer_Array
  67
+     */
  68
+    public function setExclusiveLock($exclusiveLock)
  69
+    {
  70
+        $this->_exclusiveLock = $exclusiveLock;
  71
+
  72
+        return $this;
  73
+    }
  74
+
  75
+    /**
  76
+     * Write configuration to file.
  77
+     *
  78
+     * @param string $filename
  79
+     * @param Zend_Config $config
  80
+     * @param bool $exclusiveLock
  81
+     * @return void
  82
+     */
  83
+    public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null)
  84
+    {
  85
+        if ($filename !== null) {
  86
+            $this->setFilename($filename);
  87
+        }
  88
+
  89
+        if ($config !== null) {
  90
+            $this->setConfig($config);
  91
+        }
  92
+
  93
+        if ($exclusiveLock !== null) {
  94
+            $this->setExclusiveLock($exclusiveLock);
  95
+        }
  96
+
  97
+        if ($this->_filename === null) {
  98
+            require_once 'Zend/Config/Exception.php';
  99
+            throw new Zend_Config_Exception('No filename was set');
  100
+        }
  101
+
  102
+        if ($this->_config === null) {
  103
+            require_once 'Zend/Config/Exception.php';
  104
+            throw new Zend_Config_Exception('No config was set');
  105
+        }
  106
+
  107
+        $configString = $this->render();
  108
+
  109
+        $flags = 0;
  110
+
  111
+        if ($this->_exclusiveLock) {
  112
+            $flags |= LOCK_EX;
  113
+        }
  114
+
  115
+        $result = @file_put_contents($this->_filename, $configString, $flags);
  116
+
  117
+        if ($result === false) {
  118
+            require_once 'Zend/Config/Exception.php';
  119
+            throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
  120
+        }
  121
+    }
  122
+
  123
+    /**
  124
+     * Render a Zend_Config into a config file string.
  125
+     *
  126
+     * @since 1.10
  127
+     * @todo For 2.0 this should be redone into an abstract method.
  128
+     * @return string
  129
+     */
  130
+    public function render()
  131
+    {
  132
+        return "";
  133
+    }
  134
+}
193  Config/Writer/Ini.php
... ...
@@ -0,0 +1,193 @@
  1
+<?php
  2
+/**
  3
+ * Zend Framework
  4
+ *
  5
+ * LICENSE
  6
+ *
  7
+ * This source file is subject to the new BSD license that is bundled
  8
+ * with this package in the file LICENSE.txt.
  9
+ * It is also available through the world-wide-web at this URL:
  10
+ * http://framework.zend.com/license/new-bsd
  11
+ * If you did not receive a copy of the license and are unable to
  12
+ * obtain it through the world-wide-web, please send an email
  13
+ * to license@zend.com so we can send you a copy immediately.
  14
+ *
  15
+ * @category   Zend
  16
+ * @package    Zend_Config
  17
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19
+ * @version    $Id: Ini.php 23775 2011-03-01 17:25:24Z ralph $
  20
+ */
  21
+
  22
+/**
  23
+ * @see Zend_Config_Writer
  24
+ */
  25
+require_once 'Zend/Config/Writer/FileAbstract.php';
  26
+
  27
+/**
  28
+ * @category   Zend
  29
+ * @package    Zend_Config
  30
+ * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  31
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  32
+ */
  33
+class Zend_Config_Writer_Ini extends Zend_Config_Writer_FileAbstract
  34
+{
  35
+    /**
  36
+     * String that separates nesting levels of configuration data identifiers
  37
+     *
  38
+     * @var string
  39
+     */
  40
+    protected $_nestSeparator = '.';
  41
+
  42
+    /**
  43
+     * If true the ini string is rendered in the global namespace without sections.
  44
+     *
  45
+     * @var bool
  46
+     */
  47
+    protected $_renderWithoutSections = false;
  48
+
  49
+    /**
  50
+     * Set the nest separator
  51
+     *
  52
+     * @param  string $filename
  53
+     * @return Zend_Config_Writer_Ini
  54
+     */
  55
+    public function setNestSeparator($separator)
  56
+    {
  57
+        $this->_nestSeparator = $separator;
  58
+
  59
+        return $this;
  60
+    }
  61
+
  62
+    /**
  63
+     * Set if rendering should occour without sections or not.
  64
+     *
  65
+     * If set to true, the INI file is rendered without sections completely
  66
+     * into the global namespace of the INI file.
  67
+     *
  68
+     * @param  bool $withoutSections
  69
+     * @return Zend_Config_Writer_Ini
  70
+     */
  71
+    public function setRenderWithoutSections($withoutSections=true)
  72
+    {
  73
+        $this->_renderWithoutSections = (bool)$withoutSections;
  74
+        return $this;
  75
+    }
  76
+
  77
+    /**
  78
+     * Render a Zend_Config into a INI config string.
  79
+     *
  80
+     * @since 1.10
  81
+     * @return string
  82
+     */
  83
+    public function render()
  84
+    {
  85
+        $iniString   = '';
  86
+        $extends     = $this->_config->getExtends();
  87
+        $sectionName = $this->_config->getSectionName();
  88
+
  89
+        if($this->_renderWithoutSections == true) {
  90
+            $iniString .= $this->_addBranch($this->_config);
  91
+        } else if (is_string($sectionName)) {
  92
+            $iniString .= '[' . $sectionName . ']' . "\n"
  93
+                       .  $this->_addBranch($this->_config)
  94
+                       .  "\n";
  95
+        } else {
  96
+            $config = $this->_sortRootElements($this->_config);
  97
+            foreach ($config as $sectionName => $data) {
  98
+                if (!($data instanceof Zend_Config)) {
  99
+                    $iniString .= $sectionName
  100
+                               .  ' = '
  101
+                               .  $this->_prepareValue($data)
  102
+                               .  "\n";
  103
+                } else {
  104
+                    if (isset($extends[$sectionName])) {
  105
+                        $sectionName .= ' : ' . $extends[$sectionName];
  106
+                    }
  107
+
  108
+                    $iniString .= '[' . $sectionName . ']' . "\n"
  109
+                               .  $this->_addBranch($data)
  110
+                               .  "\n";
  111
+                }
  112
+            }
  113
+        }
  114
+
  115
+        return $iniString;
  116
+    }
  117
+
  118
+    /**
  119
+     * Add a branch to an INI string recursively
  120
+     *
  121
+     * @param  Zend_Config $config
  122
+     * @return void
  123
+     */
  124
+    protected function _addBranch(Zend_Config $config, $parents = array())
  125
+    {
  126
+        $iniString = '';
  127
+
  128
+        foreach ($config as $key => $value) {
  129
+            $group = array_merge($parents, array($key));
  130
+
  131
+            if ($value instanceof Zend_Config) {
  132
+                $iniString .= $this->_addBranch($value, $group);
  133
+            } else {
  134
+                $iniString .= implode($this->_nestSeparator, $group)
  135
+                           .  ' = '
  136
+                           .  $this->_prepareValue($value)
  137
+                           .  "\n";
  138
+            }
  139
+        }
  140
+
  141
+        return $iniString;
  142
+    }
  143
+
  144
+    /**
  145
+     * Prepare a value for INI
  146
+     *
  147
+     * @param  mixed $value
  148
+     * @return string
  149
+     */
  150
+    protected function _prepareValue($value)
  151
+    {
  152
+        if (is_integer($value) || is_float($value)) {
  153
+            return $value;
  154
+        } elseif (is_bool($value)) {
  155
+            return ($value ? 'true' : 'false');
  156
+        } elseif (strpos($value, '"') === false) {
  157
+            return '"' . $value .  '"';
  158
+        } else {
  159
+            /** @see Zend_Config_Exception */
  160
+            require_once 'Zend/Config/Exception.php';
  161
+            throw new Zend_Config_Exception('Value can not contain double quotes "');
  162
+        }
  163
+    }
  164
+
  165
+    /**
  166
+     * Root elements that are not assigned to any section needs to be
  167
+     * on the top of config.
  168
+     *
  169
+     * @see    http://framework.zend.com/issues/browse/ZF-6289
  170
+     * @param  Zend_Config
  171
+     * @return Zend_Config
  172
+     */
  173
+    protected function _sortRootElements(Zend_Config $config)
  174
+    {
  175
+        $configArray = $config->toArray();
  176
+        $sections = array();
  177
+
  178
+        // remove sections from config array
  179
+        foreach ($configArray as $key => $value) {
  180
+            if (is_array($value)) {
  181
+                $sections[$key] = $value;
  182
+                unset($configArray[$key]);
  183
+            }
  184
+        }
  185
+
  186
+        // readd sections to the end
  187
+        foreach ($sections as $key => $value) {
  188
+            $configArray[$key] = $value;
  189
+        }
  190
+
  191
+        return new Zend_Config($configArray);
  192
+    }
  193
+}
106  Config/Writer/Json.php
... ...
@@ -0,0 +1,106 @@
  1
+<?php
  2
+/**
  3
+ * Zend Framework
  4
+ *
  5
+ * LICENSE
  6
+ *
  7
+ * This source file is subject to the new BSD license that is bundled
  8
+ * with this package in the file LICENSE.txt.
  9
+ * It is also available through the world-wide-web at this URL:
  10
+ * http://framework.zend.com/license/new-bsd
  11
+ * If you did not receive a copy of the license and are unable to
  12
+ * obtain it through the world-wide-web, please send an email
  13
+ * to license@zend.com so we can send you a copy immediately.
  14
+ *
  15
+ * @category   Zend
  16
+ * @package    Zend_Config
  17
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19
+ * @version    $Id: Json.php 23294 2010-11-05 00:27:34Z ramon $
  20
+ */
  21
+
  22
+/**
  23
+ * @see Zend_Config_Writer
  24
+ */
  25
+require_once 'Zend/Config/Writer/FileAbstract.php';
  26
+
  27
+/**
  28
+ * @see Zend_Config_Json
  29
+ */
  30
+require_once 'Zend/Config/Json.php';
  31
+
  32
+/**
  33
+ * @category   Zend
  34
+ * @package    Zend_Config
  35
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  36
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
  37
+ */
  38
+class Zend_Config_Writer_Json extends Zend_Config_Writer_FileAbstract
  39
+{
  40
+    /**
  41
+     * If we need to pretty-print JSON data
  42
+     *
  43
+     * @var boolean
  44
+     */
  45
+    protected $_prettyPrint = false;
  46
+
  47
+    /**