コード例 #1
0
 public function testFormatsTimestamps()
 {
     $f = new Formatter('{ts}');
     $request = new Request('GET', '/');
     $result = $f->format($request);
     // Ensure it matches this format: '2014-03-02T00:18:41+00:00';
     $this->assertEquals(1, preg_match('/^[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}/', $result));
 }
コード例 #2
0
 /**
  * @inheritDoc
  */
 public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = [])
 {
     if (in_array($request->getPath(), $this->paths)) {
         $customData = array_merge(['url' => $this->mask((string) $request->getUrl()), 'resource' => $this->mask($request->getResource()), 'request' => $this->mask((string) $request), 'response' => $this->mask((string) $response), 'res_body' => $response ? $this->mask((string) $response) : 'NULL', 'req_body' => $this->mask((string) $request->getBody())], $customData);
     }
     return parent::format($request, $response, $error, $customData);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  * Replaces the ewayCardNumber field in the body with "X"s.
  */
 public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = array())
 {
     $body = $request->getBody()->__toString();
     $newBody = preg_replace_callback('/<ewayCardNumber>(.*?)<\\/ewayCardNumber>/', function ($matches) {
         $privateNumber = str_repeat('X', strlen($matches[1]) - 4) . substr($matches[1], -4);
         return '<ewayCardNumber modified>' . $privateNumber . '</ewayCardNumber>';
     }, $body);
     $newRequest = clone $request;
     $newRequest->setBody(Stream::factory($newBody));
     $request->setBody(Stream::factory($body));
     return parent::format($newRequest, $response, $error, $customData);
 }
コード例 #4
0
 /**
  * Creates a delay function that logs each retry before proxying to a
  * wrapped delay function.
  *
  * @param callable         $delayFn   Delay function to proxy to
  * @param LoggerInterface  $logger    Logger used to log messages
  * @param string|Formatter $formatter Message formatter to format messages
  *
  * @return callable
  */
 public static function createLoggingDelay($delayFn, LoggerInterface $logger, $formatter = null)
 {
     if (!$formatter) {
         $formatter = new Formatter(self::MSG_FORMAT);
     } elseif (!$formatter instanceof Formatter) {
         $formatter = new Formatter($formatter);
     }
     return function ($retries, AbstractTransferEvent $event) use($delayFn, $logger, $formatter) {
         $delay = call_user_func_array($delayFn, array($retries, $event));
         $logger->log(LogLevel::NOTICE, $formatter->format($event->getRequest(), $event->getResponse(), $event instanceof ErrorEvent ? $event->getException() : null, array('retries' => $retries + 1, 'delay' => $delay) + $event->getTransferInfo()));
         return $delay;
     };
 }