Browse Source

Merge branch 'master' into 3.1

Mark Story 10 years ago
parent
commit
62ee633877

+ 1 - 1
src/Cache/Cache.php

@@ -252,7 +252,7 @@ class Cache
         $engine = static::engine($config);
         $return = $engine->writeMany($data);
         foreach ($return as $key => $success) {
-            if ($success === false && !empty($data[$key])) {
+            if ($success === false && $data[$key] !== '') {
                 throw new RuntimeException(sprintf(
                     '%s cache was unable to write \'%s\' to %s cache',
                     $config,

+ 1 - 1
src/Console/ConsoleInput.php

@@ -59,7 +59,7 @@ class ConsoleInput
     {
         if ($this->_canReadline) {
             $line = readline('');
-            if (!empty($line)) {
+            if (strlen($line) > 0) {
                 readline_add_history($line);
             }
             return $line;

+ 1 - 1
src/Console/ConsoleInputOption.php

@@ -153,7 +153,7 @@ class ConsoleInputOption
     {
         $name = (strlen($this->_short) > 0) ? ('-' . $this->_short) : ('--' . $this->_name);
         $default = '';
-        if (!empty($this->_default) && $this->_default !== true) {
+        if (strlen($this->_default) > 0 && $this->_default !== true) {
             $default = ' ' . $this->_default;
         }
         if (!empty($this->_choices)) {

+ 2 - 2
src/Database/Type/DateTimeType.php

@@ -99,7 +99,7 @@ class DateTimeType extends Type
      *
      * @param string $value The value to convert.
      * @param Driver $driver The driver instance to convert with.
-     * @return \Cake\I18n\Time|DateTime
+     * @return \Cake\I18n\Time|\DateTime
      */
     public function toPHP($value, Driver $driver)
     {
@@ -119,7 +119,7 @@ class DateTimeType extends Type
      * Convert request data into a datetime object.
      *
      * @param mixed $value Request data
-     * @return \Cake\I18n\Time|DateTime
+     * @return \Cake\I18n\Time|\DateTime
      */
     public function marshal($value)
     {

+ 13 - 0
src/I18n/Number.php

@@ -344,4 +344,17 @@ class Number
 
         return $formatter;
     }
+
+    /**
+     * Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])
+     *
+     * @param int|float $value An integer
+     * @return string
+     */
+    public static function ordinal($value)
+    {
+        $locale = I18n::locale();
+        $formatter = new NumberFormatter($locale, NumberFormatter::ORDINAL);
+        return $formatter->format($value);
+    }
 }

+ 3 - 0
src/Network/Http/Adapter/Stream.php

@@ -209,6 +209,9 @@ class Stream
         if (isset($options['redirect'])) {
             $this->_contextOptions['max_redirects'] = (int)$options['redirect'];
         }
+        if (isset($options['proxy']['proxy'])) {
+            $this->_contextOptions['proxy'] = $options['proxy']['proxy'];
+        }
     }
 
     /**

+ 1 - 1
src/ORM/Association.php

@@ -635,7 +635,7 @@ abstract class Association
     public function find($type = null, array $options = [])
     {
         $type = $type ?: $this->finder();
-        list($type, $opts) = $this->_extractFinder($type, $options);
+        list($type, $opts) = $this->_extractFinder($type);
         return $this->target()
             ->find($type, $options + $opts)
             ->where($this->conditions());

+ 11 - 0
src/View/Helper/NumberHelper.php

@@ -230,4 +230,15 @@ class NumberHelper extends Helper
     {
         return [];
     }
+
+    /**
+     * Formats a number into locale specific ordinal suffix.
+     *
+     * @param int|float $value An integer
+     * @return string formatted number
+     */
+    public function ordinal($value)
+    {
+        return $this->_engine->ordinal($value);
+    }
 }

+ 7 - 0
src/View/Helper/PaginatorHelper.php

@@ -82,6 +82,13 @@ class PaginatorHelper extends Helper
     ];
 
     /**
+     * Default model of the paged sets
+     *
+     * @var string
+     */
+    protected $_defaultModel;
+
+    /**
      * Constructor. Overridden to merge passed args with URL options.
      *
      * @param \Cake\View\View $View The View this helper is being attached to.

+ 28 - 0
tests/TestCase/I18n/NumberTest.php

@@ -557,4 +557,32 @@ class NumberTest extends TestCase
         $result = $this->Number->currency(15000, 'INR', ['locale' => 'en_IN']);
         $this->assertEquals('₹ 15,000', $result);
     }
+
+    /**
+     * test ordinal() with locales
+     *
+     * @return void
+     */
+    public function testOrdinal()
+    {
+        I18n::locale('en_US');
+        $result = $this->Number->ordinal(1);
+        $this->assertEquals('1st', $result);
+
+        $result = $this->Number->ordinal(2);
+        $this->assertEquals('2nd', $result);
+
+        $result = $this->Number->ordinal(3);
+        $this->assertEquals('3rd', $result);
+
+        $result = $this->Number->ordinal(4);
+        $this->assertEquals('4th', $result);
+
+        I18n::locale('fr_FR');
+        $result = $this->Number->ordinal(1);
+        $this->assertEquals('1er', $result);
+
+        $result = $this->Number->ordinal(2);
+        $this->assertEquals('2e', $result);
+    }
 }

+ 5 - 1
tests/TestCase/Network/Http/Adapter/StreamTest.php

@@ -74,7 +74,7 @@ class StreamTest extends TestCase
             ]);
 
         $options = [
-            'redirect' => 20
+            'redirect' => 20,
         ];
         $this->stream->send($request, $options);
         $result = $this->stream->contextOptions();
@@ -184,6 +184,9 @@ class StreamTest extends TestCase
             'ssl_verify_peer' => true,
             'ssl_verify_depth' => 9000,
             'ssl_allow_self_signed' => false,
+            'proxy' => [
+                'proxy' => '127.0.0.1:8080'
+            ]
         ];
 
         $this->stream->send($request, $options);
@@ -193,6 +196,7 @@ class StreamTest extends TestCase
             'verify_peer' => true,
             'verify_depth' => 9000,
             'allow_self_signed' => false,
+            'proxy' => '127.0.0.1:8080',
         ];
         foreach ($expected as $k => $v) {
             $this->assertEquals($v, $result[$k]);