Skip to content

Commit

Permalink
Merge pull request #918 from smartprogress/4.0.x
Browse files Browse the repository at this point in the history
Upgrades for phalcon 4
  • Loading branch information
Jeckerson authored Apr 15, 2020
2 parents 7164260 + f0b4b27 commit 6015583
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
139 changes: 71 additions & 68 deletions Library/Phalcon/Logger/Adapter/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,55 @@

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
*/
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");
Expand All @@ -76,6 +84,7 @@ public function __construct($name = 'phalcon', array $options = [])
}

$this->db = $options['db'];
$this->table = $options['table'];

if ($name) {
$this->name = $name;
Expand All @@ -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();
Expand All @@ -160,7 +127,7 @@ public function close()
*
* @return $this
*/
public function begin()
public function begin(): AdapterInterface
{
$this->db->begin();

Expand All @@ -172,7 +139,7 @@ public function begin()
*
* @return $this
*/
public function commit()
public function commit(): AdapterInterface
{
$this->db->commit();

Expand All @@ -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,
]
);
}
}
18 changes: 16 additions & 2 deletions Library/Phalcon/Mailer/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -37,7 +39,7 @@
*
* @package Phalcon\Manager
*/
class Manager extends Component
class Manager extends Injectable implements EventsAwareInterface
{
/**
* @var array
Expand All @@ -64,6 +66,8 @@ class Manager extends Component
*/
protected $viewEngines = null;

protected $eventsManager;

/**
* Create a new MailerManager component using $config for configuring
*
Expand All @@ -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.
*
Expand Down
15 changes: 15 additions & 0 deletions Library/Phalcon/Mailer/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
7 changes: 4 additions & 3 deletions Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<?php namespace Phalcon\Mvc\Model\EagerLoading;

use Phalcon\Mvc\Model\Query\Builder;
use Phalcon\Mvc\Model\Query\BuilderInterface;

final class QueryBuilder extends Builder
{
const E_NOT_ALLOWED_METHOD_CALL = 'When eager loading relations queries must return full entities';

public function distinct($distinct)
public function distinct($distinct): BuilderInterface
{
throw new \LogicException(
static::E_NOT_ALLOWED_METHOD_CALL
);
}

public function columns($columns)
public function columns($columns): BuilderInterface
{
throw new \LogicException(
static::E_NOT_ALLOWED_METHOD_CALL
);
}

public function where($conditions, $bindParams = null, $bindTypes = null)
public function where($conditions, $bindParams = null, $bindTypes = null): BuilderInterface
{
$currentConditions = $this->_conditions;

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down

0 comments on commit 6015583

Please sign in to comment.