1

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.

  1. Is it a good idea to place the external class in the Resources directory? Or is it better to put in the Classes directory? Could this be the reason for the missing autoloading?

  2. 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 with psr-4.

1 Answer 1

1

The Brevo PHP lib is now available via composer require getbrevo/brevo-php. This simplifies things and solves my problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.