/**
  * {@inheritdoc}
  */
 protected function init()
 {
     if (!isset($this['event_id'])) {
         /**
          * Support the old namespace
          */
         if (class_exists('Rhumsaa\\Uuid\\Uuid')) {
             $uuid = \Rhumsaa\Uuid\Uuid::uuid4();
         } else {
             $uuid = Uuid::uuid4();
         }
         $this['event_id'] = str_replace('-', '', $uuid->toString());
     }
     if (!isset($this['timestamp'])) {
         $this['timestamp'] = new \DateTime();
     }
     if ($this['timestamp'] instanceof \DateTime) {
         $this['timestamp'] = clone $this['timestamp'];
         $this['timestamp']->setTimezone(new \DateTimeZone('UTC'));
         $this['timestamp'] = $this['timestamp']->format('Y-m-d\\TH:i:s');
     }
     $factory = new VisitorFlyweight();
     $factory->addRequestVisitor('json', new JsonVisitor());
     $this->setRequestSerializer(new DefaultRequestSerializer($factory));
 }
 public function testAllowsAddingVisitors()
 {
     $f = new VisitorFlyweight();
     $j1 = new JsonRequestVisitor();
     $j2 = new JsonResponseVisitor();
     $f->addRequestVisitor('json', $j1);
     $f->addResponseVisitor('json', $j2);
     $this->assertSame($j1, $f->getRequestVisitor('json'));
     $this->assertSame($j2, $f->getResponseVisitor('json'));
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 protected function init()
 {
     if (!isset($this['event_id'])) {
         $this['event_id'] = Uuid::uuid4()->toString();
     }
     if (!isset($this['timestamp'])) {
         $this['timestamp'] = new \DateTime();
     }
     if ($this['timestamp'] instanceof \DateTime) {
         $this['timestamp'] = clone $this['timestamp'];
         $this['timestamp']->setTimezone(new \DateTimeZone('UTC'));
         $this['timestamp'] = $this['timestamp']->format(\DateTime::ISO8601);
     }
     $factory = new VisitorFlyweight();
     $factory->addRequestVisitor('json', new JsonVisitor());
     $this->setRequestSerializer(new DefaultRequestSerializer($factory));
 }
 /**
  * Add a location visitor to the serializer
  *
  * @param string                  $location Location to associate with the visitor
  * @param RequestVisitorInterface $visitor  Visitor to attach
  *
  * @return self
  */
 public function addVisitor($location, RequestVisitorInterface $visitor)
 {
     $this->factory->addRequestVisitor($location, $visitor);
     return $this;
 }