Question

I've downloaded the createsend-php library in my Symfony2 application using:

composer require  campaignmonitor/createsend-php

It's been downloaded successfuly but when I try to use it..

use CS_REST_Lists;
...
public function testNewsletterAction() {

        //... retrieving the keys

        $api = new CS_REST_Lists($listId, $apiKey);
        var_dump($api->get());
        exit;

    }

I get the following error:

ClassNotFoundException: Attempted to load class "CS_REST_Lists" from the global namespace in ...

In the use statement NetBeans suggested the class name btw. Why is it not working and how can I fix it?

No correct solution

OTHER TIPS

According to the libs documentation: https://github.com/campaignmonitor/createsend-php you need to require the file yourself

require_once 'csrest_lists.php'

instead of

use \CS_REST_Lists;

Although it does look like their composer.json is setup to autoload them so that is strange that the use statement isnt working.

This is not a solution but it worked for me...

You don't need to add manually the classmap. If you look inside vendor/composer/autoload_classmap.php you can see composer added:

'CS_REST_CLASSES' => $vendorDir .'/campaignmonitor/createsend-php/csrest_administrators.php',

Then I tried two things:

  • Instantiate my class somewhere:

$cm = new \CS_REST_Lists;

  • Inject the class in my services.yml:

my.service: class: My\Namespace\MyService arguments: [@campaign_monitor]

campaign_monitor:
    class: CS_REST_Lists
    arguments: ['', %campaignmonitor%]

The weird part is instantiating worked all the time but injecting triggered:

PHP Fatal error: Class 'CS_REST_List' not found in /my/code/path/var/cache/dev/appDevDebugProjectContainer.php on line 1779

So I tried to inject a different classmap in my services.yml (i.g File_Iterator from phpunit) I assumed that a library like phpunit wouldn't be an issue and it worked. Then I replaced in services.yml File_Iterator with CS_REST_List and magically it worked...

So... not sure what's going wrong but I think the problem comes from symfony's container not composer. I used symfony 2.5.1

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