Open bartboy011 opened 4 years ago
Note - in my error logs, a class not found fatal is not raised as my code is running in a WordPress environment where other plugins have loaded their own versions of the SendGrid client.
For anyone who comes across this, adding this code block to your scoper.inc.php should correct the issue:
'patchers' => [
function (string $filePath, string $prefix, string $content): string {
if ($filePath === '/path/to/my/project/vendor/sendgrid/sendgrid/lib/mail/Mail.php') {
$replacement = str_replace(
'\\\\SendGrid\\\\Mail\\\\',
$prefix . '\\\\SendGrid\\\\Mail\\\\',
$content
);
if ($replacement !== null) {
return $replacement;
}
}
return $content;
},
],
This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.
Issue Summary
PHP Scoper is a tool that adds a unique prefix to all namespaces in the vendor directory of a project in order to prevent namespace collisions - for example, if I'm developing a wordpress plugin and want to avoid namespace collisions or version collisions with the dependencies of other wordpress plugins, I'll use Scoper.
In
lib/mail/Mail.php
there is this line: https://github.com/sendgrid/sendgrid-php/blob/7bdf97e961f0eb529a0a027ae7d3b8a204faa905/lib/mail/Mail.php#L188. PHP Scoper is not able to detect dynamic class names like this, and so the prefix is not applied.If using Scoper, the logic in that block fails and a fatal exception is raised. This effectively looks like:
There is a workaround for this issue: https://github.com/humbug/php-scoper#patchers. This workaround is less than ideal as it's highly manual.
Steps to Reproduce
Code Snippet
Exception/Log
Technical details: