Skip to content

Commit

Permalink
Merge branch 'master' into 3.next
Browse files Browse the repository at this point in the history
Conflicts:
	.travis.yml
  • Loading branch information
ADmad committed Jun 12, 2016
2 parents 6c0844f + 30cd428 commit 138f50f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 234 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
@@ -1,9 +1,9 @@
language: php

php:
- 7.0
- 5.5
- 5.6
- 7.0

dist: trusty

Expand Down Expand Up @@ -45,7 +45,7 @@ matrix:
- php: hhvm

before_install:
- if [ $HHVM != 1 ]; then phpenv config-rm xdebug.ini; fi
- if [ $HHVM != 1 && $TRAVIS_PHP_VERSION != 7.* ]; then phpenv config-rm xdebug.ini; fi

- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;

Expand All @@ -66,7 +66,6 @@ before_install:
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' ]] ; then echo 'apc.enable_cli = 1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
- if [[ $TRAVIS_PHP_VERSION =~ 5.[56] ]] ; then echo yes | pecl install apcu-4.0.10; fi
- if [[ $TRAVIS_PHP_VERSION = 7.* ]] ; then echo yes | pecl install apcu; fi
- if [[ $TRAVIS_PHP_VERSION = 7.* ]] ; then pecl config-set preferred_state beta; echo yes | pecl install apcu_bc; fi
- if [[ $TRAVIS_PHP_VERSION = 'hhvm' ]] ; then composer require lorenzo/multiple-iterator=~1.0; fi

- phpenv rehash
Expand All @@ -76,7 +75,8 @@ before_script:
- composer install --prefer-dist --no-interaction

script:
- if [[ $DEFAULT = 1 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.* ]]; then export CODECOVERAGE=1; vendor/bin/phpunit --coverage-clover=clover.xml; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.* ]]; then vendor/bin/phpunit; fi

- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi

Expand Down
63 changes: 1 addition & 62 deletions src/I18n/DateFormatTrait.php
Expand Up @@ -16,10 +16,7 @@

use Cake\Chronos\Date as ChronosDate;
use Cake\Chronos\MutableDate;
use DateTimeZone;
use IntlDateFormatter;
use InvalidArgumentException;
use RuntimeException;

/**
* Trait for date formatting methods shared by both Time & Date.
Expand All @@ -37,14 +34,6 @@ trait DateFormatTrait
*/
public static $defaultLocale;

/**
* The \DateTimeZone default output timezone used by Time and FrozenTime.
*
* @var \DateTimeZone|null
* @see http://php.net/manual/en/timezones.php
*/
protected static $_defaultOutputTimezone;

/**
* In-memory cache of date formatters
*
Expand Down Expand Up @@ -75,43 +64,6 @@ trait DateFormatTrait
*/
protected static $_isDateInstance;

/**
* Gets the default output timezone used by Time and FrozenTime.
*
* @return \DateTimeZone|null DateTimeZone object in which the date will be displayed or null.
* @throws \RuntimeException When being executed on Date/FrozenDate.
*/
public static function getDefaultOutputTimezone()
{
if (is_subclass_of(static::class, ChronosDate::class) || is_subclass_of(static::class, MutableDate::class)) {
throw new RuntimeException('Timezone conversion is not supported by Date/FrozenDate.');
}
return static::$_defaultOutputTimezone;
}

/**
* Sets the default output timezone used by Time and FrozenTime.
*
* @param string|\DateTimeZone $timezone Timezone string or DateTimeZone object
* in which the date will be displayed.
* @return void
* @throws \RuntimeException When being executed on Date/FrozenDate.
* @throws \InvalidArgumentException When $timezone is neither a valid DateTimeZone string nor a \DateTimeZone object.
*/
public static function setDefaultOutputTimezone($timezone)
{
if (is_subclass_of(static::class, ChronosDate::class) || is_subclass_of(static::class, MutableDate::class)) {
throw new RuntimeException('Timezone conversion is not supported by Date/FrozenDate.');
}
if (is_string($timezone)) {
static::$_defaultOutputTimezone = new DateTimeZone($timezone);
} elseif ($timezone instanceof DateTimeZone) {
static::$_defaultOutputTimezone = $timezone;
} else {
throw new InvalidArgumentException('Expected valid DateTimeZone string or \DateTimeZone object.');
}
}

