Skip to content

Commit

Permalink
Merge branch 'master' into 3.next
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 4, 2017
2 parents c0e5fd1 + d4a8f72 commit 8258072
Show file tree
Hide file tree
Showing 29 changed files with 617 additions and 331 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -31,7 +31,7 @@
"ext-openssl": "To use Security::encrypt() or have secure CSRF token generation."
},
"require-dev": {
"phpunit/phpunit": "*",
"phpunit/phpunit": "<6.0",
"cakephp/cakephp-codesniffer": "~2.1"
},
"autoload": {
Expand Down
3 changes: 3 additions & 0 deletions src/Collection/CollectionTrait.php
Expand Up @@ -739,6 +739,9 @@ public function transpose()
if (count($row) != $length) {
throw new LogicException('Child arrays do not have even length');
}
}

for ($column = 0; $column < $length; $column++) {
$result[] = array_column($arrayValue, $column);
}

Expand Down
5 changes: 1 addition & 4 deletions src/Database/Expression/ValuesExpression.php
Expand Up @@ -268,9 +268,6 @@ public function sql(ValueBinder $generator)
$this->_processExpressions();
}

$i = 0;
$columns = [];

$columns = $this->_columnNames();
$defaults = array_fill_keys($columns, null);
$placeholders = [];
Expand All @@ -293,7 +290,7 @@ public function sql(ValueBinder $generator)
continue;
}

$placeholder = $generator->placeholder($i);
$placeholder = $generator->placeholder('c');
$rowPlaceholders[] = $placeholder;
$generator->bind($placeholder, $value, $types[$column]);
}
Expand Down
11 changes: 8 additions & 3 deletions src/Database/Statement/MysqlStatement.php
Expand Up @@ -32,9 +32,14 @@ class MysqlStatement extends PDOStatement
*/
public function execute($params = null)
{
$this->_driver->connection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $this->_bufferResults);
$result = $this->_statement->execute($params);
$this->_driver->connection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$connection = $this->_driver->connection();

try {
$connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $this->_bufferResults);
$result = $this->_statement->execute($params);
} finally {
$connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}

return $result;
}
Expand Down
9 changes: 4 additions & 5 deletions src/Database/ValueBinder.php
Expand Up @@ -67,8 +67,8 @@ public function bind($param, $value, $type = 'string')
public function placeholder($token)
{
$number = $this->_bindingsCount++;
if ($token[0] !== ':' || $token !== '?') {
$token = sprintf(':c%s', $number);
if ($token[0] !== ':' && $token !== '?') {
$token = sprintf(':%s%s', $token, $number);
}

return $token;
Expand All @@ -86,14 +86,13 @@ public function generateManyNamed($values, $type = 'string')
{
$placeholders = [];
foreach ($values as $k => $value) {
$param = ":c" . $this->_bindingsCount;
$param = $this->placeholder('c');
$this->_bindings[$param] = [
'value' => $value,
'type' => $type,
'placeholder' => substr($param, 1),
];
$placeholders[$k] = $param;
$this->_bindingsCount++;
}

return $placeholders;
Expand Down Expand Up @@ -143,7 +142,7 @@ public function attachTo($statement)
if (empty($bindings)) {
return;
}
$params = $types = [];

foreach ($bindings as $b) {
$statement->bindValue($b['placeholder'], $b['value'], $b['type']);
}
Expand Down
28 changes: 28 additions & 0 deletions src/I18n/TranslatorFactory.php
Expand Up @@ -17,6 +17,7 @@
use Aura\Intl\FormatterInterface;
use Aura\Intl\TranslatorFactory as BaseTranslatorFactory;
use Aura\Intl\TranslatorInterface;
use RuntimeException;

/**
* Factory to create translators
Expand All @@ -31,4 +32,31 @@ class TranslatorFactory extends BaseTranslatorFactory
* @var string
*/
protected $class = 'Cake\I18n\Translator';

/**
* Returns a new Translator.
*
* @param string $locale The locale code for the translator.
* @param array $messages The localized messages for the translator.
* @param \Aura\Intl\FormatterInterface $formatter The formatter to use for interpolating token values.
* @param \Aura\Intl\TranslatorInterface $fallback A fallback translator to use, if any.
* @throws \Cake\Core\Exception\Exception If fallback class does not match Cake\I18n\Translator
* @return \Cake\I18n\Translator
*/
public function newInstance(
$locale,
array $messages,
FormatterInterface $formatter,
TranslatorInterface $fallback = null
) {
$class = $this->class;
if ($fallback !== null && get_class($fallback) !== $class) {
throw new RuntimeException(sprintf(
'Translator fallback class %s does not match Cake\I18n\Translator, try clearing your _cake_core_ cache.',
get_class($fallback)
));
}

return new $class($locale, $messages, $formatter, $fallback);
}
}
2 changes: 1 addition & 1 deletion src/Mailer/Email.php
Expand Up @@ -2046,7 +2046,7 @@ protected function _logDelivery($contents)
}
Log::write(
$config['level'],
PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message'],
PHP_EOL . $contents['headers'] . PHP_EOL . PHP_EOL . $contents['message'],
$config['scope']
);
}
Expand Down
10 changes: 8 additions & 2 deletions src/Network/Session/CacheSession.php
Expand Up @@ -100,7 +100,11 @@ public function read($id)
*/
public function write($id, $data)
{
return Cache::write($id, $data, $this->_options['config']);
if (!$id) {
return false;
}

return (bool)Cache::write($id, $data, $this->_options['config']);
}

