Composer loading class without namespace

The Amazon MWS PHP client library is just a zip file without any namespace, is there any way to use this library with a Laravel application or with any application that uses the composer to manage dependencies.

+4
source share
1 answer

Of course, just create your own library directory in your Laravel application. Usually I keep mine only inside the directory appand name it Libraries. Dump source files inside a folder, for example AmazonMWS.

.config.inc.phpcomes with an autoloader, but it will not be used. Instead, you could just open your own composer.jsonin your Laravel project and tell him to automatically download your new configuration-oriented library directory. Example:

"autoload-dev": {
    "classmap": [
        "app/Libraries/AmazonMWS/Client.php"
    ]
}

Make sure it config.inc.phpis accessible with root AmazonMWS.

Then run composer dump-autoloadto restore autoloaders. If done correctly, you should be able to instantiate any of the MWS classes without a namespace.

In your controller, enable the following use:

use \MarketplaceWebServiceProducts_Client;

Now you can call the service as expected:

$config = [...];

$service = new MarketplaceWebServiceProducts_Client(
    AWS_ACCESS_KEY_ID,
    AWS_SECRET_ACCESS_KEY,
    APPLICATION_NAME,
    APPLICATION_VERSION,
    $config);

Or simply omit use \MarketplaceWebServiceProducts_Client;and instantiate directly using the namespace prefix of your choice.

+1
source

Source: https://habr.com/ru/post/1650177/


All Articles