PHP code example of pinkeen / api-debug-bundle

1. Go to this page and download the library: Download pinkeen/api-debug-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pinkeen / api-debug-bundle example snippets


// src/AppBundle/Service/FooService.php
// ...

use Pinkeen\ApiDebugBundle\Bridge\Guzzle\Middleware\DataCollectorMiddleware;

class FooService
{
    private $dataCollectorMiddleware;

    public function __construct(DataCollectorMiddleware $dataCollectorMiddleware)
    {
        $this->dataCollectorMiddleware = $dataCollectorMiddleware;
    }

    // ...
}

    use Pinkeen\ApiDebugBundle\ApiEvents;
    use Pinkeen\ApiDebugBundle\Event\ApiCallEvent;
    
    /* ... */
    /** @var $eventDispatcher \Symfony\Component\EventDispatcher\EventDispatcher */
    $eventDispatcher->dispatch(
        ApiEvents::API_CALL, 
        new ApiCallEvent(
            new YourApiCallData(/* your params */)
        )
    );

    /** @var $guzzleClientFactory \Pinkeen\ApiDebugBundle\Bridge\Guzzle\Service\GuzzleClientFactory */
    $guzzleClientFactory->create([
        /* Guzzle client config (optional).
         * It is passed directly to GuzzleHttp\Client constructor. */
    ]);

    $handler = new GuzzleHttp\HandlerStack(new GuzzleHttp\Handler\CurlHandler());
    /** @var $dataCollectorMiddleware \Pinkeen\ApiDebugBundle\Bridge\Guzzle\Middleware\DataCollectorMiddleware */
    $dataCollectorMiddlewareHandler = $dataCollectorMiddleware->getHandler();
    $handler->push($dataCollectorMiddlewareHandler);
    $client = new GuzzleHttp\Client(['handler' => $handler]);

    /** @var $ringPHPHandlerFactory \Pinkeen\ApiDebugBundle\Bridge\RingPHP\Service\RingPHPHandlerFactory */
    $handler = $ringPHPHandlerFactory->create(new CurlHandler());

    /** @var $dataCollectorMiddleware \Pinkeen\ApiDebugBundle\Bridge\RingPHP\Middleware\DataCollectorMiddleware */
    $ringPhpHandler = $dataCollectorMiddleware->createHandler(new GuzzleHttp\Ring\Client\CurlHandler(), 'apiname');