Odango
, (*1)
Odango is a function compositor inspired by Aspect Oriented Programming (AOP)., (*2)
To separate concerns is better practice even if you don't know AOP, for example
caching, logging, transaction, security filter, event dispatching or such as.
Cross cutting concerns should be separated from your business logic., (*3)
This is not an AOP weaving framework. I prefer Ray.Aop instead if you want some
full featured AOP like a Google Guice or such as., (*4)
Example
$withLoggedTransaction = AdviceComposite::of(
function ($invocation) use ($logger) {
$logger->info('Starting transaction.');
$result = $invocation->proceed();
$logger->info('Transaction comitted.');
return $result;
}
)->with(
function ($invocation) use ($db) {
$db->beginTransaction();
try {
$result = $invocation->proceed();
$db->commit();
return $result;
} catch (\Exception $ex) {
$dbh->rollBack();
throw $ex;
}
}
);
$storeDataInvocation = [$this, 'storeData']; // Some callable
$storeDataInvocation = $withLoggedTransaction->bind($storeDataInvocation);
$storeDataInvocation($data);
Odango supports Ray.Aop's MethodInterceptor as composition target.
So, existing AOP assets may be reusable., (*5)
Remark that AdviceComposite instance is immutable because generated function
references the creation context. Modification breaks it., (*6)
Known issue
Joinpoint::getThis() and Joinpoint::getMethod() are throw a
BadMethodCallException because no object context are bounded., (*7)