loadOptions(); * echo $options->pluginPublicUrl; * * @throws InvalidPluginRootPathException * @throws JsonException */ public function loadOptions(): UcrmOptions { if (! $this->options) { $this->updateOptions(); } return $this->options; } /** * Refreshes the cached instance of UcrmOptions held in this class. * * Example usage: * * $ucrmOptionsManager = new UcrmOptionsManager(); * $options = $ucrmOptionsManager->loadOptions(); * * // ... long operation ... * // ... long operation ... * // ... long operation ... * * $ucrmOptionsManager->updateOptions(); * // options are now up to date * $options = $ucrmOptionsManager->loadOptions(); * * @throws InvalidPluginRootPathException * @throws JsonException */ public function updateOptions(): void { $this->options = $this->getOptions(); } /** * @throws InvalidPluginRootPathException * @throws JsonException */ private function getOptions(): UcrmOptions { $options = new UcrmOptions(); $reflectionClass = new \ReflectionClass($options); $data = $this->getDataFromJson(self::UCRM_JSON); foreach ($reflectionClass->getProperties() as $reflectionProperty) { if (array_key_exists($reflectionProperty->getName(), $data)) { $reflectionProperty->setValue($options, $data[$reflectionProperty->getName()]); } } return $options; } }