Last active
December 11, 2019 18:57
-
-
Save ivastly/ac02b716ad521694ee3e21c55bf03ae7 to your computer and use it in GitHub Desktop.
hello-world aspect
This file contains hidden or 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 | |
namespace Ivastly\GoAopHelloWorld\Aop; | |
use Go\Aop\Aspect; | |
use Go\Aop\Intercept\MethodInvocation; | |
use Go\Lang\Annotation\Before; | |
class BankingAspect implements Aspect | |
{ | |
/** | |
* Runs before every money-related (named *Money) method of Bank class. | |
* | |
* @Before("execution(public Ivastly\GoAopHelloWorld\BankingSystem\Bank->*Money(*))") | |
*/ | |
public function beforeMethodExecution(MethodInvocation $invocation): void | |
{ | |
echo "\n calling {$invocation->getMethod()->getName()}", | |
' with arguments: ', | |
json_encode($invocation->getArguments()), | |
"\n"; | |
if ($invocation->getMethod()->getName() === 'sendMoney') | |
{ | |
$arguments = $invocation->getArguments(); | |
if ($arguments[1] === 'Developer') | |
{ | |
$arguments[0] *= 1.1; // some people always get slightly more money, banks should not notice 🤑 | |
$invocation->setArguments($arguments); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment