minor: add $persistentManagerName param
fixes #447
I've not provided tests, because the code is trivial, but this would need to add a new document manager in the test :shrug:
/cc @kerstvo
EDIT: I just realized that adding a param to ModelFactory::repository() will create an error in psalm in userland, because of the @phpstan-method annotation :disappointed:
https://github.com/zenstruck/foundry/actions/runs/4707671150/jobs/8349671474?pr=450#step:8:18
I just realized that adding a param to ModelFactory::repository() will create an error in psalm in userland
You mean on existing factories? I guess we should we update the maker/docs?
You mean on existing factories?
yes, all existing factories will create an error with psalm if we make this move... We can update update maker and docs, but still, this could be pretty annoying...
What about phpstan?
even in max level, phpstan does not complain. But psalm is actually true: one param is missing in the methods prototype in the phpdoc
Huh, well I don't want to not add a feature because it breaks static analysis, but that's just my opinion.
What about starting a UPGRADE.md with a note for the next feature release?
ok, this seems reasonable :)
I feel the same, otherwise it would restrict too much further updates... see this issue as well https://github.com/zenstruck/foundry/issues/445#issuecomment-1500440459
It seems that problem is more complicated.
I apply your changes in my project and got error

I think we need to have a Factory::withManagerName() where you actually configure the alternate manager name per factory.
This would remove the need for $persistentManagerName in ModelFactory::repository() (and not break static analysis for existing factories).
this seems not possible because ModelFactory::repository() is static...
I think this needs to be hardcoded directly in the class, and then have a factory class which is bound to a given manager. ex:
class SomeFactoryForSpecificManager
{
protected static function getClass(): string
{
return SomeEntity::class;
}
protected static function getManagerName(): ?string
{
return 'specific-manager;
}
}
@kerstvo would this fix your problem?
So ModelFactory would look like?
abstract class ModelFactory extends Factory
{
// ...
protected static function getManagerName(): ?string
{
return null;
}
}
That's what I'm suggesting :)
Since we're deprecating ModelFactory soon, maybe we should just add this feature to #452?
We'll need to update some function parameters and the anon. proxy generator.