-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Improved the event subscriber that listens to database exceptions #452
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,16 +28,12 @@ | |
* | ||
* @author Javier Eguiluz <[email protected]> | ||
*/ | ||
class CheckSQLiteEventSubscriber implements EventSubscriberInterface | ||
class CheckRequirementsSubscriber implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var EntityManager | ||
*/ | ||
/** @var EntityManager */ | ||
private $entityManager; | ||
|
||
/** | ||
* CheckSQLiteEventSubscriber constructor. | ||
* | ||
* @param EntityManager $entityManager | ||
*/ | ||
public function __construct(EntityManager $entityManager) | ||
|
@@ -54,9 +50,9 @@ public static function getSubscribedEvents() | |
return [ | ||
// Exceptions are one of the events defined by the Console. See the | ||
// rest here: http://symfony.com/doc/current/components/console/events.html | ||
ConsoleEvents::EXCEPTION => 'handleDatabaseExceptions', | ||
// See: http://api.symfony.com/3.2/Symfony/Component/HttpKernel/KernelEvents.html | ||
KernelEvents::EXCEPTION => 'onKernelException', | ||
ConsoleEvents::EXCEPTION => 'handleConsoleException', | ||
// See: http://api.symfony.com/master/Symfony/Component/HttpKernel/KernelEvents.html | ||
KernelEvents::EXCEPTION => 'handleKernelException', | ||
]; | ||
} | ||
|
||
|
@@ -67,7 +63,7 @@ public static function getSubscribedEvents() | |
* | ||
* @param ConsoleExceptionEvent $event | ||
*/ | ||
public function handleDatabaseExceptions(ConsoleExceptionEvent $event) | ||
public function handleConsoleException(ConsoleExceptionEvent $event) | ||
{ | ||
$commandNames = ['doctrine:fixtures:load', 'doctrine:database:create', 'doctrine:schema:create', 'doctrine:database:drop']; | ||
|
||
|
@@ -80,15 +76,16 @@ public function handleDatabaseExceptions(ConsoleExceptionEvent $event) | |
} | ||
|
||
/** | ||
* This method is triggered when kernel exception occurs. And checks if sqlite extension is enabled. | ||
* This method checks if the triggered exception is related to the database | ||
* and then, it checks if the required 'sqlite3' PHP extension is enabled. | ||
* | ||
* @param GetResponseForExceptionEvent $event | ||
*/ | ||
public function onKernelException(GetResponseForExceptionEvent $event) | ||
public function handleKernelException(GetResponseForExceptionEvent $event) | ||
{ | ||
$exception = $event->getException(); | ||
// Since any exception thrown during a Twig template rendering is wrapped in a Twig_Error_Runtime. | ||
// We must get the original exception. | ||
// Since any exception thrown during a Twig template rendering is wrapped | ||
// in a Twig_Error_Runtime, we must get the original exception. | ||
$previousException = $exception->getPrevious(); | ||
|
||
// Driver exception may happen in controller or in twig template rendering | ||
|
@@ -101,14 +98,14 @@ public function onKernelException(GetResponseForExceptionEvent $event) | |
} | ||
|
||
/** | ||
* Check if demo application is configured to use SQLite as database. | ||
* Checks if the application is using SQLite as its database. | ||
* | ||
* @return bool | ||
*/ | ||
private function isSQLitePlatform() | ||
{ | ||
$databasePlatform = $this->entityManager->getConnection()->getDatabasePlatform(); | ||
|
||
return $databasePlatform ? $databasePlatform->getName() === 'sqlite' : false; | ||
return $databasePlatform ? 'sqlite' === $databasePlatform->getName() : false; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use
current
on the API doc or no ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my first try, but ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then fine with using master