Extends Zend_Application to work without a config file.
More...
List of all members.
Public Member Functions |
| __construct ($environment, $options=null) |
| Reimplement Zend_Application constructor to look for a Bootstrap.php if one hasn't been specified and attempt to load default options from it.
|
| getConfigFile () |
| Get the configuration file this application instance was first constructed with.
|
| mergeOptions (array $array1, $array2=null, $cache=false) |
| Merge options recursively Extended to support caching of merged result in APC.
|
Protected Member Functions |
| _loadConfig ($file) |
| Load configuration file of options.
|
Protected Attributes |
| $_configFile = null |
Detailed Description
Extends Zend_Application to work without a config file.
P4Cms_Application will look for a Bootstrap.php when options don't explicitly specify one and attempt to load default options from the Bootstrap class via getDefaultOptions().
- Copyright:
- 2011-2012 Perforce Software. All rights reserved
- License:
- Please see LICENSE.txt in top-level folder of this distribution.
- Version:
- 2012.2/486814
Constructor & Destructor Documentation
P4Cms_Application::__construct |
( |
$ |
environment, |
|
|
$ |
options = null |
|
) |
| |
Reimplement Zend_Application constructor to look for a Bootstrap.php if one hasn't been specified and attempt to load default options from it.
- Parameters:
-
string | $environment | application environment. |
string | array | Zend_Config | $options | String path to configuration file, or array/Zend_Config of configuration options |
- Exceptions:
-
Zend_Application_Exception | When invalid options are provided |
- Returns:
- void
{
$this->_environment = (string) $environment;
require_once "P4Cms/Loader.php";
spl_autoload_register(array('P4Cms_Loader', 'autoload'));
if ($options === null) {
$options = array();
} elseif (is_string($options)) {
$this->_configFile = $options;
try {
$options = $this->_loadConfig($options);
} catch (Zend_Config_Exception $e) {
$options = array();
}
} elseif ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (!is_array($options)) {
throw new Zend_Application_Exception(
"Invalid options provided; must be location of config file, " .
"a config object, or an array"
);
}
if (!isset($options['bootstrap']) && class_exists('Bootstrap')) {
$options['bootstrap'] = "Bootstrap.php";
if (method_exists('Bootstrap', 'getDefaultOptions')) {
$defaults = Bootstrap::getDefaultOptions($environment);
$options = $this->mergeOptions($defaults, $options, true);
}
}
$this->setOptions($options);
}
Member Function Documentation
P4Cms_Application::_loadConfig |
( |
$ |
file | ) |
[protected] |
Load configuration file of options.
Extends Zend's _loadConfig to add caching of config data when APC is enabled.
- Parameters:
-
string | $file | the name of the configuration file to load |
- Exceptions:
-
Zend_Application_Exception | When invalid configuration file is provided |
- Returns:
- array the loaded configuration array
{
if (!extension_loaded('apc') || !is_readable($file)) {
return parent::_loadConfig($file);
}
$cacheKey = $file . "-" . $this->getEnvironment() . "-" . filemtime($file);
$cacheData = apc_fetch($cacheKey);
if (is_array($cacheData)) {
return $cacheData;
}
try {
$config = parent::_loadConfig($file);
} catch (Zend_Config_Exception $e) {
$config = array();
}
apc_store($cacheKey, $config);
return $config;
}
P4Cms_Application::getConfigFile |
( |
| ) |
|
Get the configuration file this application instance was first constructed with.
If no configuration file was used (e.g. an array or config object was injected), throws an exception.
- Returns:
- string the configuration file used to construct the application
- Exceptions:
-
Zend_Application_Exception | if no config file was used to construct the application |
{
if (!$this->_configFile) {
throw new Zend_Application_Exception(
"Cannot get the configuration file. No file was passed to application constructor."
);
}
return $this->_configFile;
}
P4Cms_Application::mergeOptions |
( |
array $ |
array1, |
|
|
$ |
array2 = null , |
|
|
$ |
cache = false |
|
) |
| |
Merge options recursively Extended to support caching of merged result in APC.
- Parameters:
-
array | $array1 | array to merge into |
mixed | $array2 | array to merge from |
bool | $cache | enable caching of merged result (defaults to false) |
- Returns:
- array the merged result
{
if (!$cache || !is_array($array2) || empty($array2) || !extension_loaded('apc')) {
return parent::mergeOptions($array1, $array2);
}
$cacheKey = md5(serialize($array1) . serialize($array2));
$cacheData = apc_fetch($cacheKey);
if (is_array($cacheData)) {
return $cacheData;
}
$merged = parent::mergeOptions($array1, $array2);
apc_store($cacheKey, $merged);
return $merged;
}
Member Data Documentation
P4Cms_Application::$_configFile = null [protected] |
The documentation for this class was generated from the following file: