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

minor: add $persistentManagerName param #450

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function delayFlush(callable $callback): mixed
* @phpstan-param Proxy<TObject>|TObject|class-string<TObject> $objectOrClass
* @phpstan-return RepositoryProxy<TObject>
*/
public function repositoryFor(object|string $objectOrClass): RepositoryProxy
public function repositoryFor(object|string $objectOrClass, string|null $persistentManagerName = null): RepositoryProxy
{
if ($objectOrClass instanceof Proxy) {
$objectOrClass = $objectOrClass->object();
Expand All @@ -186,7 +186,7 @@ public function repositoryFor(object|string $objectOrClass): RepositoryProxy
}

/** @var EntityRepository<TObject>|null $repository */
$repository = $this->managerRegistry()?->getRepository($objectOrClass);
$repository = $this->managerRegistry()?->getRepository($objectOrClass, $persistentManagerName);

if (!$repository) {
throw new \RuntimeException(\sprintf('No repository registered for "%s".', $objectOrClass));
Expand Down
4 changes: 2 additions & 2 deletions src/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ final public static function assert(): RepositoryAssertions
/**
* @phpstan-return RepositoryProxy<TModel>
*/
final public static function repository(): RepositoryProxy
final public static function repository(string|null $persistentManagerName = null): RepositoryProxy
{
return static::configuration()->repositoryFor(static::getClass());
return static::configuration()->repositoryFor(static::getClass(), $persistentManagerName);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ public function forceGet(string $property)
return Instantiator::forceGet($this->object(), $property);
}

public function repository(): RepositoryProxy
public function repository(string|null $persistentManagerName = null): RepositoryProxy
{
return Factory::configuration()->repositoryFor($this->class);
return Factory::configuration()->repositoryFor($this->class, $persistentManagerName);
}

public function enableAutoRefresh(): self
Expand Down
4 changes: 2 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ function instantiate_many(int $number, string $class, array|callable $attributes
*
* @return RepositoryProxy<TObject>
*/
function repository(object|string $objectOrClass): RepositoryProxy
function repository(object|string $objectOrClass, string|null $persistentManagerName = null): RepositoryProxy
{
return Factory::configuration()->repositoryFor($objectOrClass);
return Factory::configuration()->repositoryFor($objectOrClass, $persistentManagerName);
}

/**
Expand Down