Welcome Guest, Not a member yet? Register   Sign In
Class not found
#1

I am still trying to install the sendpulse API. I finally got Composer to install it correctly and it created a file called /vendor/sendpulse/rest-api/ApiClient.php

When I try to initialize it with this call:
$SPApiClient = new ApiClient($_SESSION['sendpulse_API_USER_ID'], $_SESSION['sendpulse_SECRET'], new FileStorage());

I get this exception: Class 'Sendpulse\RestApi\ApiClient' not found.

Now it seems clear to me (but not to the vendor) that /vendor/sendpulse/rest-api/ApiClient and Sendpulse\RestApi\ApiClient are in two different directories.

 I tried
$SPApiClient new vendor/sendpulse/rest-api/ApiClient($_SESSION['sendpulse_API_USER_ID'], $_SESSION['sendpulse_SECRET'], new FileStorage());

 but I get this error: Class 'vendor' not found. So there must be someplace else where the path to the class is defined?
proof that an old dog can learn new tricks
Reply
#2

Is Composer autoloading included in your code?
Reply
#3

Yes. I have require 'vendor/autoload.php'; at the top of the module. I just noticed that these two lines also appear in the module:
use Sendpulse\RestApi\ApiClient;
use Sendpulse\RestApi\Storage\FileStorage;

As I said above the actual php files were installed by composer at
/opt/docker-substantiator2/vendor/sendpulse/rest-api/src/ApiClient.php
/opt/docker-substantiator2/vendor/sendpulse/rest-api/src/Storage/FileStorage.php

Do I need to even have a use statement?
proof that an old dog can learn new tricks
Reply
#4

(This post was last modified: 05-19-2021, 06:37 AM by iRedds.)

Yes, it is needed.
There are two options for calling a class in a namespace.

1
use Sendpulse\RestApi\ApiClient;
new ApiClient();

2
new \Sendpulse\RestApi\ApiClient();

The result will be the same.

Error "Class 'Sendpulse\RestApi\ApiClient' not found." means that the script cannot determine the location of the class.

There are three possible reasons:
1. The composer is not included
2. The library is not installed
3. The library is not installed correctly / the composer has not indexed the library in the boot files.

In the third case, you can try reindexing 'composer dump-autoload' or reinstalling the library.

If the installation and/or indexing was successful, then an entry about the path to the library should appear in the vendor/composer/autoload_psr4.php file.
Reply
#5

Thanks. I am using version 2 above. I still get Class 'ApiClient' not found.
I then checked psr4
return array(
'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Polyfill\\Intl\\Idn\\' => array($vendorDir . '/symfony/polyfill-intl-idn'),
'Sendpulse\\RestApi\\' => array($vendorDir . '/sendpulse/rest-api/src'), <<< it is right here
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
'Http\\Promise\\' => array($vendorDir . '/php-http/promise/src'),
'Http\\Client\\' => array($vendorDir . '/php-http/httplug/src'),
'Http\\Adapter\\Guzzle6\\' => array($vendorDir . '/php-http/guzzle6-adapter/src'),
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
);

I think the install was OK. I have done it at least 3 times. How can I check if the library is installed? Should I try reindexing or am I wasting my time?
proof that an old dog can learn new tricks
Reply
#6

The library you need is listed, so the installation is successful and no reindexing is needed.

Everything seems to be fine.
I do not even know now what could be the reason.

Can you create an instance of the class of any other library installed through the composer?
Reply
#7

Are you using CodeIgniter 3? If so, did you check your
Code:
application/config/config.php
file if the path to the Composer autoload file is correctly set there? In mine, I have set the autoload like this:

PHP Code:
$config['composer_autoload'] = FCPATH 'vendor/autoload.php'
Reply
#8

(This post was last modified: 05-19-2021, 12:56 PM by richb201.)

This is what I have:
$config['composer_autoload'] = FCPATH . 'vendor/autoload.php';    //for ubuntu

same!

I sure hope the vendor is going to figure this out.
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB