/** * Reads a config file from the given location and returns it's * data as an associative array. * * @param mixed $location location of config file (as a string with a file or directory path) * * @return array config data * * @throws \InvalidArgumentException on errors like missing config file */ protected function readLocation($location) { $reader = null; if (is_dir($location)) { $base_location = Validator::fixPath(Validator::fixRelativePath($location)); foreach ($this->default_filenames as $filename) { $file = $base_location . $filename; if (is_readable($file)) { try { $reader = $this->getReaderByExtension($file); break; // found possible config file \o/ } catch (\InvalidArgumentException $e) { // next attempt as extension has no handler } } // next attempt, as file is not readable or does not exist } if (!$reader instanceof IConfigReader) { throw new \InvalidArgumentException('Could not find an environaut config file in "' . $base_location . '".' . PHP_EOL . 'Attempted files were: ' . implode(', ', $this->default_filenames) . '.' . PHP_EOL . 'Try calling from a different folder or specify a file using the "--config" option.'); } } elseif (is_file($location)) { $reader = $this->getReaderByExtension($location); } else { throw new \InvalidArgumentException('Currently only regular files and directories are supported for config file reading.'); } $config_data = $reader->getConfigData($location); return $config_data; }
public function testFileIsNotAReadableDirectory() { $this->setExpectedException('InvalidArgumentException'); Validator::readableDirectory(__FILE__); }