/** * @MethodInterceptor(class-expression=.*Service.*,expression=.*) */ public function manageTransaction(MethodInvocation $methodInvocation) { $method = $methodInvocation->getMethod(); $class = $methodInvocation->getClass(); if (strncmp($method, '_', 1) === 0 || strncmp($method, 'set', 3) === 0) { return $methodInvocation->proceed(); } $this->logger->debug("Serving for: {$class}::{$method}"); self::$count++; try { if (self::$count === 1) { $this->logger->debug('Beginning transaction'); $this->entityManager->beginTransaction(); } $result = $methodInvocation->proceed(); if (self::$count === 1) { $this->logger->debug('Commiting transaction'); $this->entityManager->flush(); $this->entityManager->commit(); } self::$count--; return $result; } catch (\Exception $exception) { if (self::$count === 1) { $this->logger->error('Exception: ' . $exception->getMessage() . ' occurred, rollbacking transaction'); $this->entityManager->rollback(); } self::$count--; throw $exception; } }
public function invoke(MethodInvocation $invocation) { echo "Before\n"; $ret = $invocation->proceed(); echo "After\n"; return $ret; }
/** * @MethodInterceptor(class-expression=.*AbstractService.*,expression=.*) */ public function profileDomainServices(MethodInvocation $invocation) { $time = microtime(true); $originalInvocation = $invocation->getOriginalInvocation(); $ret = $invocation->proceed(); $total = microtime(true) - $time; $this->logger->debug("Execution of " . $originalInvocation->getClass() . "::" . $originalInvocation->getMethod() . " took: " . sprintf('%.5f', $total)); return $ret; }
public function invoke(MethodInvocation $invocation) { return $invocation->proceed(); }
public function invoke(MethodInvocation $invocation) { echo "With exception: " . $invocation->getException() . "\n"; echo "After with exception\n"; $invocation->proceed(); }
public function invoke(MethodInvocation $invocation) { $args = $invocation->getArguments(); return $args[0]; }
public function invoke(MethodInvocation $invocation) { echo "Before2: " . print_r($invocation->getOriginalInvocation(), true) . "\n"; $invocation->proceed(array('b', 'c', 'd')); echo "After\n"; }
/** * The proxy will call this method when an aspected method is called. * * @param MethodInvocation $invocation Method invocation "descriptor". * * @return void */ public function invoke(MethodInvocation $invocation) { $interceptors = $this->getInterceptors($invocation->getMethod()); if ($interceptors != false) { return $this->_callInterceptors($invocation, $interceptors); } return $invocation->proceed(); }
/** * @MethodInterceptor(class-expression=ClassSimpleAOPAnnotation3,expression=toIgnore) */ public function trapPrivate(MethodInvocation $invocation) { return $invocation->proceed(); }
public function invoke(MethodInvocation $invocation) { try { echo "Before3: " . print_r($invocation->getOriginalInvocation(), true) . "\n"; $invocation->proceed(array('b', 'c', 'd')); echo "After3\n"; } catch (Exception $e) { echo "Move along, nothing happened here.. \n"; } }
/** * @ExceptionInterceptor(class-expression=ClassSimpleAOPAnnotation?,expression=^.+) */ public function exceptionInterceptor(MethodInvocation $invocation) { $args = $invocation->getArguments(); return $args[0]; }