I came to the following question/thoughts by chance, when I'v started implement a writer capable to write array configuration into multiple files. It splits configuration by criteria, currently hard-coded by key, later by strategy defined, into different files and join them in a stub-file, which includes the config from separate files.
I use it for example in zfcampus/zf-configuration
, to reduce the configuration file size and split top level keys into separate files. This way I can find things much quicker, if further module-separation is not possible/logical.
Now everything works fine, but I'v noticed, that the API defined by WriterInterface
does not make much sense in my new writer, because toString() would only return the stub-file contents.
This made me think about two possibilities: Either my implementation of WriterInterface
is misusing this interface and it is actually something else, that should internally use Writers, but is itself not a writer or the current spec for Writer in zend-config is to concrete.
My conclusion so far is:
- The job of my
WriterInterface
implementation is really to write the configuration, not something do something else. How it writers, in a single or multiple files, or even maybe not in a file, does not make it something else, than a writer.
- Actually the current
WriterInterface
is rather something like a FileWriterInterface
. A configuration should actually be writable to indefinite type of targets.
Example how it seem logical to me, but if I'm wrong with my thought somewhere, correct me:
interface WriterInterface
{
/**
* Write configuration
*
* @param mixed $config
*/
public function write($config);
}
interface FileWriterInterface extends WriterInterface
{
/**
* Write a config object to a file.
*
* @param string $filename
* @param mixed $config
* @param bool $exclusiveLock
* @return void
*/
public function toFile($filename, $config, $exclusiveLock = true);
/**
* Write a config object to a string.
*
* @param mixed $config
* @return string
*/
public function toString($config);
}
Whether Interfaces like the FileWriterInterface
are actually needed then is another question.
What do you think about it?
Originally posted by @akomm at https://github.com/zendframework/zend-config/issues/7