Last active
March 22, 2017 05:37
-
-
Save real34/3c84c3e91ae94d23ac00a6a014ba6b63 to your computer and use it in GitHub Desktop.
Magento2 plugin
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 | |
function displayAndConvert($input) { | |
display($input); | |
return strtoupper($input); | |
} | |
// displayAndConvert('foo') -> display('foo') -> return 'FOO' | |
function beforeDisplayAndConvert($input) { | |
return $input . ' - With before'; | |
} | |
// displayAndConvert('foo') -> display('foo - With before') -> return 'FOO - WITH BEFORE' | |
function afterDisplayAndConvert($input) { | |
return $input . ' - With after'; | |
} | |
// si que le after: displayAndConvert('foo') -> display('foo') -> return 'FOO - With after' | |
// si que le before+after: displayAndConvert('foo') -> display('foo - With before') -> return 'FOO - WITH BEFORE - With after' | |
function aroundDisplayAndConvert($subject, $proceed, $input) { | |
display('coucou'); | |
$result = $proceed($input . ' - With around'); | |
display('RES: ' . $result); | |
return $input . ' - Yolo'; | |
} | |
// si que around: | |
// displayAndConvert('foo') | |
// -> display('coucou') | |
// -> display('foo - With around') | |
// -> display('RES: FOO - WITH AROUND') | |
// -> return 'foo - Yolo' | |
// | |
// si around, before et after (avec sort order par défaut, cf http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html): | |
// displayAndConvert('foo') | |
// -> display('coucou') | |
// -> display('foo - With before - With around') | |
// -> display('RES: FOO - WITH BEFORE - WITH AROUND - WITH AFTER') | |
// -> return 'foo - With before - Yolo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment