Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ignore errors while loading ObjectManager #662

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

Draft
ruudk wants to merge 1 commit into phpstan:2.0.x
base: 2.0.x
Choose a base branch
Loading
from ruudk:catch-object-manager-errors
Draft
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
12 changes: 11 additions & 1 deletion src/Doctrine/DoctrineDiagnoseExtension.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,22 @@ public function __construct(

public function print(Output $output): void
{
$objectManager = $this->objectMetadataResolver->getObjectManager();

$output->writeLineFormatted(sprintf(
'<info>Doctrine\'s objectManagerLoader:</info> %s',
$this->objectMetadataResolver->hasObjectManagerLoader() ? 'In use' : 'No',
));

$objectManager = $this->objectMetadataResolver->getObjectManager();
if ($this->objectMetadataResolver->getLastError() !== null) {
$output->writeLineFormatted(sprintf(
'<error>Doctrine\'s objectManagerLoader error:</error> %s',
$this->objectMetadataResolver->getLastError()->getMessage(),
));

$output->writeLineFormatted('');
}

if ($objectManager instanceof EntityManagerInterface) {
$connection = $objectManager->getConnection();
$driver = $this->driverDetector->detect($connection);
Expand Down
16 changes: 15 additions & 1 deletion src/Type/Doctrine/ObjectMetadataResolver.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\Doctrine\Mapping\ClassMetadataFactory;
use PHPStan\ShouldNotHappenException;
use ReflectionException;
use Throwable;
use function class_exists;
use function is_file;
use function is_readable;
Expand All @@ -26,6 +27,8 @@ final class ObjectMetadataResolver

private string $tmpDir;

private ?Throwable $lastError = null;

public function __construct(
?string $objectManagerLoader,
string $tmpDir
Expand Down Expand Up @@ -89,6 +92,11 @@ public function isTransient(string $className): bool
}
}

public function getLastError(): ?Throwable
{
return $this->lastError;
}

private function getMetadataFactory(): ?ClassMetadataFactory
{
if ($this->metadataFactory !== null) {
Expand Down Expand Up @@ -160,7 +168,13 @@ private function loadObjectManager(string $objectManagerLoader): ?ObjectManager
));
}

return require $objectManagerLoader;
try {
return require $objectManagerLoader;
} catch (Throwable $error) {
$this->lastError = $error;

return null;
}
}

}
Loading

AltStyle によって変換されたページ (->オリジナル) /