public function read($filename) { Assertion::file($filename); $this->filename = $filename; $config = json_decode(file_get_contents($filename), true); if (json_last_error() !== JSON_ERROR_NONE) { throw InvalidConfigException::fromJSONFileError($filename, $this->getJsonError()); } return $config; }
/** * @param string $name * @param array $config * * @throws InvalidConfigException * * @return string */ private function className($name, array $config) { if (isset($config['class']) && isset($config['factory'])) { throw InvalidConfigException::fromNameWhenClassAndFactorySpecified($name); } if (isset($config['class']) && isset($config['service'])) { throw InvalidConfigException::fromNameWhenClassAndServiceSpecified($name); } if (isset($config['factory']) && isset($config['service'])) { throw InvalidConfigException::fromNameWhenFactoryAndServiceSpecified($name); } if (isset($config['service'])) { return $config['service']; } if (isset($config['class'])) { return $config['class']; } if (isset($config['factory'])) { return $config['factory']; } return $name; }
private function assertConfigIsValid($config) { if (!is_array($config)) { throw InvalidConfigException::fromPHPFileError($this->filename); } }
public function testItCanBeCreatedFromNameWhenFactoryAndServiceAreSpecified() { assertSame('Both "factory" and "service" are specified for service "example"; these cannot be used together.', InvalidConfigException::fromNameWhenFactoryAndServiceSpecified('example')->getMessage()); }