Skip to content

Commit 6015583

Browse files
authored
Merge pull request #918 from smartprogress/4.0.x
Upgrades for phalcon 4
2 parents 7164260 + f0b4b27 commit 6015583

File tree

6 files changed

+109
-75
lines changed

6 files changed

+109
-75
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ codeception.yml
1010
tests/aerospike.suite.yml
1111
tests/unit.suite.5.yml
1212
tests/unit.suite.yml
13-
tests/unit5x.suite.yml
13+
tests/unit5x.suite.yml

Library/Phalcon/Logger/Adapter/Database.php

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,55 @@
1919

2020
namespace Phalcon\Logger\Adapter;
2121

22-
use Phalcon\Db\Column;
2322
use Phalcon\Logger\Exception;
23+
use Phalcon\Logger\Formatter\FormatterInterface;
24+
use Phalcon\Logger\Item;
25+
use Phalcon\Db\Adapter\AdapterInterface as DbAdapterInterface;
2426
use Phalcon\Logger\Formatter\Line as LineFormatter;
25-
use Phalcon\Logger\Adapter as LoggerAdapter;
26-
use Phalcon\Logger\AdapterInterface;
27-
use Phalcon\Db\AdapterInterface as DbAdapterInterface;
27+
use Phalcon\Db\Column;
2828

