module = $module; } /** * Get value from .env.json and .env.local.json from the module * * @param string $key * @return mixed */ public function get($key) { $this->load(); if (!isset($this->data[$key])) { return null; } return $this->data[$key]; } /** * @return void */ protected function load() { if ($this->data !== null) { return; } $this->data = []; $path = $this->module->getLocalPath(); $this->loadFile("{$path}.env.json"); $this->loadFile("{$path}.env.local.json"); } /** * @param string $file * @return void */ protected function loadFile($file) { if (!file_exists($file)) { return; } $json = file_get_contents($file); $data = json_decode($json, true); if (!is_array($data)) { return; } $this->data = array_merge($this->data, $data); } }