Skip to content

Commit

Permalink
Merge pull request #394 from phalcon/2.0.x
Browse files Browse the repository at this point in the history
2.0.6
  • Loading branch information
sergeyklay committed Jul 27, 2015
2 parents 8e8c383 + 947a806 commit 43bf209
Show file tree
Hide file tree
Showing 25 changed files with 1,460 additions and 462 deletions.
48 changes: 27 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
language: php

php:
- 5.4
- 5.5
- 5.6

services:
- memcached
- mysql

sudo: false

cache:
directories:
- vendor
- $HOME/.composer/cache

env:
- PHALCON_VERSION="2.0.x"
- PHALCON_VERSION="phalcon-v2.0.3"
- PHALCON_VERSION="phalcon-v2.0.2"
- PHALCON_VERSION="phalcon-v2.0.1"
- PHALCON_VERSION="phalcon-v2.0.0"
- PHALCON_VERSION="2.0.6"
- PHALCON_VERSION="2.0.5"
- PHALCON_VERSION="2.0.4"

install:
- tests/memcached.sh

before_script:
- ./tests/install-php-extension.sh ${PHALCON_VERSION}
- php -r 'echo \Phalcon\Version::get()."\n";'
- composer self-update
- composer update
- mysql -e 'create database eager_loading_tests charset=utf8mb4 collate=utf8mb4_unicode_ci;'
- mysql -uroot eager_loading_tests < tests/Phalcon/Mvc/Model/EagerLoading/resources/schema.sql
- git clone -q --depth=1 https://github.com/phalcon/cphalcon.git -b phalcon-v${PHALCON_VERSION}
- (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)
- php -r 'echo \Phalcon\Version::get()."\n";'
- composer install

php:
- 5.3
- 5.4
- 5.5
- 5.6
before_script:
- mysql -e 'create database incubator_tests charset=utf8mb4 collate=utf8mb4_unicode_ci;'
- cat tests/travis/db_schema.sql | mysql incubator_tests

script:
- php vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 Library/
Expand All @@ -31,6 +39,4 @@ script:
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

services:
- memcached
- mysql -e 'DROP DATABASE incubator_tests;'
16 changes: 6 additions & 10 deletions Library/Phalcon/Db/Dialect/MysqlExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,45 @@

namespace Phalcon\Db\Dialect;

use Phalcon\Db\Dialect\Mysql;

