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

Drop Flyweight pattern #5036

Merged
merged 1 commit into from
Feb 5, 2022
Merged

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Nov 27, 2021

There is a growing need for types with parameters, and that pattern was
probably used out of concerns that are no longer relevant anyway.

The documentation needs to be updated, but sits in the wrong repository 🙈

EDIT: actually there is also one in this repository: https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types 🤔

@greg0ire greg0ire force-pushed the drop-flyweight-pattern branch from 32179bb to ca8dfbb Compare November 27, 2021 14:20
@greg0ire greg0ire marked this pull request as ready for review November 27, 2021 14:28
@greg0ire greg0ire force-pushed the drop-flyweight-pattern branch 3 times, most recently from dadfde0 to abb477f Compare November 27, 2021 14:35
'aes-256-cbc-hmac-sha256',
'/path/to/secret',
$secretStore
));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this paragraph is a how-to, the one above it is as well, and the DBAL docs do not have a cookbook/how-to section. Not sure what to do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to keep it here.

@derrabus
Copy link
Member

Because this PR implements a new feature, it should target the 3.3.x branch.

@greg0ire greg0ire changed the base branch from 3.2.x to 3.3.x November 27, 2021 17:21
@greg0ire greg0ire force-pushed the drop-flyweight-pattern branch 2 times, most recently from 3c3b6af to 87fa225 Compare November 27, 2021 17:34
@morozov
Copy link
Member

morozov commented Nov 27, 2021

Given that the types are no longer identified by their names, what's the point of the name?

@greg0ire
Copy link
Member Author

Given that the types are no longer identified by their names, what's the point of the name?

If for some reason, you have 2 instances of EncryptedType, you will have to make EncryptedType::getName() dynamic because it's not possible to register 2 types with the same name, because a type instance is still identified by its name.

@morozov
Copy link
Member

morozov commented Nov 28, 2021

I still have a feeling that it isn't the next step in refactoring the type system. If there's no clear understanding of whether the type names are needed, and the names are potentially related to the types being flyweights, I'd pause here and clean up the naming.

The need to define the type name twice and declare it in the class dynamically depending on the implementation is a footgun that IMO needs to be addressed first of all.

If you believe this PR is the right next step, we can proceed.

@greg0ire greg0ire force-pushed the drop-flyweight-pattern branch from 87fa225 to 37006dd Compare November 28, 2021 18:57
morozov
morozov previously approved these changes Nov 28, 2021
@greg0ire
Copy link
Member Author

@morozov there is no hurry for this PR, we can pause it. I noticed that there is no mention of DC2Type inside docs, this might be worth an explanation (in the sense of the website you showed me, https://documentation.divio.com). Once we have that, we can see if we can work around it, for instance by having the type registry "keys" be used instead of calling getName(). The current implementation of TypeRegistry::lookupName looks like it would just work. I didn't pay enough attention and didn't see it was implemented with array_search and an object, which I have never used like this in my life.

Consequently, there is no need to deprecate lookupName in this PR.

@greg0ire greg0ire force-pushed the drop-flyweight-pattern branch 2 times, most recently from 52ac4c3 to 431b39e Compare November 28, 2021 21:45
@greg0ire greg0ire marked this pull request as draft November 28, 2021 22:19
@derrabus derrabus changed the base branch from 3.3.x to 3.4.x January 18, 2022 00:44
@morozov
Copy link
Member

morozov commented Jan 27, 2022

Now that the confusion about using the type name twice has been eliminated in #5208, would it make sense to retarget this patch for 4.0.x?

@greg0ire
Copy link
Member Author

Yes it would, I was planning on doing it soon ™️

@greg0ire greg0ire mentioned this pull request Feb 2, 2022
9 tasks
@greg0ire greg0ire force-pushed the drop-flyweight-pattern branch from 431b39e to 3effd54 Compare February 2, 2022 18:35
@greg0ire greg0ire changed the base branch from 3.4.x to 4.0.x February 2, 2022 18:35
@greg0ire greg0ire force-pushed the drop-flyweight-pattern branch 2 times, most recently from dedac93 to d92bd55 Compare February 2, 2022 18:38
@greg0ire greg0ire marked this pull request as ready for review February 2, 2022 18:44
@greg0ire greg0ire requested a review from morozov February 5, 2022 11:17
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-wise looks good. Just a few nitpicks on documentation and tests.


public function convertToPHPValue($value, AbstractPlatform $platform): string
{
return openssl_decrypt(
Copy link
Member

@morozov morozov Feb 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, encryption is a quite specific and sophisticated domain to be used to illustrate a concept of types. It's also not self-contain since it depends on a SecretStore which isn't declared in the example.

It's better to use a dummy example with a prefix that doesn't distract from the subject.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I tried to dumb it down to a less realistic but more simple use case.

$this->registry->register('sameButDifferent', $newType);
self::assertSame(
$this->registry->get('some'),
$this->registry->get('sameButDifferent')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"sameButDifferent" is really confusing to read. Why not just use some arbitrary keys like "type1" and "type2"? The fact that they are represented by the same object will be clear from the context and doesn't have to be expressed in the names.

'aes-256-cbc-hmac-sha256',
'/path/to/secret',
$secretStore
));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to keep it here.

There is a growing need for types with parameters, and that pattern was
probably used out of concerns that are no longer relevant anyway.
@greg0ire greg0ire force-pushed the drop-flyweight-pattern branch from d92bd55 to 96c2ebf Compare February 5, 2022 16:56
@greg0ire greg0ire added this to the 4.0.0 milestone Feb 5, 2022
@greg0ire greg0ire merged commit 1ebc9eb into doctrine:4.0.x Feb 5, 2022
@greg0ire greg0ire deleted the drop-flyweight-pattern branch February 5, 2022 17:15
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants