bootstrap.php 9.19 KB
Newer Older
mickaelp's avatar
mickaelp committed
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
<?php
/**
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @since         0.10.8
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

/**
 * Configure paths required to find CakePHP + general filepath
 * constants
 */
require __DIR__ . '/paths.php';

// Use composer to load the autoloader.
require ROOT . DS . 'vendor' . DS . 'autoload.php';

/**
 * Bootstrap CakePHP.
 *
 * Does the various bits of setup that CakePHP needs to do.
 * This includes:
 *
 * - Registering the CakePHP autoloader.
 * - Setting the default application paths.
 */
require CORE_PATH . 'config' . DS . 'bootstrap.php';

// You can remove this if you are confident you have intl installed.
if (!extension_loaded('intl')) {
    trigger_error('You must enable the intl extension to use CakePHP.', E_USER_ERROR);
}

Matthieu FAURE's avatar
Matthieu FAURE committed
41
use App\Event\UserListener;
mickaelp's avatar
mickaelp committed
42
43
44
45
46
47
48
49
use Cake\Cache\Cache;
use Cake\Console\ConsoleErrorHandler;
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
use Cake\Core\Plugin;
use Cake\Database\Type;
use Cake\Datasource\ConnectionManager;
use Cake\Error\ErrorHandler;
Matthieu FAURE's avatar
Matthieu FAURE committed
50
use Cake\Event\EventManager;
mickaelp's avatar
mickaelp committed
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
use Cake\Log\Log;
use Cake\Mailer\Email;
use Cake\Network\Request;
use Cake\Routing\DispatcherFactory;
use Cake\Utility\Security;

/**
 * Read configuration file and inject configuration into various
 * CakePHP classes.
 *
 * By default there is only one configuration file. It is often a good
 * idea to create multiple configuration files, and separate the configuration
 * that changes from configuration that does not. This makes deployment simpler.
 */
try {
    Configure::config('default', new PhpConfig());
    Configure::load('app', 'default', false);
} catch (\Exception $e) {
    die($e->getMessage() . "\n");
}

// Load an environment local configuration file.
// You can use a file like app_local.php to provide local overrides to your
// shared configuration.
//Configure::load('app_local', 'default');

// When debug = false the metadata cache should last
// for a very very long time, as we don't want
// to refresh the cache while users are doing requests.
if (!Configure::read('debug')) {
    Configure::write('Cache._cake_model_.duration', '+1 years');
    Configure::write('Cache._cake_core_.duration', '+1 years');
}

/**
 * Set server timezone to UTC. You can change it to another timezone of your
 * choice but using UTC makes time calculations / conversions easier.
 */
date_default_timezone_set('UTC');

/**
 * Configure the mbstring extension to use the correct encoding.
 */
mb_internal_encoding(Configure::read('App.encoding'));

/**
 * Set the default locale. This controls how dates, number and currency is
 * formatted and sets the default language to use for translations.
 */
Pastor Mickaël's avatar
i18n    
Pastor Mickaël committed
100
DispatcherFactory::add('LocaleSelector');
Pastor Mickaël's avatar
Pastor Mickaël committed
101

Pastor Mickaël's avatar
i18n    
Pastor Mickaël committed
102
//ini_set('intl.default_locale', 'en');
mickaelp's avatar
mickaelp committed
103
104
105
106
107
108
109
110

/**
 * Register application error and exception handlers.
 */
$isCli = PHP_SAPI === 'cli';
if ($isCli) {
    (new ConsoleErrorHandler(Configure::read('Error')))->register();
} else {
Fabrice Gangler's avatar
Fabrice Gangler committed
111
    if (Configure::read('debug') === true) {
112
113
114
115
        // Development Mode ---> display exceptions
        // ---> see #731 for more details
        //               on the current implementation of exception handling
        //               and the other possible implementations.
Fabrice Gangler's avatar
Fabrice Gangler committed
116
    } else {
117
118
119
        // Production Mode ---> no error messages, errors, or warnings shown
        (new ErrorHandler(Configure::read('Error')))->register();
    }
mickaelp's avatar
mickaelp committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
}

// Include the CLI bootstrap overrides.
if ($isCli) {
    require __DIR__ . '/bootstrap_cli.php';
}

