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