Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access ReferenceValidator at runtime #22

Open
FaKleiser opened this issue Apr 7, 2016 · 0 comments
Open

Access ReferenceValidator at runtime #22

FaKleiser opened this issue Apr 7, 2016 · 0 comments

Comments

@FaKleiser
Copy link

Hey, thank you for the great project! I am trying to invoke PhpDA from within another console application and thus not directly using the CLI scripts the project provides. What I would like to do now is to define a more sophisticated ReferenceValidator that requires some configuration at runtime.

Currently, the ReferenceValidator does not support constructor-injection, as the validator is simply instantiated by the plugin loader (which is totally fine for the CLI usage). Also, it is not possible to somehow get the instantiated ReferenceValidator by the API and therefore it is also not possible to use setter-injection.

A simple way to enable either-or is to change the current config implementation as follows:

public function getReferenceValidator()
{
    if (!is_null($this->referenceValidator) && !is_string($this->referenceValidator) && !($this->referenceValidator instanceof ValidatorInterface)) {
        throw new \InvalidArgumentException('Config for referenceValidator must be an string');
    }
    return $this->referenceValidator;
}

The plugin loader would then need to check whether there is already an object coming from the config and then skip instantiation. I guess the proposed approach seems a bit like a workaround, but it should work at least :-).

What do you think? If the proposed approach is fine for you I'd be happy to help with the implementation!

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

No branches or pull requests

2 participants