In my custom extension I am trying to integrate an external PHP lib. I get the following error message in TYPO3 v12.4:
Expected to find class "Brevo\Client\Api\AccountApi" in file "/var/www/html/packages/my_extension/Resources/Private/PHP/brevo-php/lib/Api/AccountApi.php" while importing services from resource "../Resources/Private/PHP/brevo-php/lib/*", but it was not found! Check the namespace prefix used with the resource.
The class name and the path are correct. There is no reason for not finding the class.
My Services.yaml:
services:
_defaults:
autowire: true
autoconfigure: true
public: true
MyVendor\MyExtension\:
resource: '../Classes/*'
exclude:
- '../Classes/Domain/Model/*'
Brevo\Client\:
resource: '../Resources/Private/PHP/brevo-php/lib/*'
My `composer.json autoload section:
...
"autoload": {
"psr-4": {
"MyVendor\\MyExtension\\": "Classes"
},
"classmap": [
"Resources/Private/PHP/brevo-php/lib"
]
},
...
The file Api/AccountApi.php looks basically like this:
<?php
namespace Brevo\Client\Api;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Brevo\Client\ApiException;
use Brevo\Client\Configuration;
use Brevo\Client\HeaderSelector;
use Brevo\Client\ObjectSerializer;
class AccountApi {
....
}
In TYPO3 v11.5 it was no problem to include this lib, the namespace Brevo\Client\ was known.
Is it a good idea to place the external class in the
Resourcesdirectory? Or is it better to put in theClassesdirectory? Could this be the reason for the missing autoloading?I am not quite sure whether the external lib is PSR-4 compatible. That is why I declared it with
classmap. Things don't change if I add it withpsr-4.