File: PhpHttpFunctionOverrides.php

package info (click to toggle)
php-slim 3.12.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,368 kB
  • sloc: php: 11,581; makefile: 18; xml: 10; sh: 3
file content (64 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
 * Slim Framework (https://slimframework.com)
 *
 * @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
 */

namespace Slim\Http;

use Slim\Tests\Assets\HeaderStack;

/**
 * Return the value of the global variable $GLOBALS['getallheaders_return'] if it exists. Otherwise the
 * function override calls the default php built-in function.
 *
 * @return array|false
 */
function getallheaders()
{
    if (array_key_exists('getallheaders_return', $GLOBALS)) {
        return $GLOBALS['getallheaders_return'];
    }

    return \getallheaders();
}

/**
 * Emit a header, without creating actual output artifacts
 *
 * @param string   $string
 * @param bool     $replace
 * @param int|null $statusCode
 */
function header($string, $replace = true, $statusCode = null)
{
    HeaderStack::push(
        [
            'header'      => $string,
            'replace'     => $replace,
            'status_code' => $statusCode,
        ]
    );
}

function header_remove($name = null)
{
    HeaderStack::remove($name);
}

/**
 * Return the level of the output buffering shifted by the value of the global
 * variable $GLOBALS['ob_get_level_shift'] if it exists. Otherwise the function
 * override calls the default php built-in function.
 *
 * @return int
 */
function ob_get_level()
{
    if (isset($GLOBALS['ob_get_level_shift'])) {
        return \ob_get_level() + $GLOBALS['ob_get_level_shift'];
    }

    return \ob_get_level();
}