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

Allow ConnectionLocator to be used with PDO Persistent Connections #12

Merged
merged 1 commit into from
Dec 30, 2020

Conversation

dbraff
Copy link
Contributor

@dbraff dbraff commented Jan 30, 2020

This PR modifies the LoggedStatement class to be a proxy wrapping the PDOStatement class, which is constructed by the Connection class injecting the PDOStatement into it when logging is enabled.

This allows persistent connections to be used along with the logging functionality and the ConnectionLocator.

In order to maintain the existing type hints for methods returning a PDOStatement instance, this was done by overriding each of the method of the parent class as opposed to using the magic __call method.

A test case was added to cover the case of a ConnectionLocator with a persistent connection, and an existing test case, which verified that PDO natively returned LoggedStatement instances, was removed as it would no longer be applicable.

@pmjones
Copy link
Contributor

pmjones commented Jan 30, 2020

Nice. Give me a bit to look this over. Thanks!

@dbraff
Copy link
Contributor Author

dbraff commented Jan 30, 2020

Thank you!

@dbraff
Copy link
Contributor Author

dbraff commented Mar 12, 2020

Hi @pmjones, was wondering if you had any time to look at this further. If you have concerns or think a different approach would be better, please let me know.

…tion, removed test case which would no longer be applicable, and modified the LoggedStatement class to be a proxy wrapping the PDOStatement class.
@dbraff
Copy link
Contributor Author

dbraff commented Jun 25, 2020

Hi @pmjones, I came back to look over this PR and realized what a mistake I had made in the changes to the LoggedStatement class. I've corrected this so that the overriding methods are forwarding the returns of the PDOStatement instance. Apologies for the oversight and if you have another chance to look this over please let me know if you have any concerns or feedback.

@dbraff
Copy link
Contributor Author

dbraff commented Dec 29, 2020

Hi @pmjones, it's been a while since I last commented here on this. Could you please give an update on your thoughts for this PR and the issue it attempts to resolve? Any feedback would be greatly appreciated.

As an aside, it does appear that doctrine/dbal previously had a similar lack of support. That was resolved recently with this PR.
doctrine/dbal#3515

@pmjones
Copy link
Contributor

pmjones commented Dec 30, 2020

Hey @dbraff looking at it today -- thanks for your patience!

@pmjones
Copy link
Contributor

pmjones commented Dec 30, 2020

@dbraff Would it be fair to say that the bulk of the change is to explicitly add PDOStatement methods to LoggedStatement, so that the internal $statement methods called directly, instead of making parent::*() calls?

@dbraff
Copy link
Contributor Author

dbraff commented Dec 30, 2020

Hi @pmjones, thanks for getting back to me on this!

@dbraff Would it be fair to say that the bulk of the change is to explicitly add PDOStatement methods to LoggedStatement, so that the internal $statement methods called directly, instead of making parent::*() calls?

Yes, I would agree that's fair to say. I wish there was a less repetitive way to wrap the PDOStatement class but I couldn't think of a better way to do that without causing a backwards compatibility issue with users of this package already potentially relying on PDOStatement type hints. If you have any suggestions for how to approach this differently, I'd love to hear them.

@pmjones
Copy link
Contributor

pmjones commented Dec 30, 2020

I wish there was a less repetitive way to wrap

I don't think there is; one's first thought is to use __call()but it won't get invoked, since the methods exist in the parent class.

@dbraff
Copy link
Contributor Author

dbraff commented Dec 30, 2020

I wish there was a less repetitive way to wrap

I don't think there is; one's first thought is to use __call()but it won't get invoked, since the methods exist in the parent class.

Yeah, that was my first thought as well.

@pmjones
Copy link
Contributor

pmjones commented Dec 30, 2020

All right, I think this looks good! Couple of typos but nothing major. The LoggedStatement test coverage has dropped to 50%, though, because of the newly-added methods. Will merge, then add tests, then release.

Thanks for your work, and (again) for your patience!

@pmjones pmjones merged commit 3603c98 into atlasphp:1.x Dec 30, 2020
@dbraff
Copy link
Contributor Author

dbraff commented Dec 30, 2020

All right, I think this looks good! Couple of typos but nothing major. The LoggedStatement test coverage has dropped to 50%, though, because of the newly-added methods. Will merge, then add tests, then release.

Thanks for your work, and (again) for your patience!

No problem at all! Thank you taking the time to look at it, looking forward to bringing this library up again at my organization!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants