public function __construct()

in lib/php/libsdk/SDK/Build/PGO/Config.php [21:61]


	public function __construct(int $mode = self::MODE_RUN)
	{
		if (self::MODE_CHECK_INIT == $mode) {
			// XXX The check is simple right now, so this is sufficient. 
			return;
		}

		if (!$this->isInitialized()) {
			$this->initWorkDir();
		}

		if (self::MODE_REINIT == $mode) {
			$fn = $this->getWorkSectionsFilename();
			if (file_exists($fn)) {
				unlink($fn);
			}
			$mode = self::MODE_INIT;
		}

		$this->mode = $mode;


		if (self::MODE_INIT == $mode) {
			foreach (array("nginx", "mariadb", "postgresql", "php") as $i) {
				$this->importSectionFromDir($i, $this->getTplDir() . DIRECTORY_SEPARATOR . $i);
			}
		} else if (self::MODE_RUN == $mode) {
			$fn = $this->getWorkSectionsFilename();
			if (!file_exists($fn)) {
				throw new Exception("Required config doesn't exist under '$fn'.");
			}
			$s = file_get_contents($fn);
			$this->sections = json_decode($s, true);
			foreach($this->sections as $k => $v) {
				$this->importTplVars($k, $v);
			}

		} else {
			throw new Exception("Unknown config mode '$mode'.");
		}
	}