academe / SagePay-Integration

HTTP Messages for the Sage Pay REST (Pi) gateway.
GNU General Public License v3.0
9 stars 5 forks source link

Remove built-in autoloader #24

Closed judgej closed 8 years ago

judgej commented 8 years ago

This was added when considering running this package in a non-composer environment. Now it has a dependency on shrikeh/teapot, which in turn requires squizlabs/php_codesniffer, use without composer is going to be a lot more difficult.

We should either remove the built-in autoloader, or remove composer library dependencies. Or maybe extend the built-in autoloader to autoload Teapot if it is installed alongside this package? It does not look like squizlabs/php_codesniffer is needed by any of the Teapot interfaces that we use.

judgej commented 8 years ago

Something like this works in the autoloader in my dev env:

spl_autoload_register(function($class) {
    if (stripos($class, 'Teapot\\') === 0) {
        include(
            __DIR__ . '/../vendor/shrikeh/teapot/src/Teapot'
            . str_replace('\\', '/', substr($class, strlen('Teapot')))
            . '.php'
        );
    }
});

Note that this does not autoload Teapot's dependencies.

However, that makes assumptions about where the vendor directory is, and that there even is a vendor directory, and how that relates to location of this package. Too many assumptions.

We'll leave the autoloader for this package in, but the Teapot package will need to be set to autoload externally; we don't car how, so long as it is available.