Repository navigation
Expand file tree
/
Copy pathbootstrap.php
More file actions
96 lines (83 loc) · 4.23 KB
/
Copy pathbootstrap.php
File metadata and controls
96 lines (83 loc) · 4.23 KB
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
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
* cuongcds/ci3-cms bootstrap.
*
* Required from the host application's application/config/config.php:
*
* require_once APPPATH . '../vendor/cuongcds/ci3-cms/bootstrap.php';
*
* At this point in CI3's lifecycle only the local $config array (being
* built by config.php) exists — there is no $CI instance yet, so this
* file limits itself to loading the Composer autoloader and merging the
* package's default 'cms' config with any application/config/cms.php
* overrides. Package-path/library registration happens lazily on first
* controller instantiation (see adapters/codeigniter3/core/CMS_Controller.php).
*/
if (! class_exists(\Gendo\Cms\Support\Config::class)) {
// When installed as a normal Composer dependency, this package lives at
// vendor/cuongcds/ci3-cms/ and the real autoloader is two levels up, at
// vendor/autoload.php. Fall back to __DIR__ . '/vendor/autoload.php' for the
// (monorepo/local-path-repository) case where this file sits at the repo root
// and vendor/ is its own, sibling directory instead.
$composerAutoload = __DIR__ . '/../../autoload.php';
require_once is_file($composerAutoload) ? $composerAutoload : __DIR__ . '/vendor/autoload.php';
}
/*
* Cms_lib must be reachable even before any package path has been registered with
* CI3's loader (that registration is done lazily, by CMS_Controller's constructor,
* once a Loader exists): if the host app's own MY_Controller loads the `cms_lib`
* library (e.g. to call setUserProvider()) before any CMS_Controller-derived
* controller has run, CI3's loader would only look under application/libraries/ and
* BASEPATH/libraries/ — the package path isn't registered yet, so it wouldn't find
* it. Requiring it eagerly here makes CI3's loader see the class already defined and
* skip file resolution entirely (see CI_Loader::_ci_load_library()'s class_exists()
* check). Cms_lib has no CI3 base-class dependency, so it's safe to load this early.
*/
require_once __DIR__ . '/adapters/codeigniter3/libraries/Cms_lib.php';
/*
* CMS_Controller, by contrast, extends CI_Controller (or the host's MY_Controller,
* which itself extends CI_Controller) — neither class exists yet this early in the
* request (CI_Controller is only defined later by CI3's own CodeIgniter.php flow), so
* CMS_Controller can't be required eagerly here. Autoload it lazily instead, the
* first time an adapter controller file references it in a `class X extends
* CMS_Controller` declaration (which only happens once CI_Controller is available).
*/
spl_autoload_register(function ($class) {
if ($class === 'CMS_Controller') {
require_once __DIR__ . '/adapters/codeigniter3/core/CMS_Controller.php';
}
});
// adapters/codeigniter3/config/cms.php assigns the package defaults into $config['cms'].
require __DIR__ . '/adapters/codeigniter3/config/cms.php';
$cmsDefaults = $config['cms'];
$cmsOverrides = [];
$cmsOverridesFile = realpath(APPPATH . 'config/cms.php');
if ($cmsOverridesFile && is_file($cmsOverridesFile)) {
// application/config/cms.php also assigns into $config['cms'] — capture just that.
require $cmsOverridesFile;
$cmsOverrides = $config['cms'];
}
$config['cms'] = \Gendo\Cms\Support\Config::merge($cmsDefaults, $cmsOverrides);
/*
* Bootstrapping problem: CI3's core dispatch only ever looks for the requested
* controller under application/controllers/ (see Stub_generator.php for the full
* explanation), and `php index.php cms install` is itself dispatched that way — so
* the one stub for the CLI controller (application/controllers/Cms.php) has to exist
* before `cms install` can ever run to generate the rest. Self-heal it here on every
* request instead of requiring a manual one-time copy step.
*/
$cmsCliStub = APPPATH . 'controllers/Cms.php';
if (! is_file($cmsCliStub)) {
require_once __DIR__ . '/adapters/codeigniter3/core/Stub_generator.php';
if (! is_dir(APPPATH . 'controllers')) {
mkdir(APPPATH . 'controllers', 0755, true);
}
file_put_contents(
$cmsCliStub,
\Stub_generator::stub_contents_for(
__DIR__ . '/adapters/codeigniter3/controllers/Cms.php',
APPPATH . 'controllers'
)
);
}