mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-22 06:23:01 +00:00
Add production optimisations
This commit is contained in:
parent
edf52fe3df
commit
9f0442d1cf
3 changed files with 23 additions and 8 deletions
19
api.php
19
api.php
|
@ -12,14 +12,27 @@ $autoloader->addPrefix("AirQuality", "logic");
|
||||||
$autoloader->addPrefix("SBRL", "lib/SBRL");
|
$autoloader->addPrefix("SBRL", "lib/SBRL");
|
||||||
$autoloader->register();
|
$autoloader->register();
|
||||||
|
|
||||||
|
// 2: Settings
|
||||||
|
$settings = new \SBRL\TomlConfig(
|
||||||
|
"data/settings.toml",
|
||||||
|
"settings.default.toml"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// 2: Dependency injection
|
// 2: Dependency injection
|
||||||
|
|
||||||
$di_builder = new DI\ContainerBuilder();
|
$di_builder = new DI\ContainerBuilder();
|
||||||
$di_builder->addDefinitions("di_config.php");
|
$di_builder->addDefinitions("di_config.php");
|
||||||
// TODO: In production, we should use something like this - see http://php-di.org/doc/container-configuration.html
|
if($settings->get("env.mode") == "production") {
|
||||||
// $builder->enableCompilation(__DIR__ . '/tmp');
|
// http://php-di.org/doc/container-configuration.html
|
||||||
// $builder->writeProxiesToFile(true, __DIR__ . '/tmp/proxies');
|
if(!file_exists(ROOT_DIR."data/cache/php_di"))
|
||||||
|
mkdir(ROOT_DIR."data/cache/php_di", 0700);
|
||||||
|
$builder->enableCompilation(ROOT_DIR."data/cache/php_di");
|
||||||
|
|
||||||
|
if(!file_exists(ROOT_DIR."data/cache/php_di_proxies"))
|
||||||
|
mkdir(ROOT_DIR."data/cache/php_di_proxies", 0700);
|
||||||
|
$builder->writeProxiesToFile(true, ROOT_DIR."data/cache/php_di_proxies");
|
||||||
|
}
|
||||||
|
|
||||||
$di_container = $di_builder->build();
|
$di_container = $di_builder->build();
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,9 @@ return [
|
||||||
"settings.file_default" => "data/settings.toml",
|
"settings.file_default" => "data/settings.toml",
|
||||||
"settings.file_custom" => "settings.default.toml",
|
"settings.file_custom" => "settings.default.toml",
|
||||||
|
|
||||||
\SBRL\TomlConfig::class => function(ContainerInterface $c) {
|
TomlConfig::class => function(ContainerInterface $c) {
|
||||||
return new TomlConfig(
|
global $settings;
|
||||||
$c->get("settings.file_default"),
|
return $settings;
|
||||||
$c->get("settings.file_custom")
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
IDeviceRepository::class => DI\autowire(MariaDBDeviceRepository::class),
|
IDeviceRepository::class => DI\autowire(MariaDBDeviceRepository::class),
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
# Your changes may be overwritten in a future update.
|
# Your changes may be overwritten in a future update.
|
||||||
# Instead, edit the custom configuration file located at "data/settings.toml".
|
# Instead, edit the custom configuration file located at "data/settings.toml".
|
||||||
|
|
||||||
|
[env]
|
||||||
|
# The operating mode. Can be either "development", or "production" (default; activates a number of optimisations which might make development harder, such as 3rd-party library caches)
|
||||||
|
mode = "production"
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
# Settings that control the database, or the connection to it
|
# Settings that control the database, or the connection to it
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue