fix: 🐛 use isser instead of constructor to apply autorefresh setting to Factory#998
Conversation
parent::__construct() call to Factory templateparent::__construct() call to Factory template
There was a problem hiding this comment.
Hi!
thanks for this! This means that maybe a lot of factories in the wild won't benefit from auto refresh 🤔
Maybe we should modify PersistentObjectFactory in a way that it could handle the case where $autorefreshEnabled has never been initialized?
Please, adapt the tests: you'll need to add parent::__construct() where it is needed in https://github.com/zenstruck/foundry/tree/2.x/tests/Fixture/Maker/expected
|
@nikophil I fixed test fixtures! Please review again.
I think since However, if we would like to take maximum consideration into account users who are unintentionally missing out on the benefits of autorefresh due to this bug, we may be able to take additional measures, such as the following:
|
cool thanks
not sure... think of this situation: # config/packages/zenstruck_foundry.yaml
zenstruck_foundry:
enable_auto_refresh_with_lazy_objects: trueclass SomeFactory extends PersistentObjectFactory
{
public function __construct(
// ... some dependencies ...
){
// no call to parent
}
}the user explicitly asks for auto refresh to be enabled. But I think we should do something like that: // PersistentObjectFactory
private bool|null $autorefreshEnabled;
private function isAutorefreshEnabled(): bool
{
return $this->autorefreshEnabled ??= Configuration::autoRefreshWithLazyObjectsIsEnabled();
}and use WDYT? |
In conclusion, I completely agree. I think there are two possible approaches for existing users whose automatic updates are disabled due to this bug.
Option 2 is the most cautious approach, but it could be considered a bit excessive. Personally, I think option 1 is fine. And in that case, I think the example you provided is a very safe and good approach. In any case, I don't think there's any need to address this issue in this PR. Why not merge this PR for now and address any additional issues in a separate PR? |
|
Actually, I do think if we implement the approach I'm suggesting, we do not need to impact the template : we should remove the constructor from using the constructor was a mistake in the first place. Sorry for the work which needs to be undone |
|
Ah, I understand. You're absolutely right. I'll update the PR later! |
|
thank you! |
…to Factory The template of Factory that inherit from `PersistentObjectFactory` has constructor but is missing parent::__construct() call. Therefore, we will modify `PersistentObjectFactory` so that the settings are applied implicitly via isser instead of the constructor.
691e832 to
e432cf1
Compare
|
thanks @ttskch |
parent::__construct() call to Factory template
Although
PersistentObjectFactoryhas a constructor, the template of Factory that inherit from it is missingparent::__construct()call. This PR adds that. Thanks.