My application on AWS EC2 stores image-files on AWS S3. I am using the following AWS code snippet to create a Guzzle client to the S3 API:
use Aws\S3\S3Client; // Namespace alias.
...
$s3_gClient = S3Client::factory(array(
...
));
This works fine - but is repeated at several places in the application. Now, I'd like to use a method to be called from all these places instead. I tried this:
$s3ClientNamespaceString = "S3Client";
$sg->prepare_aws_s3_guzzle_client($s3ClientNamespaceString);
with the method defined as:
public function prepare_aws_s3_guzzle_client($s3ClientNamespaceString) {
$s3_gClient = $s3ClientNamespaceString::factory(array(
...
));
}
This is not working - I get a PHP error:
Fatal error: Class 'S3Client' not found
Is there any way to achieve what I am trying - i.e. to use a namespace alias within a method ?