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

Refactor internal classes #646

Merged
merged 2 commits into from
May 7, 2018
Merged

Refactor internal classes #646

merged 2 commits into from
May 7, 2018

Conversation

jwage
Copy link
Member

@jwage jwage commented May 7, 2018

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.

@jwage jwage added this to the 2.0 milestone May 7, 2018
@jwage jwage self-assigned this May 7, 2018
@jwage jwage force-pushed the refactor-internal-classes branch 2 times, most recently from 2689f6c to b3c497b Compare May 7, 2018 04:56
@jwage jwage changed the title [WIP] Refactor internal classes Refactor internal classes May 7, 2018
@jwage jwage requested a review from Majkl578 May 7, 2018 05:09
@@ -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);
Copy link
Member

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);
Copy link
Member

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 ?

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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);
Copy link
Contributor

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.

@@ -96,7 +81,17 @@ public function __construct(

$this->schemaProvider = $schemaProvider;

$this->parameterFormatter = new ParameterFormatter($this->connection);
$this->versionExecutor = new VersionExecutor(
Copy link
Contributor

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.

{
$this->markVersion(self::DIRECTION_UP);
$this->state = $state;
Copy link
Contributor

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.

public function getMigration() : AbstractMigration
{
return $this->migration;
public function exec(
Copy link
Contributor

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()?

Copy link
Member Author

@jwage jwage May 7, 2018

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.

return $this->time;
}

public function setTime(float $time) : void
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

@jwage jwage May 7, 2018

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.

@jwage jwage force-pushed the refactor-internal-classes branch 2 times, most recently from 230bd84 to b87bf47 Compare May 7, 2018 14:51
@stof
Copy link
Member

stof commented May 7, 2018

@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).

@Majkl578
Copy link
Contributor

Majkl578 commented May 7, 2018

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).

@stof
Copy link
Member

stof commented May 7, 2018

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.

@jwage
Copy link
Member Author

jwage commented May 7, 2018

@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.

@stof
Copy link
Member

stof commented May 7, 2018

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

@jwage
Copy link
Member Author

jwage commented May 7, 2018

@stof Agree. This is my current plan.

@jwage jwage force-pushed the refactor-internal-classes branch 4 times, most recently from 2bdc913 to 017676e Compare May 7, 2018 20:03

public function setError(bool $error) : bool
{
$this->error = $error;
Copy link
Contributor

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.

@jwage jwage force-pushed the refactor-internal-classes branch 6 times, most recently from 6a2f3d2 to 93253f5 Compare May 7, 2018 20:55
@jwage jwage force-pushed the refactor-internal-classes branch from 93253f5 to 9103d17 Compare May 7, 2018 21:51
@jwage jwage merged commit 12f4fc8 into master May 7, 2018
@Majkl578 Majkl578 deleted the refactor-internal-classes branch May 7, 2018 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants