Add production optimisations

pull/26/head
Starbeamrainbowlabs 4 years ago
parent edf52fe3df
commit 9f0442d1cf
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 19
      api.php
  2. 8
      di_config.php
  3. 4
      settings.default.toml

@ -12,14 +12,27 @@ $autoloader->addPrefix("AirQuality", "logic");
$autoloader->addPrefix("SBRL", "lib/SBRL");
$autoloader->register();
// 2: Settings
$settings = new \SBRL\TomlConfig(
"data/settings.toml",
"settings.default.toml"
);
// 2: Dependency injection
$di_builder = new DI\ContainerBuilder();
$di_builder->addDefinitions("di_config.php");
// TODO: In production, we should use something like this - see http://php-di.org/doc/container-configuration.html
// $builder->enableCompilation(__DIR__ . '/tmp');
// $builder->writeProxiesToFile(true, __DIR__ . '/tmp/proxies');
if($settings->get("env.mode") == "production") {
// http://php-di.org/doc/container-configuration.html
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();

@ -16,11 +16,9 @@ return [
"settings.file_default" => "data/settings.toml",
"settings.file_custom" => "settings.default.toml",
\SBRL\TomlConfig::class => function(ContainerInterface $c) {
return new TomlConfig(
$c->get("settings.file_default"),
$c->get("settings.file_custom")
);
TomlConfig::class => function(ContainerInterface $c) {
global $settings;
return $settings;
},
IDeviceRepository::class => DI\autowire(MariaDBDeviceRepository::class),

@ -3,6 +3,10 @@
# Your changes may be overwritten in a future update.
# 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]
# Settings that control the database, or the connection to it

Loading…
Cancel
Save