2929
/**
30-
* Database Logger
30+
* Phalcon\Logger\Adapter\Database
3131
*
3232
* Adapter to store logs in a database table
33-
*
34-
* @package Phalcon\Logger\Adapter
3533
*/
36-
class Database extends LoggerAdapter implements AdapterInterface
34+
class Database extends AbstractAdapter
3735
{
36+
/**
37+
* Database connection
38+
*
39+
* @var DbAdapterInterface
40+
*/
41+
protected $db;
42+
43+
/**
44+
* Table name
45+
*
46+
* @var string
47+
*/
48+
protected $table = "log";
49+
3850
/**
3951
* Name
4052
* @var string
4153
*/
4254
protected $name = 'phalcon';
4355

4456
/**
45-
* Adapter options
46-
* @var array
57+
* @var \Phalcon\Logger\Formatter\AbstractFormatter
4758
*/
48-
protected $options = [];
59+
protected $_formatter;
4960

5061
/**
51-
* @var \Phalcon\Db\AdapterInterface
62+
* Adapter options
63+
* @var array
5264
*/
53-
protected $db;
65+
protected $options = [];
5466

5567
/**
56-
* Class constructor.
57-
*
58-
* @param string $name
59-
* @param array $options
60-
* @throws \Phalcon\Logger\Exception
68+
* Constructor. Accepts the name and some options
6169
*/
62-
public function __construct($name = 'phalcon', array $options = [])
70+
public function __construct(string $name = 'phalcon', array $options = [])
6371
{
6472
if (!isset($options['db'])) {
6573
throw new Exception("Parameter 'db' is required");
@@ -76,6 +84,7 @@ public function __construct($name = 'phalcon', array $options = [])
7684
}
7785

7886
$this->db = $options['db'];
87+
$this->table = $options['table'];
7988

8089
if ($name) {
8190
$this->name = $name;
@@ -87,64 +96,22 @@ public function __construct($name = 'phalcon', array $options = [])
8796
/**
8897
* Sets database connection
8998
*
90-
* @param AdapterInterface $db
99+
* @param DbAdapterInterface $db
91100
* @return $this
92101
*/
93-
public function setDb(AdapterInterface $db)
102+
public function setDb(DbAdapterInterface $db)
94103
{
95104
$this->db = $db;
96105

97106
return $this;
98107
}
99108

100-
/**
101-
* {@inheritdoc}
102-
*
103-
* @return \Phalcon\Logger\FormatterInterface
104-
*/
105-
public function getFormatter()
106-
{
107-
if (!is_object($this->_formatter)) {
108-
$this->_formatter = new LineFormatter('%message%');
109-
}
110-
111-
return $this->_formatter;
112-
}
113-
114-
/**
115-
* Writes the log to the file itself
116-
*
117-
* @param string $message
118-
* @param integer $type
119-
* @param integer $time
120-
* @param array $context
121-
* @return bool
122-
*/
123-
public function logInternal($message, $type, $time, $context = [])
124-
{
125-
return $this->db->execute(
126-
'INSERT INTO ' . $this->options['table'] . ' VALUES (null, ?, ?, ?, ?)',
127-
[
128-
$this->name,
129-
$type,
130-
$this->getFormatter()->format($message, $type, $time, $context),
131-
$time,
132-
],
133-
[
134-
Column::BIND_PARAM_STR,
135-
Column::BIND_PARAM_INT,
136-
Column::BIND_PARAM_STR,
137-
Column::BIND_PARAM_INT,
138-
]
139-
);
140-
}
141-
142109
/**
143110
* {@inheritdoc}
144111
*
145112
* @return boolean
146113
*/
147-
public function close()
114+
public function close(): bool
148115
{
149116
if ($this->db->isUnderTransaction()) {
150117
$this->db->commit();
@@ -160,7 +127,7 @@ public function close()
160127
*
161128
* @return $this
162129
*/
163-
public function begin()
130+
public function begin(): AdapterInterface
164131
{
165132
$this->db->begin();
166133

@@ -172,7 +139,7 @@ public function begin()
172139
*
173140
* @return $this
174141
*/
175-
public function commit()
142+
public function commit(): AdapterInterface
176143
{
177144
$this->db->commit();
178145

@@ -185,10 +152,46 @@ public function commit()
185152
*
186153
* @return $this
187154
*/
188-
public function rollback()
155+
public function rollback(): AdapterInterface
189156
{
190157
$this->db->rollback();
191158

192159
return $this;
193160
}
194-
}
161+
162+
/**
163+
* {@inheritdoc}
164+
*
165+
* @return FormatterInterface
166+
*/
167+
public function getFormatter(): FormatterInterface
168+
{
169+
if (!is_object($this->_formatter)) {
170+
$this->_formatter = new LineFormatter('%message%');
171+
}
172+
173+
return $this->_formatter;
174+
}
175+
176+
/**
177+
* Processes the message i.e. writes it to the file
178+
*/
179+
public function process(Item $item): void
180+
{
181+
$this->db->execute(
182+
'INSERT INTO ' . $this->table . ' VALUES (null, ?, ?, ?, ?)',
183+
[
184+
$this->name,
185+
$item->getType(),
186+
$this->getFormatter()->format($item),
187+
$item->getTime(),
188+
],
189+
[
190+
Column::BIND_PARAM_STR,
191+
Column::BIND_PARAM_INT,
192+
Column::BIND_PARAM_STR,
193+
Column::BIND_PARAM_INT,
194+
]
195+
);
196+
}
197+
}

Library/Phalcon/Mailer/Manager.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
namespace Phalcon\Mailer;
2121

2222
use Phalcon\Config;
23-
use Phalcon\Mvc\User\Component;
23+
use Phalcon\DI\Injectable;
24+
use Phalcon\Events\EventsAwareInterface;
25+
use Phalcon\Events\ManagerInterface;
2426
use Phalcon\Mvc\View;
2527

2628
/**
@@ -37,7 +39,7 @@
3739
*
3840
* @package Phalcon\Manager
3941
*/
40-
class Manager extends Component
42+
class Manager extends Injectable implements EventsAwareInterface
4143
{
4244
/**
4345
* @var array
@@ -64,6 +66,8 @@ class Manager extends Component
6466
*/
6567
protected $viewEngines = null;
6668

69+
protected $eventsManager;
70+
6771
/**
6872
* Create a new MailerManager component using $config for configuring
6973
*
@@ -74,6 +78,16 @@ public function __construct(array $config)
7478
$this->configure($config);
7579
}
7680

81+
public function getEventsManager(): ?ManagerInterface
82+
{
83+
return $this->eventsManager;
84+
}
85+
86+
public function setEventsManager(ManagerInterface $eventsManager): void
87+
{
88+
$this->eventsManager = $eventsManager;
89+
}
90+
7791
/**
7892
* Create a new Message instance.
7993
*

Library/Phalcon/Mailer/Message.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,21 @@ public function getContent()
340340
return $this->getMessage()->getBody();
341341
}
342342

343+
/**
344+
* Add optionally an alternative body
345+
*
346+
* @param string $content
347+
* @param string $contentType optional
348+
* @param string $charset optional
349+
*
350+
* @return $this
351+
*/
352+
public function contentAlternative($content, $contentType = null, $charset = null)
353+
{
354+
$this->getMessage()->addPart($content, $contentType, $charset);
355+
return $this;
356+
}
357+
343358
/**
344359
* Set the Content-type of this message.
345360
*

Library/Phalcon/Mvc/Model/EagerLoading/QueryBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
<?php namespace Phalcon\Mvc\Model\EagerLoading;
22

33
use Phalcon\Mvc\Model\Query\Builder;
4+
use Phalcon\Mvc\Model\Query\BuilderInterface;
45

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

9-
public function distinct($distinct)
10+
public function distinct($distinct): BuilderInterface
1011
{
1112
throw new \LogicException(
1213
static::E_NOT_ALLOWED_METHOD_CALL
1314
);
1415
}
1516

16-
public function columns($columns)
17+
public function columns($columns): BuilderInterface
1718
{
1819
throw new \LogicException(
1920
static::E_NOT_ALLOWED_METHOD_CALL
2021
);
2122
}
2223

23-
public function where($conditions, $bindParams = null, $bindTypes = null)
24+
public function where($conditions, $bindParams = null, $bindTypes = null): BuilderInterface
2425
{
2526
$currentConditions = $this->_conditions;
2627

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"codeception/verify": "^0.3",
4646
"vlucas/phpdotenv": "^2.4",
4747
"phalcon/dd": "^1.1",
48-
"doctrine/instantiator": "1.0.5"
48+
"doctrine/instantiator": "1.0.5",
49+
"phalcon/ide-stubs": "4.x-dev"
4950
},
5051
"suggest": {
5152
"ext-aerospike": "*",

0 commit comments

Comments
 (0)