Example #1
0
 /**
  * @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;
     }
 }
Example #2
0
 public function invoke(MethodInvocation $invocation)
 {
     echo "Before\n";
     $ret = $invocation->proceed();
     echo "After\n";
     return $ret;
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 public function invoke(MethodInvocation $invocation)
 {
     return $invocation->proceed();
 }
Example #5
0
 public function invoke(MethodInvocation $invocation)
 {
     echo "With exception: " . $invocation->getException() . "\n";
     echo "After with exception\n";
     $invocation->proceed();
 }
Example #6
0
 public function invoke(MethodInvocation $invocation)
 {
     return 'BEFORE' . $invocation->proceed() . 'AFTER';
 }
Example #7
0
 public function invoke(MethodInvocation $invocation)
 {
     echo "Before2: " . print_r($invocation->getOriginalInvocation(), true) . "\n";
     $invocation->proceed(array('b', 'c', 'd'));
     echo "After\n";
 }
Example #8
0
 /**
  * @MethodInterceptor(class-expression=ClassSimpleAOPAnnotation3,expression=toIgnore)
  */
 public function trapPrivate(MethodInvocation $invocation)
 {
     return $invocation->proceed();
 }
Example #9
0
 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";
     }
 }
Example #10
0
 /**
  * @MethodInterceptor(class-expression=ClassSimpleAOPAnnotation?,expression=^.+)
  */
 public function methodInterceptor(MethodInvocation $invocation)
 {
     return 'BEFORE' . $invocation->proceed() . 'AFTER';
 }