From 9cda60106f4df71ba8ea90d279099c437d5f91ce Mon Sep 17 00:00:00 2001 From: easter Date: Mon, 12 Sep 2016 10:10:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B2=D0=B5=D1=81=D1=82=D0=B8=20=D1=81?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=BD=D1=8B=D0=B9=20=D0=B6=D1=83?= =?UTF-8?q?=D1=80=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 5 +++-- html/default/style2.css | 2 +- inc/classes/Alert.php | 4 ++-- inc/classes/Common.php | 5 +++-- inc/classes/Db.php | 50 +++++++++++++++++++++++++++-------------- inc/classes/Init.php | 44 ++++++++++++++++++------------------ inc/classes/Log.php | 40 +++++++++++++++++++++++++++++---- 7 files changed, 100 insertions(+), 50 deletions(-) diff --git a/composer.json b/composer.json index ff04d5a1..6bd1278f 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,11 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=5.2.11", + "php": ">=5.4.0", + "smottt/wideimage": ">=1.1.1", "mpdf/mpdf": "5.7.4", "components/jquery": "2.1.4", - "monolog/monolog": "1.17.*", + "monolog/monolog": "1.21.x", "ext-mbstring": "*" } } diff --git a/html/default/style2.css b/html/default/style2.css index 0d6e6e9c..62ab9a47 100644 --- a/html/default/style2.css +++ b/html/default/style2.css @@ -810,7 +810,7 @@ table td.homeTD { margin: 0 65px 10px 10px; } -/* css for Notice class */ +/* css for Alert class */ .im-msg-red { background-color: #f2dede; width:96%; diff --git a/inc/classes/Alert.php b/inc/classes/Alert.php index 1699fb1e..25a96572 100644 --- a/inc/classes/Alert.php +++ b/inc/classes/Alert.php @@ -143,7 +143,7 @@ public function info($head, $explanation = '', $force = false) { * @param string $explanation * @param bool $force * - * @return $this + * @return $this|void */ public function success($head, $explanation = '', $force = false) { if ($force) { @@ -161,7 +161,7 @@ public function success($head, $explanation = '', $force = false) { * @param string $explanation * @param bool $force * - * @return $this + * @return $this|void */ public function warning($head, $explanation = '', $force = false) { if ($force) { diff --git a/inc/classes/Common.php b/inc/classes/Common.php index 599e5468..ff034e38 100644 --- a/inc/classes/Common.php +++ b/inc/classes/Common.php @@ -79,7 +79,7 @@ public function getInvoker() { public function __get($k) { //исключение для герета базы или кеша, выполняется всегда - if ($k == 'db' || $k == 'cache' || $k == 'translate') { + if ($k == 'db' || $k == 'cache' || $k == 'translate' || $k == 'log') { return parent::__get($k); } //геттер для модели @@ -91,7 +91,8 @@ public function __get($k) { if (array_key_exists($k, $this->_p)) { $v = $this->_p[$k]; - } else { + } + else { // Получение экземпляра класса для работы с правами пользователей if ($k == 'acl') { $v = $this->{$k} = Zend_Registry::getInstance()->get('acl'); diff --git a/inc/classes/Db.php b/inc/classes/Db.php index 8c97fc00..51135cf9 100644 --- a/inc/classes/Db.php +++ b/inc/classes/Db.php @@ -56,7 +56,7 @@ public function __get($k) { } return $v; } - // Получение перевода + // Получение экземпляра переводчика if ($k == 'translate') { if (array_key_exists($k, $this->_s)) { $v = $this->_s[$k]; @@ -66,6 +66,16 @@ public function __get($k) { } return $v; } + // Получение экземпляра логера + elseif ($k == 'log') { + if (array_key_exists($k, $this->_s)) { + $v = $this->_s[$k]; + } else { + $v = new \Core2\Log(); + $this->_s[$k] = $v; + } + return $v; + } // Получение экземпляра модели текущего модуля elseif (strpos($k, 'data') === 0) { if (array_key_exists($k, $this->_s)) { @@ -107,15 +117,17 @@ protected function establishConnection($database) { return $db; } - /** - * @param string $dbname - * @param string $username - * @param string $password - * @param string $host - * @param string $charset - * @param string $adapter - * @return Zend_Db_Adapter_Abstract - */ + /** + * Установка соединения с произвольной базой MySQL + * @param $dbname + * @param $username + * @param $password + * @param string $host + * @param string $charset + * @param string $adapter + * + * @return void|Zend_Db_Adapter_Abstract + */ public function newConnector($dbname, $username, $password, $host = 'localhost', $charset = 'utf8', $adapter = 'Pdo_Mysql') { $temp = array('host' => $host, 'username' => $username, @@ -126,12 +138,13 @@ public function newConnector($dbname, $username, $password, $host = 'localhost', try { $db = Zend_Db::factory($adapter, $temp); $db->getConnection(); - } catch (Zend_Db_Adapter_Exception $e) { - Error::catchDbException($e); - } catch (Zend_Exception $e) { - Error::catchZendException($e); - } - return $db; + return $db; + } catch (Zend_Db_Adapter_Exception $e) { + Error::catchDbException($e); + } catch (Zend_Exception $e) { + Error::catchZendException($e); + } + return; } /** @@ -231,7 +244,7 @@ public function logActivity($exclude = array()) { isset($this->config->log->system->writer) && $this->config->log->system->writer == 'file' ) { if (!$this->config->log->system->file) { - throw new Exception($this->traslate->tr('Не задан файл журнала')); + throw new Exception($this->traslate->tr('Не задан файл журнала запросов')); } $log = new \Core2\Log('access'); @@ -535,6 +548,9 @@ final public function getModule($module_id) { } + /** + * Получение всех настроек системы + */ final private function getAllSettings() { $key = "all_settings_" . $this->config->database->params->dbname; if (!($this->cache->test($key))) { diff --git a/inc/classes/Init.php b/inc/classes/Init.php index b666b98d..81b4f751 100644 --- a/inc/classes/Init.php +++ b/inc/classes/Init.php @@ -20,27 +20,27 @@ Error::Exception("Отсутствует конфигурационный файл."); } $config = array( - 'system' => array('name' => 'CORE'), - 'include_path' => '', - 'cache' => 'cache', - 'temp' => getenv('TMP'), - 'debug' => array('on' => false), - 'database' => array( - 'adapter' => 'Pdo_Mysql', - 'params' => array( - 'charset' => 'utf8', - 'adapterNamespace' => 'Core_Db_Adapter' - ), - 'isDefaultTableAdapter' => true, - 'profiler' => array( - 'enabled' => false, - 'class' => 'Zend_Db_Profiler_Firebug' - ), - 'caseFolding' => true, - 'autoQuoteIdentifiers' => true, - 'allowSerialization' => true, - 'autoReconnectOnUnserialize' => true - ) + 'system' => array('name' => 'CORE'), + 'include_path' => '', + 'cache' => 'cache', + 'temp' => getenv('TMP'), + 'debug' => array('on' => false), + 'database' => array( + 'adapter' => 'Pdo_Mysql', + 'params' => array( + 'charset' => 'utf8', + 'adapterNamespace' => 'Core_Db_Adapter' + ), + 'isDefaultTableAdapter' => true, + 'profiler' => array( + 'enabled' => false, + 'class' => 'Zend_Db_Profiler_Firebug' + ), + 'caseFolding' => true, + 'autoQuoteIdentifiers' => true, + 'allowSerialization' => true, + 'autoReconnectOnUnserialize' => true + ) ); // определяем путь к темповой папке if (empty($config['temp'])) { @@ -161,7 +161,7 @@ public function __construct() { parent::__construct(); if (empty($_SERVER['HTTPS'])) { - if (isset($this->config->system) && ! empty($this->config->system->https)) { + if (isset($this->config->system) && !empty($this->config->system->https)) { header('Location: https://' . $_SERVER['SERVER_NAME']); } } diff --git a/inc/classes/Log.php b/inc/classes/Log.php index b969d287..21f2f027 100644 --- a/inc/classes/Log.php +++ b/inc/classes/Log.php @@ -4,6 +4,7 @@ use Monolog\Handler\StreamHandler; use Monolog\Handler\SyslogHandler; use Monolog\Processor\WebProcessor; + use Monolog\Formatter\NormalizerFormatter; /** * Обеспечение журналирования запросов пользователей @@ -15,8 +16,20 @@ class Log { private $config; private $writer; - public function __construct($name) { - $this->log = new Logger($name); + public function __construct($name = 'core2', $logfile = '') { + if ($name != 'access') { + $this->log = new Logger($_SERVER['SERVER_NAME'] . "." . $name); + $this->config = \Zend_Registry::getInstance()->get('core_config'); + if ($this->config->log->system->file) { + $stream = new StreamHandler($this->config->log->system->file); + //$stream->setFormatter(new NormalizerFormatter()); + $this->log->pushHandler($stream); + } + + } elseif ($logfile) { + $this->log = new Logger($name); + $this->config = \Zend_Registry::getInstance()->get('config'); + } } public function access($name) { @@ -27,7 +40,6 @@ public function access($name) { private function setWriter() { if (!$this->writer) { - $this->config = \Zend_Registry::getInstance()->get('config'); if ($this->config->log->system->file) { $this->log->pushHandler(new StreamHandler($this->config->log->system->file, Logger::INFO)); $this->writer = 'file'; @@ -39,7 +51,27 @@ private function setWriter() { } public function info($msg, $context = array()) { - $this->log->addInfo($msg, $context); + if (is_array($msg)) { + $context = $msg; + $msg = '-'; + } + $this->log->info($msg, $context); + } + + public function warning($msg, $context = array()) { + if (is_array($msg)) { + $context = $msg; + $msg = '-'; + } + $this->log->warning($msg, $context); + } + + public function debug($msg, $context = array()) { + if (is_array($msg)) { + $context = $msg; + $msg = '-'; + } + $this->log->debug($msg, $context); } } \ No newline at end of file