Skip to content

Instantly share code, notes, and snippets.

@real34
Last active March 22, 2017 05:37
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 real34/3c84c3e91ae94d23ac00a6a014ba6b63 to your computer and use it in GitHub Desktop.
Save real34/3c84c3e91ae94d23ac00a6a014ba6b63 to your computer and use it in GitHub Desktop.
Magento2 plugin
<?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