facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
816 stars 514 forks source link

Static singletons used everywhere #604

Open stevebauman opened 1 month ago

stevebauman commented 1 month ago

I'm working on an application that will facilitate reporting against multiple Meta integrations during the same request, but I quickly discovered that this is will cause issues if you keep one integration in memory and call it later after another one has been initialized. For example:

use FacebookAds\Api;

$one = Api::init(...);

$two = Api::init(...); // Overwrites the first

$one->... // API calls will now actually occur on $two

I thought there would be a way around this by setting the HTTP client inside of the EventRequest manually:

https://github.com/facebook/facebook-php-business-sdk/blob/f3eb099fa895ff6b5ddd98ba993982c2803b22d3/src/FacebookAds/Object/ServerSide/EventRequest.php#L214-L217

But then the singletons are called regardless later on:

https://github.com/facebook/facebook-php-business-sdk/blob/f3eb099fa895ff6b5ddd98ba993982c2803b22d3/src/FacebookAds/Object/ServerSide/EventRequest.php#L309-L313 https://github.com/facebook/facebook-php-business-sdk/blob/f3eb099fa895ff6b5ddd98ba993982c2803b22d3/src/FacebookAds/Object/ServerSide/EventRequest.php#L316-L320

Why is this the case? Why do all these static PHP singletons need to exist? This will surely cause issues for anyone running a PHP application from memory (Swoole, FrankenPHP, RoadRunner, etc.).