Skip to content

Commit af78fb5

Browse files
feature #115 Add is_countable under PHP 7.3 (carusogabriel)
This PR was squashed before being merged into the 1.7-dev branch (closes #115). Discussion ---------- Add is_countable under PHP 7.3 As requested by @nicolas-grekas :) Waiting for php/php-src#3026 Commits ------- 803a622 Add is_countable under PHP 7.3
2 parents 86e2777 + 803a622 commit af78fb5

25 files changed

+169
-17
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ matrix:
1616
- php: 5.6
1717
- php: 7.0
1818
- php: 7.1
19+
- php: 7.2
1920
fast_finish: true
2021

2122
before_install:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* v1.8.0
2+
3+
* added PHP 7.3 polyfill
4+
15
* v1.7.0
26

37
* added logic to new stream functions on Windows (sapi_windows_vt100_support)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Polyfills are provided for:
3232
`mbstring.func_overload` is required;
3333
- the `spl_object_id` and `stream_isatty` functions introduced in PHP 7.2;
3434
- the `sapi_windows_vt100_support` function (Windows only) introduced in PHP 7.2;
35-
- the `PHP_OS_FAMILY` constant introduced in PHP 7.2.
35+
- the `PHP_OS_FAMILY` constant introduced in PHP 7.2;
36+
- the `is_countable` function introduced in PHP 7.3.
3637

3738
It is strongly recommended to upgrade your PHP version and/or install the missing
3839
extensions whenever possible. This polyfill should be used only when there is no
@@ -58,6 +59,7 @@ should **not** `require` the `symfony/polyfill` package, but the standalone ones
5859
- `symfony/polyfill-php70` for using the PHP 7.0 functions,
5960
- `symfony/polyfill-php71` for using the PHP 7.1 functions,
6061
- `symfony/polyfill-php72` for using the PHP 7.2 functions,
62+
- `symfony/polyfill-php73` for using the PHP 7.3 functions,
6163
- `symfony/polyfill-iconv` for using the iconv functions,
6264
- `symfony/polyfill-intl-grapheme` for using the `grapheme_*` functions,
6365
- `symfony/polyfill-intl-icu` for using the intl functions and classes,

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"symfony/polyfill-php70": "self.version",
3333
"symfony/polyfill-php71": "self.version",
3434
"symfony/polyfill-php72": "self.version",
35+
"symfony/polyfill-php73": "self.version",
3536
"symfony/polyfill-iconv": "self.version",
3637
"symfony/polyfill-intl-grapheme": "self.version",
3738
"symfony/polyfill-intl-icu": "self.version",
@@ -50,6 +51,7 @@
5051
"src/Php70/bootstrap.php",
5152
"src/Php71/bootstrap.php",
5253
"src/Php72/bootstrap.php",
54+
"src/Php73/bootstrap.php",
5355
"src/Iconv/bootstrap.php",
5456
"src/Intl/Grapheme/bootstrap.php",
5557
"src/Intl/Icu/bootstrap.php",
@@ -65,7 +67,7 @@
6567
"minimum-stability": "dev",
6668
"extra": {
6769
"branch-alias": {
68-
"dev-master": "1.7-dev"
70+
"dev-master": "1.8-dev"
6971
}
7072
}
7173
}

src/Apcu/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"minimum-stability": "dev",
2626
"extra": {
2727
"branch-alias": {
28-
"dev-master": "1.7-dev"
28+
"dev-master": "1.8-dev"
2929
}
3030
}
3131
}

src/Iconv/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.7-dev"
31+
"dev-master": "1.8-dev"
3232
}
3333
}
3434
}

src/Intl/Grapheme/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.7-dev"
31+
"dev-master": "1.8-dev"
3232
}
3333
}
3434
}

src/Intl/Icu/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.7-dev"
31+
"dev-master": "1.8-dev"
3232
}
3333
}
3434
}

src/Intl/Normalizer/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"minimum-stability": "dev",
3030
"extra": {
3131
"branch-alias": {
32-
"dev-master": "1.7-dev"
32+
"dev-master": "1.8-dev"
3333
}
3434
}
3535
}

src/Mbstring/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.7-dev"
31+
"dev-master": "1.8-dev"
3232
}
3333
}
3434
}

src/Php54/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"minimum-stability": "dev",
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "1.7-dev"
29+
"dev-master": "1.8-dev"
3030
}
3131
}
3232
}

src/Php55/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"minimum-stability": "dev",
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "1.7-dev"
29+
"dev-master": "1.8-dev"
3030
}
3131
}
3232
}

