annotate vendor/symfony/polyfill-php70/Php70.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@14 1 <?php
Chris@14 2
Chris@14 3 /*
Chris@14 4 * This file is part of the Symfony package.
Chris@14 5 *
Chris@14 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@14 7 *
Chris@14 8 * For the full copyright and license information, please view the LICENSE
Chris@14 9 * file that was distributed with this source code.
Chris@14 10 */
Chris@14 11
Chris@14 12 namespace Symfony\Polyfill\Php70;
Chris@14 13
Chris@14 14 /**
Chris@14 15 * @author Nicolas Grekas <p@tchwork.com>
Chris@14 16 *
Chris@14 17 * @internal
Chris@14 18 */
Chris@14 19 final class Php70
Chris@14 20 {
Chris@14 21 public static function intdiv($dividend, $divisor)
Chris@14 22 {
Chris@14 23 $dividend = self::intArg($dividend, __FUNCTION__, 1);
Chris@14 24 $divisor = self::intArg($divisor, __FUNCTION__, 2);
Chris@14 25
Chris@14 26 if (0 === $divisor) {
Chris@14 27 throw new \DivisionByZeroError('Division by zero');
Chris@14 28 }
Chris@14 29 if (-1 === $divisor && ~PHP_INT_MAX === $dividend) {
Chris@14 30 throw new \ArithmeticError('Division of PHP_INT_MIN by -1 is not an integer');
Chris@14 31 }
Chris@14 32
Chris@14 33 return ($dividend - ($dividend % $divisor)) / $divisor;
Chris@14 34 }
Chris@14 35
Chris@14 36 public static function preg_replace_callback_array(array $patterns, $subject, $limit = -1, &$count = 0)
Chris@14 37 {
Chris@14 38 $count = 0;
Chris@14 39 $result = (string) $subject;
Chris@14 40 if (0 === $limit = self::intArg($limit, __FUNCTION__, 3)) {
Chris@14 41 return $result;
Chris@14 42 }
Chris@14 43
Chris@14 44 foreach ($patterns as $pattern => $callback) {
Chris@14 45 $result = preg_replace_callback($pattern, $callback, $result, $limit, $c);
Chris@14 46 $count += $c;
Chris@14 47 }
Chris@14 48
Chris@14 49 return $result;
Chris@14 50 }
Chris@14 51
Chris@14 52 public static function error_clear_last()
Chris@14 53 {
Chris@14 54 static $handler;
Chris@14 55 if (!$handler) {
Chris@17 56 $handler = function () { return false; };
Chris@14 57 }
Chris@14 58 set_error_handler($handler);
Chris@14 59 @trigger_error('');
Chris@14 60 restore_error_handler();
Chris@14 61 }
Chris@14 62
Chris@16 63 private static function intArg($value, $caller, $pos)
Chris@14 64 {
Chris@16 65 if (\is_int($value)) {
Chris@14 66 return $value;
Chris@14 67 }
Chris@16 68 if (!\is_numeric($value) || PHP_INT_MAX <= ($value += 0) || ~PHP_INT_MAX >= $value) {
Chris@17 69 throw new \TypeError(sprintf('%s() expects parameter %d to be integer, %s given', $caller, $pos, \gettype($value)));
Chris@14 70 }
Chris@14 71
Chris@14 72 return (int) $value;
Chris@14 73 }
Chris@14 74 }