/**
* Gets the default locale.
*
Expand Down Expand Up @@ -205,22 +157,9 @@ public function i18nFormat($format = null, $timezone = null, $locale = null)
{
$time = $this;

if ($time instanceof Time || $time instanceof FrozenTime) {
$timezone = $timezone ?: static::getDefaultOutputTimezone();
}
// Detect and prevent null timezone transitions, as datefmt_create will
// doubly apply the TZ offset.
$currentTimezone = $time->getTimezone();
if ($timezone && (
(is_string($timezone) && $currentTimezone->getName() === $timezone) ||
($timezone instanceof DateTimeZone && $currentTimezone->getName() === $timezone->getName())
)) {
$timezone = null;
}

if ($timezone) {
// Handle the immutable and mutable object cases.
$time = clone $time;
$time = clone $this;
$time = $time->timezone($timezone);
}

Expand Down
8 changes: 2 additions & 6 deletions src/I18n/RelativeTimeFormatter.php
Expand Up @@ -93,12 +93,8 @@ public function diffForHumans(ChronosInterface $date, ChronosInterface $other =
public function timeAgoInWords(DatetimeInterface $time, array $options = [])
{
$options = $this->_options($options, FrozenTime::class);

$timezone = null;
if ($options['timezone']) {
$timezone = $options['timezone'];
} elseif ($time instanceof Time || $time instanceof FrozenTime) {
$timezone = $time->getDefaultOutputTimezone();
$time = $time->timezone($options['timezone']);
}

$now = $options['from']->format('U');
Expand All @@ -118,7 +114,7 @@ public function timeAgoInWords(DatetimeInterface $time, array $options = [])
}

if ($diff > abs($now - (new FrozenTime($options['end']))->format('U'))) {
return sprintf($options['absoluteString'], $time->i18nFormat($options['format'], $timezone));
return sprintf($options['absoluteString'], $time->i18nFormat($options['format']));
}

$diffData = $this->_diffData($futureTime, $pastTime, $backwards, $options);
Expand Down
47 changes: 32 additions & 15 deletions src/ORM/Query.php
Expand Up @@ -289,20 +289,37 @@ public function eagerLoader(EagerLoader $instance = null)
* Each association might define special options when eager loaded, the allowed
* options that can be set per association are:
*
* - foreignKey: Used to set a different field to match both tables, if set to false
* - `foreignKey`: Used to set a different field to match both tables, if set to false
* no join conditions will be generated automatically. `false` can only be used on
* joinable associations and cannot be used with hasMany or belongsToMany associations.
* - fields: An array with the fields that should be fetched from the association
* - queryBuilder: Equivalent to passing a callable instead of an options array
* - `fields`: An array with the fields that should be fetched from the association.
* - `finder`: The finder to use when loading associated records. Either the name of the
* finder as a string, or an array to define options to pass to the finder.
* - `queryBuilder`: Equivalent to passing a callable instead of an options array.
*
* ### Example:
*
* ```
* // Set options for the hasMany articles that will be eagerly loaded for an author
* $query->contain([
* 'Articles' => [
* 'fields' => ['title', 'author_id']
* ]
* 'Articles' => [
* 'fields' => ['title', 'author_id']
* ]
* ]);
* ```
*
* Finders can be configured to use options.
*
* ```
* // Retrieve translations for the articles, but only those for the `en` and `es` locales
* $query->contain([
* 'Articles' => [
* 'finder' => [
* 'translations' => [
* 'locales' => ['en', 'es']
* ]
* ]
* ]
* ]);
* ```
*
Expand All @@ -312,24 +329,24 @@ public function eagerLoader(EagerLoader $instance = null)
* ```
* // Use special join conditions for getting an Articles's belongsTo 'authors'
* $query->contain([
* 'Authors' => [
* 'foreignKey' => false,
* 'queryBuilder' => function ($q) {
* return $q->where(...); // Add full filtering conditions
* }
* ]
* 'Authors' => [
* 'foreignKey' => false,
* 'queryBuilder' => function ($q) {
* return $q->where(...); // Add full filtering conditions
* }
* ]
* ]);
* ```
*
* If called with no arguments, this function will return an array with
* with the list of previously configured associations to be contained in the
* result.
*
* If called with an empty first argument and $override is set to true, the
* If called with an empty first argument and `$override` is set to true, the
* previous list will be emptied.
*
* @param array|string|null $associations list of table aliases to be queried
* @param bool $override whether override previous list with the one passed
* @param array|string|null $associations List of table aliases to be queried.
* @param bool $override Whether override previous list with the one passed
* defaults to merging previous list with the new one.
* @return array|$this
*/
Expand Down

0 comments on commit 138f50f

Please sign in to comment.