8000 merged branch stloyd/feature/travis_php55 (PR #6552) · klend/symfony@cd0a9d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd0a9d7

Browse files
committed
merged branch stloyd/feature/travis_php55 (PR symfony#6552)
This PR was merged into the 2.0 branch. Commits ------- 73d9cef [Locale] Adjust `StubIntlDateFormatter` to have new methods added in PHP 5.5 b2ce983 [Locale] Fix failing `StubIntlDateFormatter` tests in PHP 5.5 913b564 [Locale] Fix failing `StubIntlDateFormatter` in PHP 5.5 8ae773b [Form] Fix failing `MonthChoiceList` in PHP 5.5 f4ce2f1 Update .travis.yml Discussion ---------- [2.0] Add testing of PHP 5.5 on Travis-CI & fix failing code
2 parents df5c171 + 73d9cef commit cd0a9d7

File tree

4 files changed

+267
-38
lines changed

4 files changed

+267
-38
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ php:
44
- 5.3.3
55
- 5.3
66
- 5.4
7+
- 5.5
8+
9+
matrix:
10+
allow_failures:
11+
- php: 5.5
712

813
before_script: php vendors.php

src/Symfony/Component/Form/Extension/Core/ChoiceList/MonthChoiceList.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ protected function load()
3939
$pattern = $this->formatter->getPattern();
4040
$timezone = $this->formatter->getTimezoneId();
4141

42-
$this->formatter->setTimezoneId('UTC');
42+
if (version_compare(phpversion(), '5.5.0alpha1', '<')) {
43+
$this->formatter->setTimezoneId('UTC');
44+
} else {
45+
$this->formatter->setTimezone('UTC');
46+
}
4347

4448
if (preg_match('/M+/', $pattern, $matches)) {
4549
$this->formatter->setPattern($matches[0]);
@@ -53,6 +57,10 @@ protected function load()
5357
$this->formatter->setPattern($pattern);
5458
}
5559

56-
$this->formatter->setTimezoneId($timezone);
60+
if (version_compare(phpversion(), '5.5.0alpha1', '<')) {
61+
$this->formatter->setTimezoneId($timezone);
62+
} else {
63+
$this->formatter->setTimezone($timezone);
64+
}
5765
}
5866
}

src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ public function format($timestamp)
188188
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value ';
189189
} elseif (version_compare(\PHP_VERSION, '5.3.4', '>=') && !is_int($timestamp) && !$timestamp instanceof \DateTime) {
190190
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object';
191+
if (version_compare(\PHP_VERSION, '5.5.0alpha1', '>=') && !is_int($timestamp)) {
192+
$argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp);
193+
}
191194
}
192195

193196
if (null !== $argumentError) {
@@ -214,6 +217,24 @@ public function format($timestamp)
214217
return $formatted;
215218
}
216219

220+
/**
221+
* Formats an object
222+
*
223+
* @param object $object
224+
* @param mixed $format
225+
* @param string $locale
226+
*
227+
* @return string The formatted value
228+
*
229+
* @see http://www.php.net/manual/en/intldateformatter.formatobject.php
230+
*
231+
* @throws MethodNotImplementedException
232+
*/
233+
public function formatObject($object, $format = null, $locale = null)
234+
{
2 D7AE 35+
throw new MethodNotImplementedException(__METHOD__);
236+
}
237+
217238
/**
218239
* Returns the formatter's calendar
219240
*
@@ -226,6 +247,20 @@ public function getCalendar()
226247
return self::GREGORIAN;
227248
}
228249

250+
/**
251+
* Returns the formatter's calendar object
252+
*
253+
* @return object The calendar's object being used by the formatter
254+
*
255+
* @see http://www.php.net/manual/en/intldateformatter.getcalendarobject.php
256+
*
257+
* @throws MethodNotImplementedException
258+
*/
259+
public function getCalendarObject()
260+
{
261+
throw new MethodNotImplementedException(__METHOD__);
262+
}
263+
229264
/**
230265
* Returns the formatter's datetype
231266
*
@@ -313,9 +348,28 @@ public function getTimeZoneId()
313348
return $this->timeZoneId;
314349
}
315350

351+
// In PHP 5.5 default timezone depends on `date_default_timezone_get()` method
352+
if (version_compare(\PHP_VERSION, '5.5.0alpha1', '>=')) {
353+
return date_default_timezone_get();
354+
}
355+
316356
return null;
317357
}
318358

359+
/**
360+
* Returns the formatter's timezone
361+
*
362+
* @return mixed The timezone used by the formatter
363+
*
364+
* @see http://www.php.net/manual/en/intldateformatter.gettimezone.php
365+
*
366+
* @throws MethodNotImplementedException
367+
*/
368+
public function getTimeZone()
369+
{
370+
throw new MethodNotImplementedException(__METHOD__);
371+
}
372+
319373
/**
320374
* Returns whether the formatter is lenient
321375
*
@@ -458,11 +512,16 @@ public function setPattern($pattern)
458512
public function setTimeZoneId($timeZoneId)
459513
{
460514
if (null === $timeZoneId) {
461-
// TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
462-
// use ini's date.timezone when the time zone is not provided. As a not well tested workaround, uses UTC.
463-
// See the first two items of the commit message for more information:
464-
// https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9
465-
$timeZoneId = getenv('TZ') ?: 'UTC';
515+
// In PHP 5.5 if $timeZoneId is null it fallbacks to `date_default_timezone_get()` method
516+
if (version_compare(\PHP_VERSION, '5.5.0alpha1', '>=')) {
517+
$timeZoneId = date_default_timezone_get();
518+
} else {
519+
// TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
520+
// use ini's date.timezone when the time zone is not provided. As a not well tested workaround, uses UTC.
521+
// See the first two items of the commit message for more information:
522+
// https://github.com/php/php-src/commit/eb346ef0f419b90739aadfb6cc7b7436c5b521d9
523+
$timeZoneId = getenv('TZ') ?: 'UTC';
524+
}
466525

467526
$this->unitializedTimeZoneId = true;
468527
}
@@ -490,13 +549,27 @@ public function setTimeZoneId($timeZoneId)
490549
return true;
491550
}
492551

552+
/**
553+
* This method was added in PHP 5.5 as replacement for `setTimeZoneId()`
554+
*
555+
* @param mixed $timeZone
556+
*
557+
* @return Boolean true on success or false on failure
558+
*
559+
* @see http://www.php.net/manual/en/intldateformatter.settimezone.php
560+
*/
561+
public function setTimeZone($timeZone)
562+
{
563+
return $this->setTimeZoneId($timeZone);
564+
}
565+
493566
/**
494567
* Create and returns a DateTime object with the specified timestamp and with the
495568
* current time zone
496569
*
497570
* @param int $timestamp
498571
*
499-
* @return DateTime
572+
* @return \DateTime
500573
*/
501574
protected function createDateTime($timestamp)
502575
{

0 commit comments

Comments
 (0)
0