PHP code example of allejo / php-vcr-sanitizer

1. Go to this page and download the library: Download allejo/php-vcr-sanitizer 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/ */

    

allejo / php-vcr-sanitizer example snippets


VCR::turnOn();
VCR::insertCassette('...');

VCRCleaner::enable(array(
   'request' => array(
       'ignoreHostname' => false,
       'ignoreQueryFields' => array(
           'apiKey',
       ),
       'ignoreHeaders' => array(
           'X-Api-Key',
       ),
       'bodyScrubbers' => array(
           function($body) {
               return preg_replace('/<password.*?<\/password>/', 'hunter2', $body);
           }
       ),
       'postFieldScrubbers' => array(
           function(array $postFields) {
               $postFields['Secret'] = 'REDACTED';
               return $postFields;
           }
       ),
   ),
   'response' => array(
       'ignoreHeaders' => array('*'),
       'bodyScrubbers' => array(),
   ),
));

VCRCleaner::enable(array(
    'request' => array(
        'bodyScrubbers' => array(
            function ($body) {
                $parameters = array();

                parse_str($body, $parameters);
                unset($parameters['password']);

                return http_build_query($parameters);
            },
        ),
    ),
));

VCRCleaner::enable(array(
    'request' => array(
        'postFieldScrubber' => array(
            function (array $postFields) {
                $postFields['Secret_Key'] = '';
                return $postFields;
            },
        ),
    ),
));