laravel-5packagistexacttarget

How to integrate in Laravel 5 a Package from Packagist?


I'm working with laravel 5 and trying to integrate the following package: exacttarget/fuel-sdk-php

I executed on my project:

composer require exacttarget/fuel-sdk-php

So I had on my vendor dir exacttarget provider.

First thing I've noticed this particular package doesn't use namespaces, so it still calls require directives but not "use \path\namespace" Is it a right approach? I haven't seen many packages yet but among my past experience doesn't look to me the right approach to write a package...

After this I edit condif/app.php to use ET_Client class.

 'providers' => [
 ...
 'ET_Client',
 ...

],

Once I did this, I got an error: looks like Laravel frmwk tries to instantiate the class, that needs some parameters to work, even if I'm not yet using it (istantiating). It this a normal behavior from Laravel?

Am I missing something ?


Solution

  • The providers array is for registering service provider classes. Unless ET_Client extends Laravel’s base ServiceProvider class, it’s not going to work.

    Instead, just add the use statements to your PHP classes as and when you need to use the class:

    <?php
    
    namespace App\Http\Controllers;
    
    use ET_Client;
    
    class SomeController extends Controller
    {
        public function someAction()
        {
            // Instantiate client class
            $client = new ET_Client;
    
            // Now do something with it...
        }
    }