src/Php56/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"minimum-stability": "dev",
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "1.7-dev"
29+
"dev-master": "1.8-dev"
3030
}
3131
}
3232
}

src/Php70/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"minimum-stability": "dev",
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "1.7-dev"
30+
"dev-master": "1.8-dev"
3131
}
3232
}
3333
}

src/Php71/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"minimum-stability": "dev",
2626
"extra": {
2727
"branch-alias": {
28-
"dev-master": "1.7-dev"
28+
"dev-master": "1.8-dev"
2929
}
3030
}
3131
}

src/Php72/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"minimum-stability": "dev",
2626
"extra": {
2727
"branch-alias": {
28-
"dev-master": "1.7-dev"
28+
"dev-master": "1.8-dev"
2929
}
3030
}
3131
}

src/Php73/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

src/Php73/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Symfony Polyfill / Php73
2+
========================
3+
4+
This component provides functions added to PHP 7.3 core:
5+
6+
- [`is_countable`](https://php.net/is_countable)
7+
8+
More information can be found in the
9+
[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md).
10+
11+
License
12+
=======
13+
14+
This library is released under the [MIT license](LICENSE).

src/Php73/bootstrap.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
if (PHP_VERSION_ID < 70300) {
13+
if (!function_exists('is_countable')) {
14+
function is_countable($var) {
15+
return is_array($var) || $var instanceof Countable;
16+
}
17+
}
18+
}

src/Php73/composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "symfony/polyfill-php73",
3+
"type": "library",
4+
"description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions",
5+
"keywords": ["polyfill", "shim", "compatibility", "portable"],
6+
"homepage": "https://symfony.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Nicolas Grekas",
11+
"email": "[email protected]"
12+
},
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": ">=5.3.3"
20+
},
21+
"autoload": {
22+
"psr-4": { "Symfony\\Polyfill\\Php73\\": "" },
23+
"files": [ "bootstrap.php" ]
24+
},
25+
"minimum-stability": "dev",
26+
"extra": {
27+
"branch-alias": {
28+
"dev-master": "1.8-dev"
29+
}
30+
}
31+
}

src/Util/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"minimum-stability": "dev",
2525
"extra": {
2626
"branch-alias": {
27-
"dev-master": "1.7-dev"
27+
"dev-master": "1.8-dev"
2828
}
2929
}
3030
}

src/Xml/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"minimum-stability": "dev",
2424
"extra": {
2525
"branch-alias": {
26-
"dev-master": "1.7-dev"
26+
"dev-master": "1.8-dev"
2727
}
2828
}
2929
}

tests/Mbstring/MbstringTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function testEncodeNumericEntityWarnsOnInvalidEncodingType()
176176
*/
177177
public function testEncodeNumericEntityWarnsOnInvalidIsHexType()
178178
{
179-
$this->setExpectedException('PHPUnit\Framework\Error\Warning', 'expects parameter 4 to be boolean');
179+
$this->setExpectedException('PHPUnit\Framework\Error\Warning', 'expects parameter 4 to be bool');
180180
mb_encode_numericentity('déjà', array(0x0, 0x10ffff, 0x0, 0x1fffff), 'UTF-8', new \stdClass());
181181
}
182182

tests/Php73/Php73Test.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Polyfill\Tests\Php73;
13+
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* @author Gabriel Caruso <[email protected]>
18+
*/
19+
class Php73Test extends TestCase
20+
{
21+
/**
22+
* @covers Symfony\Polyfill\Php73\Php73::is_countable
23+
*/
24+
public function testIsCountable()
25+
{
26+
$this->assertTrue(is_countable(array(1, 2, '3')));
27+
$this->assertTrue(is_countable(new \ArrayIterator(array('foo', 'bar', 'baz'))));
28+
$this->assertTrue(is_countable(new \ArrayIterator()));
29+
$this->assertFalse(is_countable(new \stdClass()));
30+
}
31+
32+
/**
33+
* @covers Symfony\Polyfill\Php73\Php73::is_countable
34+
* @requires PHP 5.5
35+
*/
36+
public function testIsCountableForGenerator()
37+
{
38+
require 'generator.php';
39+
40+
$this->assertFalse(is_countable(genOneToTen()));
41+
}
42+
}

tests/Php73/generator.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Polyfill\Tests\Php73;
13+
14+
function genOneToTen()
15+
{
16+
for ($i = 1; $i <= 10; ++$i) {
17+
yield $i;
18+
}
19+
}

0 commit comments

Comments
 (0)