Closed loretoparisi closed 4 years ago
[UPDATE]
I have successfully renamed the SendGrid
class and namespace to SendGridSDK
, thus the "external" (i.e. directly installed from Wordpress) plugin works fine. The problem is the "internal" (ie. the one used as a library in my plugin) has an error, related to Composer
I assume. Let's consider that I have already installed of Composer
requirements locally, so my directory looks like:
.
├── lib
│ ├── SendGridSDK.php
│ └── helpers
│ └── mail
│ ├── Mail.php
│ └── README.md
├── sendgrid-php.php
└── vendor
├── autoload.php
├── bin
├── composer
│ ├── ClassLoader.php
│ ├── LICENSE
│ ├── autoload_classmap.php
│ ├── autoload_files.php
│ ├── autoload_namespaces.php
│ ├── autoload_psr4.php
│ ├── autoload_real.php
│ ├── autoload_static.php
│ └── installed.json
└── sendgrid
└── php-http-client
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── examples
│ └── example.php
└── lib
├── Client.php
└── Response.php
The error is Fatal error: Uncaught Error: Class 'SendGridSDK\Client' not found in
thrown in /home/loretoparisi/staging/2/wp-content/plugins/loretoparisi_admin/sendgrid-php/lib/SendGridSDK.php on line 53, where the Client
is called:
$this->client = new \SendGridSDK\Client($host, $headers, '/v3', null, $curlOptions);
I have also refactored the class Client
and Response
to match the right namespace:
namespace SendGridSDK;
/**
* Quickly and easily access any REST or REST-like API.
*/
class Client
{
...
Also for the Composer
auto loader classes:
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'SendGridSDK\\' => array($vendorDir . '/sendgrid/php-http-client/lib'),
);
So, since I have all files locally, why The ClassLoader
cannot import the class SendGridSDK\Client
?
Recommend upgrading to a later, supported version of this library which may resolve the issue you're seeing. Latest is 7.8.3
.
@childish-sambino thank you.
By the way, in the meantime I have fixed the old one just removing Composer
and including libraries manually:
.
├── Wrapper
│ ├── Php.php
│ ├── Wordpress.php
│ └── WordpressCli.php
├── sendgrid-php
│ ├── lib
│ │ ├── Client.php
│ │ ├── Mail.php
│ │ ├── Response.php
│ │ └── SendGridSDK.php
│ └── sendgrid-php.php
├── test.php
where sendgrid-php.php
looks like:
<?php
require __DIR__ ."/lib/Client.php";
require __DIR__ ."/lib/Response.php";
require __DIR__ ."/lib/Mail.php";
require __DIR__ ."/lib/SendGridSDK.php";
?>
Issue Summary
When included
sendgrid-php
plugin within another plugin as a library, aCannot declare class
error comes out.Steps to Reproduce
sendgrid-php
pluginCode Snippet
To avoid the error, I'm currently using this check:
Exception/Log
Technical details:
I have posted more details on SF here.