Skip to content
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
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
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