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 handleRequest() { $request = new Request(); $app_c = \woo\base\ApplicationRegistry::appController(); while ($cmd = $app_c->getCommand($request)) { $cmd->execute($request); } $this->invokeView($app_c->getView($request)); }
private function getOptions() { $this->ensure(file_exists($this->config), "Could not find options file"); $options = SimpleXml_load_file($this->config); print get_class($options); $dsn = (string) $options->dsn; $this->ensure($dsn, "No DSN found"); \woo\base\ApplicationRegistry::setDSN($dsn); // set other values }
function handleRequest() { $request = new Request(); $app_c = \woo\base\ApplicationRegistry::appController(); while ($cmd = $app_c->getCommand($request)) { $cmd->execute($request); } \woo\domain\ObjectWatcher::instance()->performOperations(); $this->invokeView($app_c->getView($request)); }
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); } }
function handleRequest() { $request = new Request(); $app_c = ApplicationRegistry::appController(); while ($cmd = $app_c->getCommand($request)) { print 'Выполняется ' . get_class($cmd) . '\\n'; $cmd->execute($request); } $this->invokeView($app_c->getView()); // $cmd_r = new CommandResolver(); // $cmd = $cmd_r->getCommand($request); // $cmd->execute($request); }
private function getOptions() { $this->ensure(file_exists($this->config), 'Файл конфигурации не найден'); $options = simplexml_load_file($this->config); print get_class($options); $dsn = (string) $options->dsn; $this->ensure($options instanceof \SimpleXMLElement, 'Файл конфигурации запорчен'); $this->ensure($dsn, 'DSN не найден'); ApplicationRegistry::setDSN($dsn); $map = new ControllerMap(); foreach ($options->control->view as $default_view) { $stat_str = trim($default_view['status']); $status = Command::statues($stat_str); $map->addView('default', $status, (string) $default_view); } // анализ остальных кодов ApplicationRegistry::setControllerMap($map); }
private function getOptions() { $this->ensure(file_exists($this->config), "Could not find options file"); $options = @SimpleXml_load_file($this->config); // $this->ensure( $options instanceof SimpleXMLElement, // "Could not resolve options file" ); $dsn = (string) $options->dsn; $this->ensure($dsn, "No DSN found"); \woo\base\ApplicationRegistry::setDSN($dsn); $map = new ControllerMap(); foreach ($options->control->view as $default_view) { $stat_str = trim($default_view['status']); $status = \woo\command\Command::statuses($stat_str); $map->addView('default', $status, (string) $default_view); } foreach ($options->control->command as $command_view) { $command = trim((string) $command_view['name']); if ($command_view->classalias) { $classroot = trim((string) $command_view->classalias['name']); $map->addClassroot($command, $classroot); } if ($command_view->view) { $view = trim((string) $command_view->view); $forward = trim((string) $command_view->forward); $map->addView($command, 0, $view); if ($forward) { $map->addForward($command, 0, $forward); } foreach ($command_view->status as $command_view_status) { $view = trim((string) $command_view_status->view); $forward = trim((string) $command_view_status->forward); $stat_str = trim($command_view_status['value']); $status = \woo\command\Command::statuses($stat_str); if ($view) { $map->addView($command, $status, $view); } if ($forward) { $map->addForward($command, $status, $forward); } } } } \woo\base\ApplicationRegistry::setControllerMap($map); }
<?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]); }