/**
Expand All @@ -111,7 +115,9 @@ public function write($id, $data)
*/
public function destroy($id)
{
return Cache::delete($id, $this->_options['config']);
Cache::delete($id, $this->_options['config']);

return true;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/ORM/Association/HasMany.php
Expand Up @@ -264,7 +264,9 @@ public function link(EntityInterface $sourceEntity, array $targetEntities, array

$sourceEntity->set($property, $currentEntities);

$savedEntity = $this->saveAssociated($sourceEntity, $options);
$savedEntity = $this->connection()->transactional(function () use ($sourceEntity, $options) {
return $this->saveAssociated($sourceEntity, $options);
});

$ok = ($savedEntity instanceof EntityInterface);

Expand Down
22 changes: 19 additions & 3 deletions src/ORM/ResultSet.php
Expand Up @@ -313,10 +313,19 @@ public function first()
*/
public function serialize()
{
if (!$this->_useBuffering) {
$msg = 'You cannot serialize an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.';
throw new Exception($msg);
}

while ($this->valid()) {
$this->next();
}

if ($this->_results instanceof SplFixedArray) {
return serialize($this->_results->toArray());
}

return serialize($this->_results);
}

Expand All @@ -330,9 +339,10 @@ public function serialize()
*/
public function unserialize($serialized)
{
$this->_results = unserialize($serialized);
$results = (array)(unserialize($serialized) ?: []);
$this->_results = SplFixedArray::fromArray($results);
$this->_useBuffering = true;
$this->_count = count($this->_results);
$this->_count = $this->_results->count();
}

/**
Expand All @@ -351,7 +361,13 @@ public function count()
return $this->_count = $this->_statement->rowCount();
}

return $this->_count = count($this->_results);
if ($this->_results instanceof SplFixedArray) {
$this->_count = $this->_results->count();
} else {
$this->_count = count($this->_results);
}

return $this->_count;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Element/exception_stack_trace_nav.ctp
Expand Up @@ -18,7 +18,7 @@ use Cake\Error\Debugger;

<ul class="stack-trace">
<?php foreach ($error->getTrace() as $i => $stack): ?>
<?php $class = (isset($stack['file']) && strpos(APP, $stack['file']) === false) ? 'vendor-frame' : 'app-frame'; ?>
<?php $class = (isset($stack['file']) && strpos($stack['file'], APP) === false) ? 'vendor-frame' : 'app-frame'; ?>
<li class="stack-frame <?= $class ?>">
<?php if (isset($stack['function'])): ?>
<a href="#" data-target="stack-frame-<?= $i ?>">
Expand Down
2 changes: 1 addition & 1 deletion src/TestSuite/TestCase.php
Expand Up @@ -401,7 +401,7 @@ public function assertHtml($expected, $string, $fullDebug = false)
}
$regex[] = [
sprintf('%sClose %s tag', $prefix[0], substr($tags, strlen($match[0]))),
sprintf('%s<[\s]*\/[\s]*%s[\s]*>[\n\r]*', $prefix[1], substr($tags, strlen($match[0]))),
sprintf('%s\s*<[\s]*\/[\s]*%s[\s]*>[\n\r]*', $prefix[1], substr($tags, strlen($match[0]))),
$i,
];
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validation.php
Expand Up @@ -85,7 +85,7 @@ public static function notEmpty($check)
*/
public static function notBlank($check)
{
if (empty($check) && $check !== '0' && $check !== 0) {
if (empty($check) && !is_bool($check) && !is_numeric($check)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validator.php
Expand Up @@ -1745,7 +1745,7 @@ protected function _canBeEmpty($field, $context)
*/
protected function _fieldIsEmpty($data)
{
if (empty($data) && $data !== '0' && $data !== false && $data !== 0 && $data !== 0.0) {
if (empty($data) && !is_bool($data) && !is_numeric($data)) {
return true;
}
$isArray = is_array($data);
Expand Down
125 changes: 0 additions & 125 deletions tests/Fixture/AssertHtmlTestCase.php

This file was deleted.

0 comments on commit 8258072

Please sign in to comment.