Alternatif olarak, yerine Zend_Registry kullanmak ayrıca ilgili verileri erişmek için izin kamu üye fonksiyonları ile tüm uygulama bilgileri, içerecek bir tek uygulama sınıf oluşturabilir. Eğer (bu sadece size bunun nasıl uygulanabileceği bir fikir vermek için, olduğu gibi çalışmaz) ilgili koduyla bir pasajı bulabilirsiniz:
final class Application
{
/**
* @var Zend_Config
*/
private $config = null;
/**
* @var Application
*/
private static $application;
// snip
/**
* @return Zend_Config
*/
public function getConfig()
{
if (!$this->config instanceof Zend_Config) {
$this->initConfig();
}
return $this->config;
}
/**
* @return Application
*/
public static function getInstance()
{
if (self::$application === null) {
self::$application = new Application();
}
return self::$application;
}
/**
* Load Configuration
*/
private function initConfig()
{
$configFile = $this->appDir . '/config/application.xml';
if (!is_readable($configFile)) {
throw new Application_Exception('Config file "' . $configFile . '" is not readable');
}
$config = new Zend_Config_Xml($configFile, 'test');
$this->config = $config;
}
// snip
/**
* @param string $appDir
*/
public function init($appDir)
{
$this->appDir = $appDir;
$this->initConfig();
// snip
}
public function run ($appDir)
{
$this->init($appDir);
$front = $this->initController();
$front->dispatch();
}
}
Sizin önyükleme gibi olacaktır:
require 'Application.php';
try {
Application::getInstance()->run(dirname(dirname(__FILE__)));
} catch (Exception $e) {
header("HTTP/1.x 500 Internal Server Error");
trigger_error('Application Error : '.$e->getMessage(), E_USER_ERROR);
}
Eğer yapılandırma erişmek istediğinizde aşağıdakileri kullanabilirsiniz:
$var = Application::getInstance()->getConfig()->somevar;