├── LICENSE ├── Php73.php ├── README.md ├── Resources └── stubs │ └── JsonException.php ├── bootstrap.php └── composer.json /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-present 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. 20 | -------------------------------------------------------------------------------- /Php73.php: -------------------------------------------------------------------------------- 1 | 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\Php73; 13 | 14 | /** 15 | * @author Gabriel Caruso 16 | * @author Ion Bazan 17 | * 18 | * @internal 19 | */ 20 | final class Php73 21 | { 22 | public static $startAt = 1533462603; 23 | 24 | /** 25 | * @param bool $asNum 26 | * 27 | * @return array|float|int 28 | */ 29 | public static function hrtime($asNum = false) 30 | { 31 | $ns = microtime(false); 32 | $s = substr($ns, 11) - self::$startAt; 33 | $ns = 1E9 * (float) $ns; 34 | 35 | if ($asNum) { 36 | $ns += $s * 1E9; 37 | 38 | return \PHP_INT_SIZE === 4 ? $ns : (int) $ns; 39 | } 40 | 41 | return [$s, (int) $ns]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Symfony Polyfill / Php73 2 | ======================== 3 | 4 | This component provides functions added to PHP 7.3 core: 5 | 6 | - [`array_key_first`](https://php.net/array_key_first) 7 | - [`array_key_last`](https://php.net/array_key_last) 8 | - [`hrtime`](https://php.net/function.hrtime) 9 | - [`is_countable`](https://php.net/is_countable) 10 | - [`JsonException`](https://php.net/JsonException) 11 | 12 | More information can be found in the 13 | [main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md). 14 | 15 | License 16 | ======= 17 | 18 | This library is released under the [MIT license](LICENSE). 19 | -------------------------------------------------------------------------------- /Resources/stubs/JsonException.php: -------------------------------------------------------------------------------- 1 | 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 | class JsonException extends Exception 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /bootstrap.php: -------------------------------------------------------------------------------- 1 | 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 | use Symfony\Polyfill\Php73 as p; 13 | 14 | if (\PHP_VERSION_ID >= 70300) { 15 | return; 16 | } 17 | 18 | if (!function_exists('is_countable')) { 19 | function is_countable($value) { return is_array($value) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; } 20 | } 21 | if (!function_exists('hrtime')) { 22 | require_once __DIR__.'/Php73.php'; 23 | p\Php73::$startAt = (int) microtime(true); 24 | function hrtime($as_number = false) { return p\Php73::hrtime($as_number); } 25 | } 26 | if (!function_exists('array_key_first')) { 27 | function array_key_first(array $array) { foreach ($array as $key => $value) { return $key; } } 28 | } 29 | if (!function_exists('array_key_last')) { 30 | function array_key_last(array $array) { return key(array_slice($array, -1, 1, true)); } 31 | } 32 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 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": "p@tchwork.com" 12 | }, 13 | { 14 | "name": "Symfony Community", 15 | "homepage": "https://symfony.com/contributors" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=7.2" 20 | }, 21 | "autoload": { 22 | "psr-4": { "Symfony\\Polyfill\\Php73\\": "" }, 23 | "files": [ "bootstrap.php" ], 24 | "classmap": [ "Resources/stubs" ] 25 | }, 26 | "minimum-stability": "dev", 27 | "extra": { 28 | "thanks": { 29 | "name": "symfony/polyfill", 30 | "url": "https://github.com/symfony/polyfill" 31 | } 32 | } 33 | } 34 | --------------------------------------------------------------------------------