1 | <?php |
||||
2 | /** |
||||
3 | * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
||||
4 | * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
||||
5 | * |
||||
6 | * Licensed under The MIT License |
||||
7 | * For full copyright and license information, please see the LICENSE.txt |
||||
8 | * Redistributions of files must retain the above copyright notice. |
||||
9 | * |
||||
10 | * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
||||
11 | * @link https://cakephp.org CakePHP(tm) Project |
||||
12 | * @since 0.10.8 |
||||
13 | * @license https://opensource.org/licenses/mit-license.php MIT License |
||||
14 | */ |
||||
15 | |||||
16 | /* |
||||
17 | * Configure paths required to find CakePHP + general filepath constants |
||||
18 | */ |
||||
19 | require __DIR__ . '/paths.php'; |
||||
20 | |||||
21 | /* |
||||
22 | * Bootstrap CakePHP. |
||||
23 | * |
||||
24 | * Does the various bits of setup that CakePHP needs to do. |
||||
25 | * This includes: |
||||
26 | * |
||||
27 | * - Registering the CakePHP autoloader. |
||||
28 | * - Setting the default application paths. |
||||
29 | */ |
||||
30 | require CORE_PATH . 'config' . DS . 'bootstrap.php'; |
||||
31 | |||||
32 | use Cake\Cache\Cache; |
||||
33 | use Cake\Console\ConsoleErrorHandler; |
||||
34 | use Cake\Core\App; |
||||
35 | use Cake\Core\Configure; |
||||
36 | use Cake\Core\Configure\Engine\PhpConfig; |
||||
37 | use Cake\Core\Plugin; |
||||
38 | use Cake\Database\Type; |
||||
39 | use Cake\Datasource\ConnectionManager; |
||||
40 | use Cake\Error\ErrorHandler; |
||||
41 | use Cake\Http\ServerRequest; |
||||
42 | use Cake\Log\Log; |
||||
43 | use Cake\Mailer\Email; |
||||
44 | use Cake\Mailer\TransportFactory; |
||||
45 | use Cake\Routing\DispatcherFactory; |
||||
46 | use Cake\Utility\Inflector; |
||||
47 | use Cake\Utility\Security; |
||||
0 ignored issues
–
show
|
|||||
48 | |||||
49 | /** |
||||
50 | * Uncomment block of code below if you want to use `.env` file during development. |
||||
51 | * You should copy `config/.env.default to `config/.env` and set/modify the |
||||
52 | * variables as required. |
||||
53 | */ |
||||
54 | if (!env('APP_NAME') && file_exists(CONFIG . '.env')) { |
||||
55 | $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']); |
||||
56 | $dotenv->parse() |
||||
57 | ->putenv() |
||||
58 | ->toEnv() |
||||
59 | ->toServer(); |
||||
60 | } |
||||
61 | |||||
62 | /* |
||||
63 | * Read configuration file and inject configuration into various |
||||
64 | * CakePHP classes. |
||||
65 | * |
||||
66 | * By default there is only one configuration file. It is often a good |
||||
67 | * idea to create multiple configuration files, and separate the configuration |
||||
68 | * that changes from configuration that does not. This makes deployment simpler. |
||||
69 | */ |
||||
70 | try { |
||||
71 | Configure::config('default', new PhpConfig()); |
||||
72 | Configure::load('app', 'default', false); |
||||
73 | |||||
74 | /** |
||||
75 | * Load additional config files |
||||
76 | */ |
||||
77 | Configure::load('permissions', 'default'); |
||||
78 | Configure::load('saito_config', 'default'); |
||||
79 | Configure::config('saitoCore', new PhpConfig(APP . '/Lib/')); |
||||
80 | Configure::load('version', 'saitoCore'); |
||||
81 | |||||
82 | Configure::write( |
||||
83 | 'App.defaultLocale', |
||||
84 | Configure::read('Saito.language') |
||||
85 | ); |
||||
86 | |||||
87 | Configure::load('email', 'default'); |
||||
88 | } catch (\Exception $e) { |
||||
89 | exit($e->getMessage() . "\n"); |
||||
90 | } |
||||
91 | |||||
92 | /* |
||||
93 | * Load an environment local configuration file. |
||||
94 | * You can use a file like app_local.php to provide local overrides to your |
||||
95 | * shared configuration. |
||||
96 | */ |
||||
97 | //Configure::load('app_local', 'default'); |
||||
98 | |||||
99 | /* |
||||
100 | * When debug = true the metadata cache should only last |
||||
101 | * for a short time. |
||||
102 | */ |
||||
103 | if (Configure::read('debug')) { |
||||
104 | Configure::write('Cache._cake_model_.duration', '+2 minutes'); |
||||
105 | Configure::write('Cache._cake_core_.duration', '+2 minutes'); |
||||
106 | // disable router cache during development |
||||
107 | Configure::write('Cache._cake_routes_.duration', '+2 seconds'); |
||||
108 | } |
||||
109 | |||||
110 | /* |
||||
111 | * Set the default server timezone. Using UTC makes time calculations / conversions easier. |
||||
112 | * Check http://php.net/manual/en/timezones.php for list of valid timezone strings. |
||||
113 | */ |
||||
114 | date_default_timezone_set(Configure::read('App.defaultTimezone')); |
||||
115 | |||||
116 | /* |
||||
117 | * Configure the mbstring extension to use the correct encoding. |
||||
118 | */ |
||||
119 | mb_internal_encoding(Configure::read('App.encoding')); |
||||
120 | |||||
121 | /* |
||||
122 | * Set the default locale. This controls how dates, number and currency is |
||||
123 | * formatted and sets the default language to use for translations. |
||||
124 | */ |
||||
125 | ini_set('intl.default_locale', Configure::read('App.defaultLocale')); |
||||
126 | |||||
127 | /* |
||||
128 | * Register application error and exception handlers. |
||||
129 | */ |
||||
130 | $isCli = PHP_SAPI === 'cli'; |
||||
131 | if ($isCli) { |
||||
132 | (new ConsoleErrorHandler(Configure::read('Error')))->register(); |
||||
133 | } else { |
||||
134 | (new ErrorHandler(Configure::read('Error')))->register(); |
||||
135 | } |
||||
136 | |||||
137 | /* |
||||
138 | * Include the CLI bootstrap overrides. |
||||
139 | */ |
||||
140 | if ($isCli) { |
||||
141 | require __DIR__ . '/bootstrap_cli.php'; |
||||
142 | } |
||||
143 | |||||
144 | /* |
||||
145 | * Set the full base URL. |
||||
146 | * This URL is used as the base of all absolute links. |
||||
147 | * |
||||
148 | * If you define fullBaseUrl in your config file you can remove this. |
||||
149 | */ |
||||
150 | if (!Configure::read('App.fullBaseUrl')) { |
||||
151 | $s = null; |
||||
152 | if (env('HTTPS')) { |
||||
153 | $s = 's'; |
||||
154 | } |
||||
155 | |||||
156 | $httpHost = env('HTTP_HOST'); |
||||
157 | if (isset($httpHost)) { |
||||
158 | Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost); |
||||
159 | } |
||||
160 | unset($httpHost, $s); |
||||
161 | } |
||||
162 | |||||
163 | Cache::setConfig(Configure::consume('Cache')); |
||||
164 | ConnectionManager::setConfig(Configure::consume('Datasources')); |
||||
165 | TransportFactory::setConfig(Configure::consume('EmailTransport')); |
||||
166 | Email::setConfig(Configure::consume('Email')); |
||||
167 | Log::setConfig(Configure::consume('Log')); |
||||
168 | Security::setSalt(Configure::consume('Security.salt')); |
||||
0 ignored issues
–
show
It seems like
Cake\Core\Configure::consume('Security.salt') can also be of type array ; however, parameter $salt of Cake\Utility\Security::setSalt() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
169 | |||||
170 | /* |
||||
171 | * The default crypto extension in 3.0 is OpenSSL. |
||||
172 | * If you are migrating from 2.x uncomment this code to |
||||
173 | * use a more compatible Mcrypt based implementation |
||||
174 | */ |
||||
175 | //Security::engine(new \Cake\Utility\Crypto\Mcrypt()); |
||||
176 | |||||
177 | /* |
||||
178 | * Setup detectors for mobile and tablet. |
||||
179 | */ |
||||
180 | ServerRequest::addDetector('mobile', function ($request) { |
||||
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
181 | $detector = new \Detection\MobileDetect(); |
||||
182 | |||||
183 | return $detector->isMobile(); |
||||
184 | }); |
||||
185 | ServerRequest::addDetector('tablet', function ($request) { |
||||
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
186 | $detector = new \Detection\MobileDetect(); |
||||
187 | |||||
188 | return $detector->isTablet(); |
||||
189 | }); |
||||
190 | |||||
191 | /* |
||||
192 | * Enable immutable time objects in the ORM. |
||||
193 | * |
||||
194 | * You can enable default locale format parsing by adding calls |
||||
195 | * to `useLocaleParser()`. This enables the automatic conversion of |
||||
196 | * locale specific date formats. For details see |
||||
197 | * @link https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data |
||||
198 | */ |
||||
199 | Type::build('time') |
||||
200 | ->useImmutable(); |
||||
0 ignored issues
–
show
The method
useImmutable() does not exist on Cake\Database\Type . It seems like you code against a sub-type of Cake\Database\Type such as Cake\Database\Type\DateTimeType .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
201 | Type::build('date') |
||||
202 | ->useImmutable(); |
||||
203 | Type::build('datetime') |
||||
204 | ->useImmutable(); |
||||
205 | Type::build('timestamp') |
||||
206 | ->useImmutable(); |
||||
207 | |||||
208 | /* |
||||
209 | * Custom Inflector rules, can be set to correctly pluralize or singularize |
||||
210 | * table, model, controller names or whatever other string is passed to the |
||||
211 | * inflection functions. |
||||
212 | */ |
||||
213 | //Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']); |
||||
214 | //Inflector::rules('irregular', ['red' => 'redlings']); |
||||
215 | //Inflector::rules('uninflected', ['dontinflectme']); |
||||
216 | //Inflector::rules('transliteration', ['/å/' => 'aa']); |
||||
217 | |||||
218 | /** |
||||
219 | * cake doesn't handle smiley <-> smilies |
||||
220 | */ |
||||
221 | Inflector::rules('plural', ['/^(smil)ey$/i' => '\1ies']); |
||||
222 | Inflector::rules('singular', ['/^(smil)ies$/i' => '\1ey']); |
||||
223 | |||||
224 | include Cake\Core\App::path('Lib')[0] . 'BaseFunctions.php'; |
||||
225 | |||||
226 | \Cake\Event\EventManager::instance()->on(\Saito\Event\SaitoEventManager::getInstance()); |
||||
227 | |||||
228 | /** |
||||
229 | * Add custom Database-types |
||||
230 | */ |
||||
231 | Type::map('serialize', 'App\Database\Type\SerializeType'); |
||||
232 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: