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.');
}