/**
* Phalcon\Db\Adapter\Dialect\MysqlExtended
*
* Every query executed via this adapter is automatically cached
*/
class MysqlExtended extends \Phalcon\Db\Dialect\Mysql
class MysqlExtended extends Mysql
{

/**
* Transforms an intermediate representation for a expression into a database system valid expression
*
* @param array expression
* @param string escapeChar
* @param array $expression
* @param string $escapeChar
*
* @return string
* @throws \Exception
*/
public function getSqlExpression(array $expression, $escapeChar = null)
{
if ($expression["type"] == 'functionCall') {
switch ($expression["name"]) {

case 'DATE_INTERVAL':

if (count($expression["arguments"]) != 2) {
throw new \Exception('DATE_INTERVAL requires 2 parameters');
}

switch ($expression["arguments"][1]['value']) {

case "'DAY'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' DAY';

case "'MONTH'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' MONTH';

case "'YEAR'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' YEAR';
}
break;

case 'FULLTEXT_MATCH':

if (count($expression["arguments"]) < 2) {
throw new \Exception('FULLTEXT_MATCH requires 2 parameters');
}
Expand All @@ -76,7 +73,6 @@ public function getSqlExpression(array $expression, $escapeChar = null)
$this->getSqlExpression($expression["arguments"][$length]) . ')';

case 'FULLTEXT_MATCH_BMODE':

if (count($expression["arguments"]) < 2) {
throw new \Exception('FULLTEXT_MATCH requires 2 parameters');
}
Expand Down
9 changes: 8 additions & 1 deletion Library/Phalcon/Mailer/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,21 @@ protected function renderView($viewPath, $params, $viewsDir = null)
protected function getView()
{
if (!$this->view) {
/** @var $viewApp \Phalcon\Mvc\View */
$viewApp = $this->getDI()->get('view');

if (!($viewsDir = $this->getConfig('viewsDir'))) {
$viewsDir = $this->getDI()->get('view')->getViewsDir();
$viewsDir = $viewApp->getViewsDir();
}

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

if ($engines = $viewApp->getRegisteredEngines()) {
$view->registerEngines($engines);
}

$this->view = $view;
}

Expand Down
2 changes: 1 addition & 1 deletion Library/Phalcon/Mailer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Add in your the code
$viewPath = 'email/example_message';

// Set variables to views (OPTIONAL)
$params [
$params = [
'var1' => 'VAR VALUE 1',
'var2' => 'VAR VALUE 2',
...
Expand Down
57 changes: 31 additions & 26 deletions Library/Phalcon/Mvc/Model/EagerLoading/EagerLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Phalcon\Mvc\Model\Relation;
use Phalcon\Mvc\Model\Resultset;
use Phalcon\Mvc\Model\Query\Builder;
use Phalcon\Version;

/**
* Represents a level in the relations tree to be eagerly loaded
Expand All @@ -15,20 +15,20 @@ final class EagerLoad
private $constraints;
/** @var Loader|EagerLoad */
private $parent;
/** @var null|Phalcon\Mvc\ModelInterface[] */
/** @var null|\Phalcon\Mvc\ModelInterface[] */
private $subject;
/** @var boolean */
private static $isPhalcon2;

/**
* @param RelationInterface
* @param Relation $relation
* @param null|callable $constraints
* @param Loader|EagerLoad $parent
*/
public function __construct(Relation $relation, $constraints, $parent)
{
if (static::$isPhalcon2 === null) {
static::$isPhalcon2 = version_compare(\Phalcon\Version::get(), '2.0.0') >= 0;
static::$isPhalcon2 = version_compare(Version::get(), '2.0.0') >= 0;
}

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

/**
* @return null|Phalcon\Mvc\ModelInterface[]
* @return null|\Phalcon\Mvc\ModelInterface[]
*/
public function getSubject()
{
Expand All @@ -56,6 +56,12 @@ public function getSubject()
*/
public function load()
{
$parentSubject = $this->parent->getSubject();

if (empty($parentSubject)) {
return $this;
}

$relation = $this->relation;

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

$bindValues = array ();
$bindValues = [];

foreach ($this->parent->getSubject() as $record) {
foreach ($parentSubject as $record) {
$bindValues[$record->readAttribute($relField)] = true;
}

$bindValues = array_keys($bindValues);

$subjectSize = count($this->parent->getSubject());
$subjectSize = count($parentSubject);
$isManyToManyForMany = false;

$builder = new QueryBuilder;
Expand Down Expand Up @@ -116,14 +122,14 @@ public function load()
->setHydrateMode(Resultset::HYDRATE_ARRAYS)
;

$bindValues = $modelReferencedModelValues = array ();
$bindValues = $modelReferencedModelValues = [];

foreach ($relIrValues as $row) {
$bindValues[$row[$relIrReferencedField]] = true;
$modelReferencedModelValues[$row[$relIrField]][$row[$relIrReferencedField]] = true;
}

unset ($relIrValues, $row);
unset($relIrValues, $row);

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

$records = array ();
$records = [];

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

foreach ($this->parent->getSubject() as $record) {
foreach ($parentSubject as $record) {
$referencedFieldValue = $record->readAttribute($relField);

if (isset ($modelReferencedModelValues[$referencedFieldValue])) {
$referencedModels = array ();
if (isset($modelReferencedModelValues[$referencedFieldValue])) {
$referencedModels = [];

foreach ($modelReferencedModelValues[$referencedFieldValue] as $idx => $_) {
$referencedModels[] = $records[$idx];
Expand All @@ -160,7 +166,7 @@ public function load()
}
} else {
$record->{$alias} = null;
$record->{$alias} = array ();
$record->{$alias} = [];
}
}

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

$record = $this->parent->getSubject();
$record = $record[0];
$record = $parentSubject[0];

if ($isSingle) {
$record->{$alias} = empty ($records) ? null : $records[0];
$record->{$alias} = empty($records) ? null : $records[0];
} else {
if (empty ($records)) {
if (empty($records)) {
$record->{$alias} = null;
$record->{$alias} = array ();
$record->{$alias} = [];
} else {
$record->{$alias} = $records;

Expand All @@ -197,7 +202,7 @@ public function load()
}
}
} else {
$indexedRecords = array ();
$indexedRecords = [];

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

foreach ($this->parent->getSubject() as $record) {
foreach ($parentSubject as $record) {
$referencedFieldValue = $record->readAttribute($relField);

if (isset ($indexedRecords[$referencedFieldValue])) {
if (isset($indexedRecords[$referencedFieldValue])) {
$record->{$alias} = $indexedRecords[$referencedFieldValue];

if (static::$isPhalcon2 && is_array($indexedRecords[$referencedFieldValue])) {
Expand All @@ -222,9 +227,9 @@ public function load()
}
} else {
$record->{$alias} = null;

if (!$isSingle) {
$record->{$alias} = array ();
$record->{$alias} = [];
}
}
}
Expand Down
Loading

0 comments on commit 43bf209

Please sign in to comment.