/**
 * Set the full base URL.
 * This URL is used as the base of all absolute links.
 *
 * If you define fullBaseUrl in your config file you can remove this.
 */
if (!Configure::read('App.fullBaseUrl')) {
    $s = null;
    if (env('HTTPS')) {
        $s = 's';
    }

    $httpHost = env('HTTP_HOST');
    if (isset($httpHost)) {
        Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
    }
    unset($httpHost, $s);
}

Cache::config(Configure::consume('Cache'));
ConnectionManager::config(Configure::consume('Datasources'));
Email::configTransport(Configure::consume('EmailTransport'));
Email::config(Configure::consume('Email'));
Log::config(Configure::consume('Log'));
Security::salt(Configure::consume('Security.salt'));

/**
 * The default crypto extension in 3.0 is OpenSSL.
 * If you are migrating from 2.x uncomment this code to
 * use a more compatible Mcrypt based implementation
 */
// Security::engine(new \Cake\Utility\Crypto\Mcrypt());

/**
 * Setup detectors for mobile and tablet.
 */
Request::addDetector('mobile', function ($request) {
    $detector = new \Detection\MobileDetect();
    return $detector->isMobile();
});
Request::addDetector('tablet', function ($request) {
    $detector = new \Detection\MobileDetect();
    return $detector->isTablet();
});

/**
 * Custom Inflector rules, can be set to correctly pluralize or singularize
 * table, model, controller names or whatever other string is passed to the
 * inflection functions.
 *
 * Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
 * Inflector::rules('irregular', ['red' => 'redlings']);
 * Inflector::rules('uninflected', ['dontinflectme']);
 * Inflector::rules('transliteration', ['/å/' => 'aa']);
 */

/**
 * Plugins need to be loaded manually, you can either load them one by one or all of them in a single call
 * Uncomment one of the lines below, as you need. make sure you read the documentation on Plugin to use more
 * advanced ways of loading plugins
 *
 * Plugin::loadAll(); // Loads all plugins at once
 * Plugin::load('Migrations'); //Loads a single plugin named Migrations
 *
 */

// Only try to load DebugKit in development mode
// Debug Kit should not be installed on a production system
if (Configure::read('debug')) {
    Plugin::load('DebugKit', ['bootstrap' => true]);
}

DispatcherFactory::add('Asset');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');

/**
 * Enable default locale format parsing.
 * This is needed for matching the auto-localized string output of Time() class when parsing dates.
 */
Type::build('date')->useLocaleParser();
Type::build('datetime')->useLocaleParser();


Matthieu FAURE's avatar
Matthieu FAURE committed
211
212
213
214
/** ===========================================================================
 * COMPTOIR Configuration
 *
 */
215

Matthieu FAURE's avatar
Matthieu FAURE committed
216
Configure::write('DEFAULT_PREFIX', "api/v1");
Matthieu FAURE's avatar
Matthieu FAURE committed
217
218
219

//Initialize the message referring to the Comptoir api documentation
Configure::write('Help', 'Please check the manual at http://comptoir.adullact.org/manual');
Pastor Mickaël's avatar
Pastor Mickaël committed
220

Pastor Mickaël's avatar
Pastor Mickaël committed
221
222
223
224
225
226
227
Configure::write(
    'QueryObject',
    [
        'limit' => 50
    ]
);

Matthieu FAURE's avatar
Matthieu FAURE committed
228
// Initialize the limit parameter for a QueryObject.
229
Configure::write('LIMIT', 3000);
Matthieu FAURE's avatar
Matthieu FAURE committed
230
231

// Initialize the offset parameter for a QueryObject
Matthieu FAURE's avatar
Matthieu FAURE committed
232
Configure::write('OFFSET', 1);
Matthieu FAURE's avatar
Matthieu FAURE committed
233
234

// Initialize the order parameter for a QueryObject
Matthieu FAURE's avatar
Matthieu FAURE committed
235
Configure::write('ORDER', 'asc');
Pastor Mickaël's avatar
Pastor Mickaël committed
236

Matthieu FAURE's avatar
Matthieu FAURE committed
237
//Connect middleware/dispatcher filters.
Matthieu FAURE's avatar
Matthieu FAURE committed
238
Configure::write('TIMEOUT', 10);
Pastor Mickaël's avatar
Pastor Mickaël committed
239

