Replies: 3 comments
-
|
Hey @ara303, apologies for the delay in responding to this issue. I definitely think adding a namespace is a good idea. Though I had a question for you regarding the I've also been thinking about aligning the PHP SDK with Node.js SDK where you would do: $resend = new Resend(...);Instead of the existing Keen to hear your thoughts. |
Beta Was this translation helpful? Give feedback.
-
|
All good. I'm honestly excited to contribute. For context, when debugging a WordPress plugin I ultimately concluded I had to isolate its Composer dependencies by using a prefixed namespace to avoid conflicts with other plugins requiring the same dependencies but different versions. All the versions tried to coexist in the global namespace, causing fatal errors. Based on the wide variety of solutions to this, Mozart, PHP-Scoper, Strauss, Impostor, etc., it's safe to say it's a common problem. Regarding the
(I was ultimately unable to use Mozart for other reasons involving incompatibility with certain PSR-4 modules.) Easy wayWe could simply amend the readme with a section on dependency isolation, say anything except Strauss doesn't work, and call it a day. No code changes. 😁 Another way
Updated: I was naive and misunderstood how namespace overwriting works. OAI's client is good but I've since realised it actually has the same problem I wanted to work around here. I'm happy to help however I can, if you do want to rewrite to align this closer to the current Node.js SDK - but wouldn't that introduce breaking changes? I sort of wanted to add something that doesn't, if possible. I got stumped and asked Claude. It told me my initial idea to namespace all files and provide a See my fork for my proposed solution. I'd be delighted to turn it into a PR for merging here, if you like what you read. It's like what I first suggested but more thorough. By adding a new file that shims backward compatibility into Composer's To confirm and for peace of mind (primarily my own), I've created and ran some "real world" test cases. The readme explains in depth, but in summary: it just kinda works. 🥳 Please let me know what you think. This is my first time, ever, doing SDK work and I could totally have things wrong. 😅 |
Beta Was this translation helpful? Give feedback.
-
|
Since this has been converted to a discussion, I thought I'd add what I've learned since so it can help others. My solution was to use Strauss, which just works. Personally, I think SDK code should have a prefixed namespace that's deeper than just I proposed a fix which achieves both by prefixing the current global namespace, making it In summary, your current approach is "isolate-able" as long as the right tool is used. Change is not necessarily needed right now. Feel free to close this discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Resend.phpdoesn't have anamespacedeclaration which means Mozart can't automatically isolate dependencies.The solution I went with
To save you the effort of reading this: You should just use Strauss if you're also having this problem.
For context, this library is used in Send Emails With Resend, a WordPress plugin that lets me use Resend for all transactional emails on WordPress sites. Unfortunately, a different WordPress plugin (WPForms) bundles with it an older version of PSR-3 which caused conflicts with the Resend WP plugin. I wanted to fix this by contributing a PR to the Resend plugin that uses namespaced dependencies, but Mozart can't overwrite the namespace if there isn't one to begin with here.
I'm happy to contribute a PR with the fix but thought you might want an issue opened first.
I believe it's just as simple as changing
Resend.phplike so.At the start of the file:
At the end, to ensure existing implementations referencing
\Resend\<name>would still work:Thank you for your time and even more so for this library. Resend's the best transactional email service I've used for TS/JS projects, and I have a big interest in it also being as useable for PHP projects.
Beta Was this translation helpful? Give feedback.
All reactions