Last active
August 29, 2015 13:57
-
-
Save antecedent/9705836 to your computer and use it in GitHub Desktop.
"Wrapping" a method using Patchwork 1.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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