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

Add config options to allow fields to be updated using a setter method. #2645

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

fwolfsjaeger
Copy link
Contributor

@fwolfsjaeger fwolfsjaeger commented Jul 3, 2023

Feature request: #2644

This change is applied in Blameable, IpTraceable, SoftDeleteable & Timestampable annotations. The new attribute "setterMethod" can be passed to specify the setter method to be used for a field. If no setter method is specified, the property value would be set directly as before.

@fwolfsjaeger
Copy link
Contributor Author

I would like to add tests for those changes as well. Do you want a separate/duplicated test for every affected annotation/listener?

@RomanApunts
Copy link

I'm interested with this functionality.

I hope soon will merged to master.

src/AbstractTrackingListener.php Show resolved Hide resolved
src/Mapping/Driver/AbstractAnnotationDriver.php Outdated Show resolved Hide resolved
@yakobe
Copy link

yakobe commented Nov 27, 2023

I'm also interested in this functionality. At the moment I override and extend the BlameableListener to add this functionality but it was made final so that wont work for long 😄. Any chance we could have this functionality?

@fwolfsjaeger
Copy link
Contributor Author

I'll try to find the time to add tests for the changes this week.

@fwolfsjaeger
Copy link
Contributor Author

Alright, all done:

  • I've rebased the branch,
  • added the missing logic in the SoftDeleteable listener,
  • fixed getting the property name in the annotation drivers
  • and added Unit tests for all 4 annotations.

Let me know if you need anything else ;)

@fwolfsjaeger
Copy link
Contributor Author

Any chance that this PR is getting merged?

Even though there is no BC breaking change right now: I could refactor the changes to auto-detect a setter method by simply checking for setFieldName(). That however could break BC as there's no way to stick to the original way of setting the property directly.

Copy link
Contributor

@mbabker mbabker left a comment

Choose a reason for hiding this comment

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

Needs rebasing but in general looks good to me.

@fwolfsjaeger
Copy link
Contributor Author

I'll rebase the latest changes right away. Many thanks for taking the time to review the changes!

This change is applied in Blameable, IpTraceable, SoftDeleteable & Timestampable annotations. The new attribute "setterMethod" can be passed to specify the setter method to be used for a field. If no setter method is specified, the property value would be set directly as before.
Fixed using setterMethod for SoftDeleteable annotations
Added Unit tests for the setter methods
Amended Code Style
@franmomu franmomu force-pushed the feature/use-setter-methods branch from bd614cc to 4f2c498 Compare June 9, 2024 10:29
@franmomu
Copy link
Collaborator

franmomu commented Jun 9, 2024

Thanks for keeping working into this @fwolfsjaeger, in general I see the code fine, but I would like to avoid empty calls and we were also trying to not working with array references, I don't know how hard would be to make that change.

Comment on lines +71 to +73
if (isset($mappingProperty['setterMethod'])) {
$this->setSetterMethod($field, $mappingProperty['setterMethod'], $config);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since YAML drivers are deprecated, I'd rather don't add more code in the drivers

Comment on lines +163 to +178

/**
* Set the setter method for the given field.
*/
protected function setSetterMethod(string $field, ?string $method, array &$config): void
{
if (empty($method)) {
return;
}

if (!isset($config['setterMethod'])) {
$config['setterMethod'] = [];
}

$config['setterMethod'][$field] = $method;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code doesn't seem to belong to File, if we don't use it in Yaml drivers, I'd move it to Xml

@fwolfsjaeger
Copy link
Contributor Author

Sorry, but I'm no longer using DoctrineExtensions. I've created this and another PR about a year ago. That and the incompatibility with DBAL 4 forced me to just add my own listeners for the 3 attributes I was using.

I'll look into the recent deprecations and requested changes, but it might take some time.

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.

6 participants