VCR Facade Reference
One-liner:
VCR\VCRis a static facade — every call forwards to a singletonVideorecorderinstance.
On this page: Lifecycle methods · Mode constants · Events · Misc
Lifecycle methods
VCR::turnOn(): void
- Throws: nothing
- Enables all configured library hooks. If VCR is already on, it's turned off first.
\VCR\VCR::turnOn();
VCR::turnOff(bool $restoreStreamWrappers = false): void
- Params:
$restoreStreamWrappers— whentrue, also restores PHP's originalhttp/httpsstream wrappers (only relevant if thestream_wrapperhook was enabled). - Disables all library hooks and ejects the current cassette, if any.
\VCR\VCR::turnOff();
VCR::insertCassette(string $cassetteName): void
- Params:
$cassetteName— file name (no extension needed) relative to the configured cassette path. May contain path separators to nest cassettes in subfolders. - Throws:
\LogicExceptionifmodeisalland the configured storage doesn't implementPurgeableStorage. - Creates the storage + cassette, purges it first if mode is
all, and enables library hooks.
\VCR\VCR::insertCassette('example');
VCR::eject(): void
- Throws:
\LogicExceptionif VCR is off (no cassette can be active). - Detaches the current cassette. Call this before
turnOff().
\VCR\VCR::eject();
VCR::configure(): Configuration
- Returns the shared
Configurationobject for fluent setup. Must be called beforeturnOn()for hook/whitelist/blacklist changes to take effect.
\VCR\VCR::configure()->setMode(\VCR\VCR::MODE_ONCE);
VCR::handleRequest(Request $request): Response
- Throws:
\BadMethodCallExceptionif no cassette is inserted;\LogicExceptionon an unmatched request undernone/once. - The core record/playback dispatcher. Library hooks call this internally — you won't normally call it yourself.
Mode constants
| Constant | Value | See |
|---|---|---|
VCR::MODE_NEW_EPISODES | 'new_episodes' | Record Modes |
VCR::MODE_ONCE | 'once' | Record Modes |
VCR::MODE_NONE | 'none' | Record Modes |
VCR::MODE_ALL | 'all' | Record Modes |
Events
VCR::setEventDispatcher(EventDispatcherInterface $dispatcher): void / VCR::getEventDispatcher(): EventDispatcherInterface
- Get/replace the Symfony event dispatcher VCR uses internally. Register listeners on it to hook into the record/playback lifecycle — see Events.
\VCR\VCR::getEventDispatcher()->addListener(
\VCR\VCREvents::VCR_BEFORE_RECORD,
function (\VCR\Event\BeforeRecordEvent $event) { /* ... */ }
);
Misc
VCR::resetIndex(): void
- Resets the identical-request index table. Called automatically
on
insertCassette(); rarely needed directly.
← Getting Started · Next: Configuration →