/** * Tests that no output file is written if logging is disabled */ public function testDisabledLogging() { unlink($this->tempName); Configuration::setOption("partkeepr.logger.enable", false); Logger::log("test", Logger::LOGLEVEL_CRITICAL); $this->assertEquals(false, file_exists($this->tempName)); }
public function testConfiguration() { Configuration::setOption("test", "value"); $this->assertEquals(Configuration::getOption("test"), "value"); /* Test for the default value of bool false */ $this->assertEquals(Configuration::getOption("test2"), false); /* Test for an user-specified default value */ $this->assertEquals(Configuration::getOption("test2", "default"), "default"); }
<?php namespace PartKeepr; use PartKeepr\Util\Configuration; Configuration::setOption("partkeepr.database.dbname", "partkeepr-test"); Configuration::setOption("partkeepr.database.driver", "pdo_sqlite");
/** * Sets the database configuration array from $_REQUEST */ public static function setDatabaseConfigurationFromRequest() { if (isset($_REQUEST["dbname"])) { PartKeeprConfiguration::setOption("partkeepr.database.dbname", $_REQUEST["dbname"]); } if (isset($_REQUEST["user"])) { PartKeeprConfiguration::setOption("partkeepr.database.username", $_REQUEST["user"]); } if (isset($_REQUEST["password"])) { PartKeeprConfiguration::setOption("partkeepr.database.password", $_REQUEST["password"]); } if (isset($_REQUEST["host"])) { PartKeeprConfiguration::setOption("partkeepr.database.host", $_REQUEST["host"]); } if (isset($_REQUEST['port'])) { PartKeeprConfiguration::setOption("partkeepr.database.port", $_REQUEST["port"]); } switch ($_REQUEST["driver"]) { case "mysql": PartKeeprConfiguration::setOption("partkeepr.database.driver", "pdo_mysql"); break; case "pgsql": PartKeeprConfiguration::setOption("partkeepr.database.driver", "pdo_pgsql"); break; default: throw new \Exception(sprintf("Invalid driver %s specified.", $_REQUEST["driver"])); break; } }
/** * Initializes the configuration for a given environment. * * An environment is used to load a different configuration file. * * Usually, you don't need to pass anything here. * * * @param $environment string The environment to use, null otherwise. * @return nothing */ public static function initializeConfig($environment = null) { if ($environment != null) { $config = self::getRootDirectory() . "/config-{$environment}.php"; } else { $config = self::getRootDirectory() . "/config.php"; } if (file_exists($config)) { include $config; } // Check if the files path is set. If not, fall back to <partkeepr-root>/data/ if (PartKeeprConfiguration::getOption("partkeepr.files.path", null) === null) { PartKeeprConfiguration::setOption("partkeepr.files.path", PartKeepr::getRootDirectory() . "/data/"); } // Check if the image path is set. If not, fall back to <configured-files-directory>/images/ if (PartKeeprConfiguration::getOption("partkeepr.images.path", null) === null) { PartKeeprConfiguration::setOption("partkeepr.images.path", PartKeeprConfiguration::getOption("partkeepr.files.path") . "images/"); } // Check if the image cache path is set. If not, fall back to <configured-images-directory>/images/ if (PartKeeprConfiguration::getOption("partkeepr.images.cache", null) === null) { PartKeeprConfiguration::setOption("partkeepr.images.cache", PartKeeprConfiguration::getOption("partkeepr.images.path") . "cache/"); } }