Question

I'm working on a project which has two components:

1) One is the CodeIgniter framework in which I'll be building all of my custom code.

2) The other is Amazon's PHP SDK libraries for MWS API.

The issue is, both my CodeIgniter code and Amazon's SDK require their own autoload().

Amazon's SDK is also further split up into 3-4 components, each of them has their own autoload function, so if you want to work with Products' SDK, and then Reports SDK in the same session, you would run into the already defined autoload function.

For this reason, I'm thinking about setting up a web services system for communication between my own code and Amazon's SDK files, even though they're on the same server, but at least this way the naming conflicts can be avoided. I.e I'll send a HTTP request to a file outside CodeIgniter, which will deal with Amazon's SDK, and return a response in JSON or XML.

I don't think namespaces are an option since I don't want to go through each file/class in the SDK and add namespace statements.

My question is, are there any performance issues with this method that I should be aware of? And is there any way apart from namespaces that this method could be avoided?

Was it helpful?

Solution

Just copy their autoloader functions to a separate file, rename them, and hook them up with spl_autoload_register thus:

<?php
function loadFrameworkOne($name) {
    // contents of __autoload from framework one.
}
function loadFrameworkTwo($name) {
    // contents of __autoload from framework two.
}
spl_autoload_register('loadFrameworkOne');
spl_autoload_register('loadFrameworkTwo');

This is quick, dirty and off the top of my head ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top