diff --git a/.gitignore b/.gitignore index 7ed06261c..0601cbf34 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ codeception.yml tests/aerospike.suite.yml tests/unit.suite.5.yml tests/unit.suite.yml -tests/unit5x.suite.yml +tests/unit5x.suite.yml \ No newline at end of file diff --git a/Library/Phalcon/Logger/Adapter/Database.php b/Library/Phalcon/Logger/Adapter/Database.php index 1b946d367..2c784849c 100644 --- a/Library/Phalcon/Logger/Adapter/Database.php +++ b/Library/Phalcon/Logger/Adapter/Database.php @@ -19,22 +19,34 @@ namespace Phalcon\Logger\Adapter; -use Phalcon\Db\Column; use Phalcon\Logger\Exception; +use Phalcon\Logger\Formatter\FormatterInterface; +use Phalcon\Logger\Item; +use Phalcon\Db\Adapter\AdapterInterface as DbAdapterInterface; use Phalcon\Logger\Formatter\Line as LineFormatter; -use Phalcon\Logger\Adapter as LoggerAdapter; -use Phalcon\Logger\AdapterInterface; -use Phalcon\Db\AdapterInterface as DbAdapterInterface; +use Phalcon\Db\Column; /** - * Database Logger + * Phalcon\Logger\Adapter\Database * * Adapter to store logs in a database table - * - * @package Phalcon\Logger\Adapter */ -class Database extends LoggerAdapter implements AdapterInterface +class Database extends AbstractAdapter { + /** + * Database connection + * + * @var DbAdapterInterface + */ + protected $db; + + /** + * Table name + * + * @var string + */ + protected $table = "log"; + /** * Name * @var string @@ -42,24 +54,20 @@ class Database extends LoggerAdapter implements AdapterInterface protected $name = 'phalcon'; /** - * Adapter options - * @var array + * @var \Phalcon\Logger\Formatter\AbstractFormatter */ - protected $options = []; + protected $_formatter; /** - * @var \Phalcon\Db\AdapterInterface + * Adapter options + * @var array */ - protected $db; + protected $options = []; /** - * Class constructor. - * - * @param string $name - * @param array $options - * @throws \Phalcon\Logger\Exception + * Constructor. Accepts the name and some options */ - public function __construct($name = 'phalcon', array $options = []) + public function __construct(string $name = 'phalcon', array $options = []) { if (!isset($options['db'])) { throw new Exception("Parameter 'db' is required"); @@ -76,6 +84,7 @@ public function __construct($name = 'phalcon', array $options = []) } $this->db = $options['db']; + $this->table = $options['table']; if ($name) { $this->name = $name; @@ -87,64 +96,22 @@ public function __construct($name = 'phalcon', array $options = []) /** * Sets database connection * - * @param AdapterInterface $db + * @param DbAdapterInterface $db * @return $this */ - public function setDb(AdapterInterface $db) + public function setDb(DbAdapterInterface $db) { $this->db = $db; return $this; } - /** - * {@inheritdoc} - * - * @return \Phalcon\Logger\FormatterInterface - */ - public function getFormatter() - { - if (!is_object($this->_formatter)) { - $this->_formatter = new LineFormatter('%message%'); - } - - return $this->_formatter; - } - - /** - * Writes the log to the file itself - * - * @param string $message - * @param integer $type - * @param integer $time - * @param array $context - * @return bool - */ - public function logInternal($message, $type, $time, $context = []) - { - return $this->db->execute( - 'INSERT INTO ' . $this->options['table'] . ' VALUES (null, ?, ?, ?, ?)', - [ - $this->name, - $type, - $this->getFormatter()->format($message, $type, $time, $context), - $time, - ], - [ - Column::BIND_PARAM_STR, - Column::BIND_PARAM_INT, - Column::BIND_PARAM_STR, - Column::BIND_PARAM_INT, - ] - ); - } - /** * {@inheritdoc} * * @return boolean */ - public function close() + public function close(): bool { if ($this->db->isUnderTransaction()) { $this->db->commit(); @@ -160,7 +127,7 @@ public function close() * * @return $this */ - public function begin() + public function begin(): AdapterInterface { $this->db->begin(); @@ -172,7 +139,7 @@ public function begin() * * @return $this */ - public function commit() + public function commit(): AdapterInterface { $this->db->commit(); @@ -185,10 +152,46 @@ public function commit() * * @return $this */ - public function rollback() + public function rollback(): AdapterInterface { $this->db->rollback(); return $this; } -} + + /** + * {@inheritdoc} + * + * @return FormatterInterface + */ + public function getFormatter(): FormatterInterface + { + if (!is_object($this->_formatter)) { + $this->_formatter = new LineFormatter('%message%'); + } + + return $this->_formatter; + } + + /** + * Processes the message i.e. writes it to the file + */ + public function process(Item $item): void + { + $this->db->execute( + 'INSERT INTO ' . $this->table . ' VALUES (null, ?, ?, ?, ?)', + [ + $this->name, + $item->getType(), + $this->getFormatter()->format($item), + $item->getTime(), + ], + [ + Column::BIND_PARAM_STR, + Column::BIND_PARAM_INT, + Column::BIND_PARAM_STR, + Column::BIND_PARAM_INT, + ] + ); + } +} \ No newline at end of file diff --git a/Library/Phalcon/Mailer/Manager.php b/Library/Phalcon/Mailer/Manager.php index fd8d55c06..0697efde3 100644 --- a/Library/Phalcon/Mailer/Manager.php +++ b/Library/Phalcon/Mailer/Manager.php @@ -20,7 +20,9 @@ namespace Phalcon\Mailer; use Phalcon\Config; -use Phalcon\Mvc\User\Component; +use Phalcon\DI\Injectable; +use Phalcon\Events\EventsAwareInterface; +use Phalcon\Events\ManagerInterface; use Phalcon\Mvc\View; /** @@ -37,7 +39,7 @@ * * @package Phalcon\Manager */ -class Manager extends Component +class Manager extends Injectable implements EventsAwareInterface { /** * @var array @@ -64,6 +66,8 @@ class Manager extends Component */ protected $viewEngines = null; + protected $eventsManager; + /** * Create a new MailerManager component using $config for configuring * @@ -74,6 +78,16 @@ public function __construct(array $config) $this->configure($config); } + public function getEventsManager(): ?ManagerInterface + { + return $this->eventsManager; + } + + public function setEventsManager(ManagerInterface $eventsManager): void + { + $this->eventsManager = $eventsManager; + } + /** * Create a new Message instance. * diff --git a/Library/Phalcon/Mailer/Message.php b/Library/Phalcon/Mailer/Message.php index f8a377df3..33c3da057 100644 --- a/Library/Phalcon/Mailer/Message.php +++ b/Library/Phalcon/Mailer/Message.php @@ -340,6 +340,21 @@ public function getContent() return $this->getMessage()->getBody(); } + /** + * Add optionally an alternative body + * + * @param string $content + * @param string $contentType optional + * @param string $charset optional + * + * @return $this + */ + public function contentAlternative($content, $contentType = null, $charset = null) + { + $this->getMessage()->addPart($content, $contentType, $charset); + return $this; + } + /** * Set the Content-type of this message. * diff --git a/Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php b/Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php index 899040d39..a24556a5b 100644 --- a/Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php +++ b/Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php @@ -1,26 +1,27 @@ _conditions; diff --git a/composer.json b/composer.json index ea08e5f77..03a12a9b4 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "codeception/verify": "^0.3", "vlucas/phpdotenv": "^2.4", "phalcon/dd": "^1.1", - "doctrine/instantiator": "1.0.5" + "doctrine/instantiator": "1.0.5", + "phalcon/ide-stubs": "4.x-dev" }, "suggest": { "ext-aerospike": "*",