krz/vox-populi

A Tumblr web client.

clone: git clone https://gitbay.org/krz/vox-populi.git

main: vendor/symfony/polyfill-php70/Php70.php · raw

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