ci4

Форк
0
/
preload.php 
106 строк · 3.1 Кб
1
<?php
2

3
/**
4
 * This file is part of CodeIgniter 4 framework.
5
 *
6
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11

12
/*
13
 *---------------------------------------------------------------
14
 * Sample file for Preloading
15
 *---------------------------------------------------------------
16
 * See https://www.php.net/manual/en/opcache.preloading.php
17
 *
18
 * How to Use:
19
 *   0. Copy this file to your project root folder.
20
 *   1. Set the $paths property of the preload class below.
21
 *   2. Set opcache.preload in php.ini.
22
 *     php.ini:
23
 *     opcache.preload=/path/to/preload.php
24
 */
25

26
// Load the paths config file
27
require __DIR__ . '/app/Config/Paths.php';
28

29
// Path to the front controller
30
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR);
31

32
class preload
33
{
34
    /**
35
     * @var array Paths to preload.
36
     */
37
    private array $paths = [
38
        [
39
            'include' => __DIR__ . '/vendor/codeigniter4/framework/system', // Change this path if using manual installation
40
            'exclude' => [
41
                // Not needed if you don't use them.
42
                '/system/Database/OCI8/',
43
                '/system/Database/Postgre/',
44
                '/system/Database/SQLite3/',
45
                '/system/Database/SQLSRV/',
46
                // Not needed for web apps.
47
                '/system/Database/Seeder.php',
48
                '/system/Test/',
49
                '/system/CLI/',
50
                '/system/Commands/',
51
                '/system/Publisher/',
52
                '/system/ComposerScripts.php',
53
                // Not Class/Function files.
54
                '/system/Config/Routes.php',
55
                '/system/Language/',
56
                '/system/bootstrap.php',
57
                '/system/rewrite.php',
58
                '/Views/',
59
                // Errors occur.
60
                '/system/ThirdParty/',
61
            ],
62
        ],
63
    ];
64

65
    public function __construct()
66
    {
67
        $this->loadAutoloader();
68
    }
69

70
    private function loadAutoloader(): void
71
    {
72
        $paths = new Config\Paths();
73
        require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'Boot.php';
74

75
        CodeIgniter\Boot::preload($paths);
76
    }
77

78
    /**
79
     * Load PHP files.
80
     */
81
    public function load(): void
82
    {
83
        foreach ($this->paths as $path) {
84
            $directory = new RecursiveDirectoryIterator($path['include']);
85
            $fullTree  = new RecursiveIteratorIterator($directory);
86
            $phpFiles  = new RegexIterator(
87
                $fullTree,
88
                '/.+((?<!Test)+\.php$)/i',
89
                RecursiveRegexIterator::GET_MATCH
90
            );
91

92
            foreach ($phpFiles as $key => $file) {
93
                foreach ($path['exclude'] as $exclude) {
94
                    if (str_contains($file[0], $exclude)) {
95
                        continue 2;
96
                    }
97
                }
98

99
                require_once $file[0];
100
                echo 'Loaded: ' . $file[0] . "\n";
101
            }
102
        }
103
    }
104
}
105

106
(new preload())->load();
107

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.