Skip to content

Instantly share code, notes, and snippets.

@antecedent
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antecedent/9705836 to your computer and use it in GitHub Desktop.
Save antecedent/9705836 to your computer and use it in GitHub Desktop.
"Wrapping" a method using Patchwork 1.2
<?php
# Ad-hoc code for a hypothetical method named Filesystem::contains.
$replacement = function($path) use (&$replacement, &$handle) {
# Run code before the original function
echo 'Before', PHP_EOL;
# Make this replacement function disable itself
Patchwork\undo($handle);
# Call the original function
$result = Filesystem::contains($path);
# Re-enable this replacement function
$handle = Patchwork\replace('Filesystem::contains', $replacement);
# Run code after the original function
echo 'After', PHP_EOL;
};
$handle = Patchwork\replace('Filesystem::contains', $replacement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment