-
-
Notifications
You must be signed in to change notification settings - Fork 207
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
Config merge is too late #151
Comments
PR: #152 |
The idea with the I'm not necessarily opposed to changing how the configuration works. However, I'm not completely sold on the implementation in #152 for a couple reasons:
That being said, I'm definitely open to hearing your thoughts - you're welcome to try changing my mind :) I appreciate you taking the time to share your thoughts and proposal! |
Thanks for the explanation. The problem I see with that option is that if you need to execute some code depending on the Config, you will execute this code each time you convert an HTML fragment. I have a case in a import: I instanciate once the HtmlConverter and for each piece of content in my source, I use it to convert the HTML in MD. I need it for #154 to work, but will try different approach |
Okay, I see where you're coming from. I would still like to keep the current functionality as-is though. For your use case, I'd recommend doing something like this: class HtmlConverter implements ConverterInterface, ConfigurationAwareInterface
{
private $foo; // null until convert() is called
public function convert(ElementInterface $element)
{
if ($this->foo === null) {
$this->foo = new Whatever(); // lazy-instantiate whatever you need here based on the config
}
// $this->foo will always be the same instance now
}
} |
I think that the config merge in HtmlConverter::__construct() happens too late because the setConfig() of ConfigurationAwareInterface converters has already be called with the default config.
It will allow to set some properties on the object once at setConfig() and to re-use these properties in convert() without executing several times the code to set those properties
PR will follow
The text was updated successfully, but these errors were encountered: