function load($filename) { $file = new \SplFileInfo($filename); $cacheDir = $this->cacheDir . '/config'; $cachedConfig = $cacheDir . '/' . $file->getFilename() . '.cache'; $hash = md5(file_get_contents($filename)); if (!file_exists($cacheDir)) { mkdir($cacheDir, 0750, true); } if (file_exists($cachedConfig)) { $config = (require $cachedConfig); if ($hash === $config['hash']) { unset($config['hash']); return $config; } } $config = $this->driver->load($filename); file_put_contents($cachedConfig, '<?php return ' . var_export($config + array('hash' => $hash), true) . ' ?>'); return $config; }
private function readConfig() { if (!$this->filename) { throw new \RuntimeException('A valid configuration file must be passed before reading the config.'); } if (!file_exists($this->filename)) { throw new \InvalidArgumentException(sprintf("The config file '%s' does not exist.", $this->filename)); } if ($this->driver->supports($this->filename)) { return $this->driver->load($this->filename); } throw new \InvalidArgumentException(sprintf("The config file '%s' appears to have an invalid format.", $this->filename)); }