0

Instead of using Composer for AWS SES I installed the files from a zip file and included them as per the documentation: require '/path/to/aws-autoloader.php';

The problem is all the code examples assume you're using Composer, so I'm trying to find the alternative to things like:

use Aws\Ses\SesClient; 
use Aws\Exception\AwsException;

EDIT:

The full code looks like:

use Aws\Ses\SesClient; 
use Aws\Exception\AwsException;

//Create a SESClient
$SesClient = new SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-1'
]);

When I remove the "use" lines I get the error: Class 'SesClient' not found

I guess I'm missing what "use" does and how to replicate that outside of Composer. The autoloader file has a $mapping array:

$mapping = array(
    'JmesPath\FnDispatcher' => __DIR__ . '/JmesPath/FnDispatcher.php',
... etc)

And then below that array:

spl_autoload_register(function ($class) use ($mapping) {
    if (isset($mapping[$class])) {
        require $mapping[$class];
    }
}, true);
  • Since you don't use composer and you have autoloaded AWS autoloader, where is the issue? – nice_dev May 14 '21 at 15:34
  • 2
    `use` statements and autoloading are not related. An autoloader is triggered when a class is instanciated, statically called, etc. You can add use statements of unknown classes. Your question is unclear, especially if you already have an autoloading file. Is there a reason you don't use Composer ? – AymDev May 14 '21 at 15:37
  • The full code looks like: use Aws\Ses\SesClient; use Aws\Exception\AwsException; //Create a SESClient $SesClient = new SesClient([ 'profile' => 'default','version' => '2010-12-01', 'region' => 'us-east-1' ]); – BostonPHPGuy May 14 '21 at 15:47
  • A class import is nothing more than a convenience so you don't have to type out the fully qualified class name with every use of the class. If you, for some reason, are offended by the presence of `use` statements, you must do this every time: `try {$SesClient = new \Aws\Ses\SesClient(...);} catch (\Aws\Exception\AwsException $e){...}` – miken32 May 14 '21 at 16:16

0 Answers0