Example #1
0
 public function testMatchReturnsNull()
 {
     $t1 = $this->getTransformerMock(1);
     $t1->expects($this->once())->method('supports')->willReturn(false);
     $this->coll->add($t1);
     $t2 = $this->getTransformerMock(2);
     $t2->expects($this->once())->method('supports')->willReturn(false);
     $this->coll->add($t2);
     $this->assertNull($this->coll->match(new \stdClass()));
 }
Example #2
0
 private function unpackExt($length)
 {
     if (!isset($this->buffer[$this->offset + $length - 1])) {
         throw new InsufficientDataException($length, \strlen($this->buffer) - $this->offset);
     }
     $type = $this->unpackInt8();
     if ($this->transformers && ($transformer = $this->transformers->find($type))) {
         return $transformer->reverseTransform($this->unpack());
     }
     $data = \substr($this->buffer, $this->offset, $length);
     $this->offset += $length;
     return new Ext($type, $data);
 }
Example #3
0
 public function pack($value)
 {
     if (\is_int($value)) {
         return $this->packInt($value);
     }
     if (\is_string($value)) {
         if (!$this->strDetectionMode) {
             return \preg_match(self::UTF8_REGEX, $value) ? $this->packStr($value) : $this->packBin($value);
         }
         if (self::FORCE_STR === $this->strDetectionMode) {
             return $this->packStr($value);
         }
         return $this->packBin($value);
     }
     if (\is_array($value)) {
         if (!$this->arrDetectionMode) {
             return \array_values($value) === $value ? $this->packArray($value) : $this->packMap($value);
         }
         if (self::FORCE_ARR === $this->arrDetectionMode) {
             return $this->packArray($value);
         }
         return $this->packMap($value);
     }
     if (null === $value) {
         return $this->packNil();
     }
     if (\is_bool($value)) {
         return $this->packBool($value);
     }
     if (\is_double($value)) {
         return $this->packFloat($value);
     }
     if ($value instanceof Ext) {
         return $this->packExt($value);
     }
     if ($this->transformers && ($transformer = $this->transformers->match($value))) {
         $ext = new Ext($transformer->getId(), $this->pack($transformer->transform($value)));
         return $this->packExt($ext);
     }
     throw new PackingFailedException($value, 'Unsupported type.');
 }