cross-language data interchange format.
Zend_Config_Json is a
Zend_Config extension using JSON
as its serialization format.
The following is a JSON version of a standard application configuration.
To utilize it, you simply instantiate
it to the location of this file and indicating the section of the file to load. By
default, constant names found in values will be substituted with their appropriate
$config = new Zend_Config_Json(
APPLICATION_PATH . '/configs/application.json',
Once instantiated, you use it as you would any other configuration object.
$db = Zend_Db::factory($config->resources->db);
|Use Constants With Care|
JSON has a strict structure with regards to data types. As such, you need to ensure that your constants are use correctly. For constants that have string values, put your constant values in double quotes (""). For non-string values, you can omit the quotes -- but be absolutely certain that they are not returning strings, as otherwise you will encounter parser errors with your configuration file. When in doubt, enclose the contant in double quotes.
The following options may be passed as keys to the third,
argument of the constructor.
The default behavior of
Zend_Config is to mark the
object as immutable once loaded. Passing this flag with a boolean
true will enable modifications to the object.
By default, any time a section extends another,
Zend_Config will merge the section with the section
it extends. Speciying a boolean
true value to this
option will disable this feature, giving you only the configuration defined
explicitly in that section.
Zend_Config_Json will replace constant
names found in values with the defined constant value. You map pass a
true to this option to disable this
Please note that ignoring constants can potentially lead to parse errors, particularly if you are using constants for integer, float, or boolean values. The safest practice is to enclose constants within quotes.
__construct($json, $section = null, $options = false);
$json should be either a valid
JSON string, or refer to a valid filesystem location
containing a JSON configuration file.
$section, if specified, indicates a specific section of
the configuration file to use.
$options is discussed in
This static function may be used to globally override
the default settings for how constants found in JSON
strings are handled. By default, constant names are replaced with the
appropriate constant values; passing a boolean
value to this method will override that behavior. (You can override it
per-instance via the
ignore_constants option as well.)
This static method gives you the current setting for