function init() { $dsn = \woo\base\ApplicationRegistry::getDSN(); if (!is_null($dsn)) { return; } $this->getOptions(); }
function init() { $dsn = ApplicationRegistry::getDSN(); if (!is_null($dsn)) { // Данные хранятся в кэше return; } $this->getOptions(); }
function __construct() { $dsn = ApplicationRegistry::getDSN(); if (is_null($dsn)) { throw new AppException('DSN не задан'); } self::$DB = new \PDO($dsn); self::$DB->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); }
function __construct() { if (!isset(self::$PDO)) { $dsn = \woo\base\ApplicationRegistry::getDSN(); if (is_null($dsn)) { throw new \woo\base\AppException("No DSN"); } self::$PDO = new \PDO($dsn); self::$PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } }
function __construct() { if (!isset(self::$PDO)) { $dsn = ApplicationRegistry::getDSN(); if (is_null($dsn)) { throw new AppException('DSN не определен'); } self::$PDO = new \PDO($dsn); self::$PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } }
<?php require_once "listing12.05.php"; // Registry // test file app registry if (!isset($argv[1])) { // run script without argument to monitor while (1) { sleep(5); $thing = \woo\base\ApplicationRegistry::getDSN(); \woo\base\RequestRegistry::instance(); \woo\base\SessionRegistry::instance(); \woo\base\MemApplicationRegistry::instance(); print "dsn is {$thing}\n"; } } else { // run script with argument in separate window to change value.. see the result in monitor process print "setting dsn {$argv[1]}\n"; \woo\base\ApplicationRegistry::setDSN($argv[1]); }