Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Questions/thoughts regarding WriterInterface #7

Open
akomm opened this issue Sep 24, 2015 · 1 comment
Open

Questions/thoughts regarding WriterInterface #7

akomm opened this issue Sep 24, 2015 · 1 comment

Comments

@akomm
Copy link

akomm commented Sep 24, 2015

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?

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-config; a new issue has been opened at laminas/laminas-config#5.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants