Skip to content

Commit 43bf209

Browse files
committed
Merge pull request phalcon#394 from phalcon/2.0.x
2.0.6
2 parents 8e8c383 + 947a806 commit 43bf209

File tree

25 files changed

+1460
-462
lines changed

25 files changed

+1460
-462
lines changed

.travis.yml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
language: php
22

3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
8+
services:
9+
- memcached
10+
- mysql
11+
12+
sudo: false
13+
14+
cache:
15+
directories:
16+
- vendor
17+
- $HOME/.composer/cache
18+
319
env:
4-
- PHALCON_VERSION="2.0.x"
5-
- PHALCON_VERSION="phalcon-v2.0.3"
6-
- PHALCON_VERSION="phalcon-v2.0.2"
7-
- PHALCON_VERSION="phalcon-v2.0.1"
8-
- PHALCON_VERSION="phalcon-v2.0.0"
20+
- PHALCON_VERSION="2.0.6"
21+
- PHALCON_VERSION="2.0.5"
22+
- PHALCON_VERSION="2.0.4"
923

1024
install:
11-
- tests/memcached.sh
12-
13-
before_script:
14-
- ./tests/install-php-extension.sh ${PHALCON_VERSION}
15-
- php -r 'echo \Phalcon\Version::get()."\n";'
1625
- composer self-update
17-
- composer update
18-
- mysql -e 'create database eager_loading_tests charset=utf8mb4 collate=utf8mb4_unicode_ci;'
19-
- mysql -uroot eager_loading_tests < tests/Phalcon/Mvc/Model/EagerLoading/resources/schema.sql
26+
- git clone -q --depth=1 https://github.com/phalcon/cphalcon.git -b phalcon-v${PHALCON_VERSION}
27+
- (cd cphalcon/ext; export CFLAGS="-g3 -O1 -fno-delete-null-pointer-checks -Wall"; phpize &> /dev/null && ./configure --silent --enable-phalcon &> /dev/null && make --silent -j4 > /dev/null && make --silent install && phpenv config-add ../unit-tests/ci/phalcon.ini &> /dev/null)
28+
- php -r 'echo \Phalcon\Version::get()."\n";'
29+
- composer install
2030

21-
php:
22-
- 5.3
23-
- 5.4
24-
- 5.5
25-
- 5.6
31+
before_script:
32+
- mysql -e 'create database incubator_tests charset=utf8mb4 collate=utf8mb4_unicode_ci;'
33+
- cat tests/travis/db_schema.sql | mysql incubator_tests
2634

2735
script:
2836
- php vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 Library/
@@ -31,6 +39,4 @@ script:
3139
after_script:
3240
- wget https://scrutinizer-ci.com/ocular.phar
3341
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
34-
35-
services:
36-
- memcached
42+
- mysql -e 'DROP DATABASE incubator_tests;'

Library/Phalcon/Db/Dialect/MysqlExtended.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,45 @@
2020

2121
namespace Phalcon\Db\Dialect;
2222