Matthieu FAURE's avatar
Matthieu FAURE committed
240
// Define the limit of software  on the home page
Matthieu FAURE's avatar
Matthieu FAURE committed
241
Configure::write('LIMIT_NUMBER_OF_SOFTWARES_HOME_PAGE', 4);
242

Matthieu FAURE's avatar
Matthieu FAURE committed
243
// Database Name
Matthieu FAURE's avatar
Matthieu FAURE committed
244
Configure::write('DATABASE', 'comptoir');
Pastor Mickaël's avatar
Pastor Mickaël committed
245

Matthieu FAURE's avatar
Matthieu FAURE committed
246
// Schema use in the database
Matthieu FAURE's avatar
Matthieu FAURE committed
247
Configure::write('SCHEMA', 'public');
Pastor Mickaël's avatar
Pastor Mickaël committed
248

Matthieu FAURE's avatar
Matthieu FAURE committed
249
// Database for tests
Matthieu FAURE's avatar
Matthieu FAURE committed
250
Configure::write('DATABASETEST', 'tests');
Pastor Mickaël's avatar
Pastor Mickaël committed
251

Matthieu FAURE's avatar
Matthieu FAURE committed
252
// Max number of elements (screenshots/review...) display
253
254
Configure::write('MAX_DISPLAY', 3);

255
// Min time to send sign up form (limit spam by bots)
256
Configure::write('DEFAULT_MIN_TIME_TO_SEND_SIGNUP_FORM', 5); // 5 secondes
257
258
259
260
261
262
263
if (defined('TEST_BYPASS_DEFAULT_MIN_TIME_TO_SEND_SIGNUP_FORM')) { // used by unit test and CI
    Configure::write('MIN_TIME_TO_SEND_SIGNUP_FORM', TEST_BYPASS_DEFAULT_MIN_TIME_TO_SEND_SIGNUP_FORM);
} else {
    Configure::write('MIN_TIME_TO_SEND_SIGNUP_FORM', Configure::read('DEFAULT_MIN_TIME_TO_SEND_SIGNUP_FORM'));
}


Matthieu FAURE's avatar
Matthieu FAURE committed
264
265
266
267
// Session duration
Configure::write('Session', [
    'defaults' => 'php',
    'cookie' => 'ComptoirDuLibre',
268
269
270

    // Time of inactivity allowed for a user before automatic disconnection
    'timeout' => 180  // 3 h = 3 x 60 minutes
Matthieu FAURE's avatar
Matthieu FAURE committed
271
272
273
]);

// Limit value for software datas
274
275
276
277
278
279
280
281
282
Configure::write(
    'Softwares',
    [
        'scores' => [
            'score_medium' => 50,
            'score_low' => 25,
            'score_high' => 75,
            'score_best' => 100
        ],
Matthieu FAURE's avatar
Matthieu FAURE committed
283
284
        'Rating' => [
            'maximum' => 4
285
286
287
        ],
    ]
);
288

289
290
291

//

Matthieu FAURE's avatar
Matthieu FAURE committed
292
// Version  of comptoir
Fabrice Gangler's avatar
Fabrice Gangler committed
293
294
Configure::write(
    'VERSION',
295
    [
Fabrice Gangler's avatar
Fabrice Gangler committed
296
        "footer" => "v2.11.1_DEV"
297
298
299
    ]
);

300
301
302
303
304
305
try {
    Configure::config('default', new PhpConfig());
    Configure::load('comptoir', 'default', false);
} catch (\Exception $e) {
    exit($e->getMessage() . "\n");
}
306

Matthieu FAURE's avatar
Matthieu FAURE committed
307
308
309
310
311
312
313
/**
 * Listeners declaration
 */
$CrudListener = new \App\Event\CrudListener();
$ContactListener = new \App\Event\ContactListener();
EventManager::instance()->on($CrudListener);
EventManager::instance()->on($ContactListener);
314

Matthieu FAURE's avatar
Matthieu FAURE committed
315
316
317
318
319
/**
 * Plugins
 */
Plugin::load('Josegonzalez/Upload');
Plugin::load('Migrations');
320
Plugin::load('Alt3/Swagger', ['routes' => true]);