-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Refactor internal classes #646
Conversation
2689f6c
to
b3c497b
Compare
@@ -109,6 +113,7 @@ public function __construct( | |||
$this->outputWriter = $outputWriter ?? new OutputWriter(); | |||
$this->migrationFinder = $finder ?? new RecursiveRegexFinder(); | |||
$this->queryWriter = $queryWriter; | |||
$this->eventDispatcher = new EventDispatcher($this, $this->connection); |
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.
having a circular object graph here is quite unfortunate. Couldn't we handle it differently ?
|
||
public function dispatchEvent(string $eventName, ?EventArgs $args = null) : void | ||
{ | ||
$this->connection->getEventManager()->dispatchEvent($eventName, $args); |
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.
instead of injecting the whole Connection, shouldn't we inject only the EventManager ?
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.
I would not reuse EvM from Connection at all, it's entirely different layer.
use Doctrine\Migrations\Event\MigrationsEventArgs; | ||
use Doctrine\Migrations\Event\MigrationsVersionEventArgs; | ||
|
||
final class EventDispatcher |
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.
I am personally not a big fan of introducing yet another event dispatcher in Doctrine, given that we are looking for replacement of the one in Common for ORM 3.0.
I suppose this would be good as temporary solution until the replacement is found, but then it should be abstracted through interface + marked as interal.
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.
@Majkl578 this is not necessarily a new "EventDispatcher", it is a composition class that depends on the existing Doctrine\Common\EventManager
. I am fine with marking it internal. I don't intend for anyone else to be using this outside of migrations internals.
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.
This is really just an abstraction on top of EventManager and not necessarily a new EventDispatcher. I will mark it as internal.
|
||
public function dispatchEvent(string $eventName, ?EventArgs $args = null) : void | ||
{ | ||
$this->connection->getEventManager()->dispatchEvent($eventName, $args); |
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.
I would not reuse EvM from Connection at all, it's entirely different layer.
lib/Doctrine/Migrations/Version.php
Outdated
@@ -96,7 +81,17 @@ public function __construct( | |||
|
|||
$this->schemaProvider = $schemaProvider; | |||
|
|||
$this->parameterFormatter = new ParameterFormatter($this->connection); | |||
$this->versionExecutor = new VersionExecutor( |
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.
This isn't DI friendly.
lib/Doctrine/Migrations/Version.php
Outdated
{ | ||
$this->markVersion(self::DIRECTION_UP); | ||
$this->state = $state; |
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.
This needs validation of $state
, I think simple assert()
would do.
lib/Doctrine/Migrations/Version.php
Outdated
public function getMigration() : AbstractMigration | ||
{ | ||
return $this->migration; | ||
public function exec( |
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.
No abbreviations 😭, anything wrong with execute()
?
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.
I maintained backwards compatibility. The execute()
method already exists and I didn't want to change the signature of that method.
lib/Doctrine/Migrations/Version.php
Outdated
return $this->time; | ||
} | ||
|
||
public function setTime(float $time) : void |
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.
Instead of doing this, could it be moved to the Result? Or possibly passed around through some ExecutionContext?
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.
Yes, I think we can refactor this further to get rid of all the state in the Version class.
} | ||
|
||
/** | ||
* @param string[]|string $sql |
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.
I'd try to eliminate this by always passing an array of strings (or a collection). This leads to some nasty if-else tricks.
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.
I can make this change here, I won't be able to make the change in the addSql() that the end user uses as it would be a big BC break, but I can make it so the internal addSql here always receives a string[]
or some class/collection of queries.
230bd84
to
b87bf47
Compare
@Majkl578 the advantage of keeping the EventManager of the Connection is that users have a single place to register their listeners, instead of having to gain access to the specific EventManager used by the doctrine/migrations layer (which would make it harder to use doctrine/migrations only as a tool and not as a library). |
That is currently true for DBAL 2.x, but since Doctrine's EvM has uncertain fate, I would be more careful about making it a hard contract, given that DBAL 3 and ORM 3 may ship something different (I assume Migrations 2.0 will eventually support DBAL 3). |
Well, would doctrine/migrations wait for the DBAL 3 release to be released, or do you plan to release it sooner ? If you want to be able to support DBAL 3, it might be quite hard to release migrations 2.x sooner, as it might require other API changes to support it. And if we wait, we can keep this implementation until the future of EvM gets settled. |
@stof I don't want to wait for DBAL 3.0. We can make another release for 3.0 at a later date once that happens. |
Then I vote for keeping the usage of the EvM of the connection for now, to make the upgrade to doctrine/migrations easy (listeners would work the same than in 1.x for users), and making a new major version of doctrine/migrations for DBAL 3.0 if needed, based on what the DBAL 3 support involves |
@stof Agree. This is my current plan. |
2bdc913
to
017676e
Compare
|
||
public function setError(bool $error) : bool | ||
{ | ||
$this->error = $error; |
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.
As scrutinizer points out, this will crash due to void return in non-void method.
6a2f3d2
to
93253f5
Compare
93253f5
to
9103d17
Compare
Fixes #645
Fixes #629
I moved stuff around and refactored but maintained BC in the public API. There is more to do in general but to avoid a monster PR I think this is all I want to do for now.