23+
use Phalcon\Db\Dialect\Mysql;
24+
2325
/**
2426
* Phalcon\Db\Adapter\Dialect\MysqlExtended
2527
*
2628
* Every query executed via this adapter is automatically cached
2729
*/
28-
class MysqlExtended extends \Phalcon\Db\Dialect\Mysql
30+
class MysqlExtended extends Mysql
2931
{
3032

3133
/**
3234
* Transforms an intermediate representation for a expression into a database system valid expression
3335
*
34-
* @param array expression
35-
* @param string escapeChar
36+
* @param array $expression
37+
* @param string $escapeChar
3638
*
3739
* @return string
40+
* @throws \Exception
3841
*/
3942
public function getSqlExpression(array $expression, $escapeChar = null)
4043
{
4144
if ($expression["type"] == 'functionCall') {
4245
switch ($expression["name"]) {
43-
4446
case 'DATE_INTERVAL':
45-
4647
if (count($expression["arguments"]) != 2) {
4748
throw new \Exception('DATE_INTERVAL requires 2 parameters');
4849
}
4950

5051
switch ($expression["arguments"][1]['value']) {
51-
5252
case "'DAY'":
5353
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' DAY';
54-
5554
case "'MONTH'":
5655
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' MONTH';
57-
5856
case "'YEAR'":
5957
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' YEAR';
6058
}
6159
break;
6260

6361
case 'FULLTEXT_MATCH':
64-
6562
if (count($expression["arguments"]) < 2) {
6663
throw new \Exception('FULLTEXT_MATCH requires 2 parameters');
6764
}
@@ -76,7 +73,6 @@ public function getSqlExpression(array $expression, $escapeChar = null)
7673
$this->getSqlExpression($expression["arguments"][$length]) . ')';
7774

7875
case 'FULLTEXT_MATCH_BMODE':
79-
8076
if (count($expression["arguments"]) < 2) {
8177
throw new \Exception('FULLTEXT_MATCH requires 2 parameters');
8278
}

Library/Phalcon/Mailer/Manager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,21 @@ protected function renderView($viewPath, $params, $viewsDir = null)
322322
protected function getView()
323323
{
324324
if (!$this->view) {
325+
/** @var $viewApp \Phalcon\Mvc\View */
326+
$viewApp = $this->getDI()->get('view');
327+
325328
if (!($viewsDir = $this->getConfig('viewsDir'))) {
326-
$viewsDir = $this->getDI()->get('view')->getViewsDir();
329+
$viewsDir = $viewApp->getViewsDir();
327330
}
328331

329332
/** @var $view \Phalcon\Mvc\View\Simple */
330333
$view = $this->getDI()->get('\Phalcon\Mvc\View\Simple');
331334
$view->setViewsDir($viewsDir);
332335

336+
if ($engines = $viewApp->getRegisteredEngines()) {
337+
$view->registerEngines($engines);
338+
}
339+
333340
$this->view = $view;
334341
}
335342

Library/Phalcon/Mailer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Add in your the code
111111
$viewPath = 'email/example_message';
112112

113113
// Set variables to views (OPTIONAL)
114-
$params [
114+
$params = [
115115
'var1' => 'VAR VALUE 1',
116116
'var2' => 'VAR VALUE 2',
117117
...

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Phalcon\Mvc\Model\Relation;
44
use Phalcon\Mvc\Model\Resultset;
5-
use Phalcon\Mvc\Model\Query\Builder;
5+
use Phalcon\Version;
66

77
/**
88
* Represents a level in the relations tree to be eagerly loaded
@@ -15,20 +15,20 @@ final class EagerLoad
1515
private $constraints;
1616
/** @var Loader|EagerLoad */
1717
private $parent;
18-
/** @var null|Phalcon\Mvc\ModelInterface[] */
18+
/** @var null|\Phalcon\Mvc\ModelInterface[] */
1919
private $subject;
2020
/** @var boolean */
2121
private static $isPhalcon2;
2222

2323
/**
24-
* @param RelationInterface
24+
* @param Relation $relation
2525
* @param null|callable $constraints
2626
* @param Loader|EagerLoad $parent
2727
*/
2828
public function __construct(Relation $relation, $constraints, $parent)
2929
{
3030
if (static::$isPhalcon2 === null) {
31-
static::$isPhalcon2 = version_compare(\Phalcon\Version::get(), '2.0.0') >= 0;
31+
static::$isPhalcon2 = version_compare(Version::get(), '2.0.0') >= 0;
3232
}
3333

3434
$this->relation = $relation;
@@ -37,7 +37,7 @@ public function __construct(Relation $relation, $constraints, $parent)
3737
}
3838

3939
/**
40-
* @return null|Phalcon\Mvc\ModelInterface[]
40+
* @return null|\Phalcon\Mvc\ModelInterface[]
4141
*/
4242
public function getSubject()
4343
{
@@ -56,6 +56,12 @@ public function getSubject()
5656
*/
5757
public function load()
5858
{
59+
$parentSubject = $this->parent->getSubject();
60+
61+
if (empty($parentSubject)) {
62+
return $this;
63+
}
64+
5965
$relation = $this->relation;
6066

6167
$alias = $relation->getOptions();
@@ -72,15 +78,15 @@ public function load()
7278
$relReferencedModel = ltrim($relReferencedModel, '\\');
7379
}
7480

75-
$bindValues = array ();
81+
$bindValues = [];
7682

77-
foreach ($this->parent->getSubject() as $record) {
83+
foreach ($parentSubject as $record) {
7884
$bindValues[$record->readAttribute($relField)] = true;
7985
}
8086

8187
$bindValues = array_keys($bindValues);
8288

83-
$subjectSize = count($this->parent->getSubject());
89+
$subjectSize = count($parentSubject);
8490
$isManyToManyForMany = false;
8591

8692
$builder = new QueryBuilder;
@@ -116,14 +122,14 @@ public function load()
116122
->setHydrateMode(Resultset::HYDRATE_ARRAYS)
117123
;
118124

119-
$bindValues = $modelReferencedModelValues = array ();
120-
125+
$bindValues = $modelReferencedModelValues = [];
126+
121127
foreach ($relIrValues as $row) {
122128
$bindValues[$row[$relIrReferencedField]] = true;
123129
$modelReferencedModelValues[$row[$relIrField]][$row[$relIrReferencedField]] = true;
124130
}
125131

126-
unset ($relIrValues, $row);
132+
unset($relIrValues, $row);
127133

128134
$builder->inWhere("[{$relReferencedField}]", array_keys($bindValues));
129135
}
@@ -135,18 +141,18 @@ public function load()
135141
call_user_func($this->constraints, $builder);
136142
}
137143

138-
$records = array ();
144+
$records = [];
139145

140146
if ($isManyToManyForMany) {
141147
foreach ($builder->getQuery()->execute() as $record) {
142148
$records[$record->readAttribute($relReferencedField)] = $record;
143149
}
144150

145-
foreach ($this->parent->getSubject() as $record) {
151+
foreach ($parentSubject as $record) {
146152
$referencedFieldValue = $record->readAttribute($relField);
147153

148-
if (isset ($modelReferencedModelValues[$referencedFieldValue])) {
149-
$referencedModels = array ();
154+
if (isset($modelReferencedModelValues[$referencedFieldValue])) {
155+
$referencedModels = [];
150156

151157
foreach ($modelReferencedModelValues[$referencedFieldValue] as $idx => $_) {
152158
$referencedModels[] = $records[$idx];
@@ -160,7 +166,7 @@ public function load()
160166
}
161167
} else {
162168
$record->{$alias} = null;
163-
$record->{$alias} = array ();
169+
$record->{$alias} = [];
164170
}
165171
}
166172

@@ -178,15 +184,14 @@ public function load()
178184
$records[] = $record;
179185
}
180186

181-
$record = $this->parent->getSubject();
182-
$record = $record[0];
187+
$record = $parentSubject[0];
183188

184189
if ($isSingle) {
185-
$record->{$alias} = empty ($records) ? null : $records[0];
190+
$record->{$alias} = empty($records) ? null : $records[0];
186191
} else {
187-
if (empty ($records)) {
192+
if (empty($records)) {
188193
$record->{$alias} = null;
189-
$record->{$alias} = array ();
194+
$record->{$alias} = [];
190195
} else {
191196
$record->{$alias} = $records;
192197

@@ -197,7 +202,7 @@ public function load()
197202
}
198203
}
199204
} else {
200-
$indexedRecords = array ();
205+
$indexedRecords = [];
201206

202207
// Keep all records in memory
203208
foreach ($builder->getQuery()->execute() as $record) {
@@ -210,10 +215,10 @@ public function load()
210215
}
211216
}
212217

213-
foreach ($this->parent->getSubject() as $record) {
218+
foreach ($parentSubject as $record) {
214219
$referencedFieldValue = $record->readAttribute($relField);
215220

216-
if (isset ($indexedRecords[$referencedFieldValue])) {
221+
if (isset($indexedRecords[$referencedFieldValue])) {
217222
$record->{$alias} = $indexedRecords[$referencedFieldValue];
218223

219224
if (static::$isPhalcon2 && is_array($indexedRecords[$referencedFieldValue])) {
@@ -222,9 +227,9 @@ public function load()
222227
}
223228
} else {
224229
$record->{$alias} = null;
225-
230+
226231
if (!$isSingle) {
227-
$record->{$alias} = array ();
232+
$record->{$alias} = [];
228233
}
229234
}
230235
}

0 commit comments

Comments
 (0)