annotate vendor/symfony/polyfill-php70/Php70.php @ 0:c75dbcec494b

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