Help with "Accessing the API with PHP" tutorial

Hi,

I am trying to get an example built using the tutorial at https://api.foxycart.com/docs/tutorials/php. There is a section titled "Set up our script" and it contains the follwong code:

<?php
require __DIR__ . '/vendor/autoload.php';
session_start();

use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;
use Foxy\FoxyClient\FoxyClient;

$guzzle_config = array(
'defaults' => array(
'debug' => false,
'exceptions' => false
)
);
$guzzle = new Client($guzzle_config);
CacheSubscriber::attach($guzzle);
When I run this, I get the following message:

E_ERRORwith message "Uncaught Error: Class 'GuzzleHttpXSubscriberXCacheXCacheSubscriber' not found in my_foxyexample.php
Did my Composer install possibley miss something? I used:

php composer.phar require foxycart/foxyclient:~2.0
Thanks,
Nick
Tagged:
Comments
  • Tried

    find . -name CacheSubscriber.php -print
    in my vendor folder, but found nothing.
  • I tried also installing

    php composer.phar require guzzlehttp/guzzle
  • fc_adamfc_adam FoxyCart Team
    @nickweavers,

    Sorry for the delay in getting back to you here.

    I believe the issue you're running into here is that our example code isn't compatible with the 2.0.X tags for the FoxyClient code. That uses an newer version of Guzzle (version 6) and that includes a different module for caching than the 1.0.X tags did with Guzzle 5 and CacheSubscriber.

    If you switch to requiring ~1.0, that should get the example code working. Alternatively, if you wanted to go with Guzzle v6, you can see information about the caching middleware here: https://github.com/Kevinrob/guzzle-cache-middleware
Sign In or Register to comment.