PHP Class VCR\Videorecorder

If turned on, a videorecorder will intercept HTTP requests using hooks into libraries like cUrl, SOAP and streamWrappers. Requests and responses will be recorded on a inserted cassette. If a request is already recorded on a cassette the videorecorder will play back its response and not issue a HTTP request. If turned off, HTTP requests won't be intercepted and will hit their original servers.
Author: Adrian Philipp ([email protected])
Datei anzeigen Open project: php-vcr/php-vcr Class Usage Examples

Protected Properties

Property Type Description
$cassette Cassette on which to store requests and responses.
$client Client to use to issue HTTP requests.
$config Config options like which library hooks to use.
$eventDispatcher Symfony\Component\EventDispatcher\EventDispatcherInterface
$factory Factory which can create instances and resolve dependencies.
$isOn Flag if this videorecorder is turned on or not.

Public Methods

Method Description
__construct ( Configuration $config, VCR\Util\HttpClient $client, vcr\VCRFactory $factory ) Creates a videorecorder instance.
__destruct ( ) Turns off this videorecorder when instance is destroyed.
configure ( ) : Configuration Returns the current Configuration for this videorecorder.
eject ( ) : void Eject the currently inserted cassette.
getEventDispatcher ( ) : Symfony\Component\EventDispatcher\EventDispatcherInterface
handleRequest ( Request $request ) : Response Records, sends or plays back a intercepted request.
insertCassette ( string $cassetteName ) : void Inserts a cassette to record responses and requests on.
setEventDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher )
turnOff ( ) : void Turns off this videorecorder.
turnOn ( ) : void Turns on this videorecorder.

Protected Methods

Method Description
disableLibraryHooks ( ) : void Disables all library hooks.
enableLibraryHooks ( ) : void Enables configured library hooks.

Private Methods

Method Description
dispatch ( string $eventName, Symfony\Component\EventDispatcher\Event $event = null ) : Symfony\Component\EventDispatcher\Event Dispatches an event to all registered listeners.

Method Details

__construct() public method

Creates a videorecorder instance.
public __construct ( Configuration $config, VCR\Util\HttpClient $client, vcr\VCRFactory $factory )
$config Configuration Config options like which library hooks to use.
$client VCR\Util\HttpClient Client which is used to issue HTTP requests.
$factory vcr\VCRFactory Factory which can create instances and resolve dependencies.

__destruct() public method

Turns off this videorecorder when instance is destroyed.
public __destruct ( )

configure() public method

Returns the current Configuration for this videorecorder.
public configure ( ) : Configuration
return Configuration Configuration for this videorecorder.

disableLibraryHooks() protected method

Disables all library hooks.
protected disableLibraryHooks ( ) : void
return void

eject() public method

Recording and playing back requests won't be possible after ejecting.
public eject ( ) : void
return void

enableLibraryHooks() protected method

Enables configured library hooks.
protected enableLibraryHooks ( ) : void
return void

getEventDispatcher() public method

public getEventDispatcher ( ) : Symfony\Component\EventDispatcher\EventDispatcherInterface
return Symfony\Component\EventDispatcher\EventDispatcherInterface

handleRequest() public method

If a request was already recorded on a cassette it's response is returned, otherwise the request is issued and it's response recorded (and returned).
public handleRequest ( Request $request ) : Response
$request Request Intercepted request.
return Response Response for the intercepted request.

insertCassette() public method

Inserts a cassette to record responses and requests on.
public insertCassette ( string $cassetteName ) : void
$cassetteName string Name of the cassette (used for the cassette filename).
return void

setEventDispatcher() public method

public setEventDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher )
$dispatcher Symfony\Component\EventDispatcher\EventDispatcherInterface

turnOff() public method

Library hooks will be disabled and cassettes ejected.
public turnOff ( ) : void
return void

turnOn() public method

This enables configured library hooks.
public turnOn ( ) : void
return void

Property Details

$cassette protected_oe property

Cassette on which to store requests and responses.
protected $cassette

$client protected_oe property

Client to use to issue HTTP requests.
protected $client

$config protected_oe property

Config options like which library hooks to use.
protected $config

$eventDispatcher protected_oe property

protected EventDispatcherInterface,Symfony\Component\EventDispatcher $eventDispatcher
return Symfony\Component\EventDispatcher\EventDispatcherInterface

$factory protected_oe property

Factory which can create instances and resolve dependencies.
protected $factory

$isOn protected_oe property

Flag if this videorecorder is turned on or not.
protected $isOn