File: bootstrap.php

package info (click to toggle)
php-slim-psr7 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 656 kB
  • sloc: php: 5,274; makefile: 17; sh: 11; xml: 10
file content (99 lines) | stat: -rw-r--r-- 3,037 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php

/**
 * Slim Framework (https://slimframework.com)
 *
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 */

declare(strict_types=1);

use AdrianSuter\Autoload\Override\Override;
use Slim\Psr7\Factory;
use Slim\Psr7\Headers;
use Slim\Psr7\Message;
use Slim\Psr7\NonBufferedBody;
use Slim\Psr7\UploadedFile;
use Slim\Tests\Psr7\Assets\HeaderStack;

$classLoader = require __DIR__ . '/../vendor/autoload.php';

Override::apply($classLoader, [
    Headers::class => [
        'getallheaders' => function () {
            if (array_key_exists('getallheaders_return', $GLOBALS)) {
                return $GLOBALS['getallheaders_return'];
            }

            return getallheaders();
        }
    ],
    Message::class => [
        'header' => function (string $string, bool $replace = true, ?int $statusCode = null): void {
            HeaderStack::push(
                [
                    'header'      => $string,
                    'replace'     => $replace,
                    'status_code' => $statusCode,
                ]
            );
        },
        'header_remove' => function ($name = null): void {
            HeaderStack::remove($name);
        }
    ],
    NonBufferedBody::class => [
        'ob_get_level' => function (): int {
            if (isset($GLOBALS['ob_get_level_shift'])) {
                return ob_get_level() + $GLOBALS['ob_get_level_shift'];
            }

            return ob_get_level();
        }
    ],
    UploadedFile::class => [
        'copy' => function (string $source, string $destination, $context = null): bool {
            if (isset($GLOBALS['copy_return'])) {
                return $GLOBALS['copy_return'];
            }

            if ($context === null) {
                return copy($source, $destination);
            }
            return copy($source, $destination, $context);
        },
        'is_uploaded_file' => function (string $filename): bool {
            if (isset($GLOBALS['is_uploaded_file_return'])) {
                return $GLOBALS['is_uploaded_file_return'];
            }

            return is_uploaded_file($filename);
        },
        'rename' => function (string $oldName, string $newName, $context = null): bool {
            if (isset($GLOBALS['rename_return'])) {
                return $GLOBALS['rename_return'];
            }

            if ($context === null) {
                return rename($oldName, $newName);
            }
            return rename($oldName, $newName, $context = null);
        }
    ],
    Factory\StreamFactory::class => [
        'fopen' => function (string $filename, string $mode) {
            if (isset($GLOBALS['fopen_return'])) {
                return isset($GLOBALS['fopen_return']);
            }

            return fopen($filename, $mode);
        },
        'is_readable' => function (string $filename) {
            if ($filename === 'non-readable') {
                return false;
            }

            return is_readable($filename);
        }
    ]
]);