예제 #1
0
 /**
  * @covers ::invoke
  */
 public function testInvoke()
 {
     $complete = SmartCallable::factory(function () {
         $this->completed = true;
     });
     $complete->invoke();
     $this->assertTrue($this->completed);
 }
예제 #2
0
 /**
  * Calls the function
  */
 public function invoke()
 {
     $args = func_get_args();
     $retries = 0;
     $exception = null;
     $return = null;
     /** @noinspection PhpUnusedLocalVariableInspection */
     $sc = SmartCallable::factory("restore_error_handler");
     set_error_handler(function ($type, $message, $file, $line) {
         throw PHPException::factory($message, $type, $file, $line);
     });
     do {
         try {
             $exception = null;
             $return = call_user_func_array($this->callback, $args);
         } catch (Exception $exception) {
             $this->logger->error($exception->getMessage());
         }
         $action = $this->matchesCondition($return, $exception);
         if ("retry" == $action) {
             $retries++;
         }
     } while ("retry" == $action && ($retries < $this->max_retries || -1 === $this->max_retries));
     if ($exception && "return" !== $action) {
         throw $exception;
     }
     if ($this->filter) {
         $return = call_user_func($this->filter, $return);
     }
     return $return;
 }