Appends signed 16-bit integer to buffer.

@param int $value
@return Buffer
972426
public function appendInt16($value)
    {
        $s = pack("s", $value);
        return $this->append(self::$isLittleEndian ? self::swapEndian16($s) : $s);
    }
832129
public function coerce($value): int
    {
        if ($value === '') {
            throw new InvalidTypeException('Int cannot represent non 32-bit signed integer value: (empty string)');
        }

        if (\is_bool($value)) {
            $value = (int)$value;
        }

        if (!\is_numeric($value) || $value > PHP_INT_MAX || $value < PHP_INT_MIN) {
            throw new InvalidTypeException(
                \sprintf('Int cannot represent non 32-bit signed integer value: %s', $value)
            );
        }

        $floatValue = (float)$value;

        if ($floatValue != $value || \floor($floatValue) !== $floatValue) {
            throw new InvalidTypeException(\sprintf('Int cannot represent non-integer value: %s', $value));
        }

        return (int)$value;
    }
1333796
public function add( $value )
	{
		if( !isset( $this->value ) )
			return $this->value = $value;
		if( $value == $this->value)
			return -1;
		if( $value < $this->value )
		{
			if( $this->left )
				$this->left->add( $value );
			else
				$this->left = new ADT_Tree_BinaryNode( $value );
		}
		else if( $value > $this->value )
		{
			if( $this->right )
				$this->right->add( $value );
			else
				$this->right = new ADT_Tree_BinaryNode( $value );
		}
	}
368783
public function encodeValue($value)
    {
        if (is_bool($value)) {
            return (int) $value;
        }

        if ($value instanceof Enum) {
            return $value->name();
        }

        if ($value instanceof Stream) {
            return json_encode($value->__toString());
        }

        return json_encode($value);
    }
625138
public function appendUint64($value)
    {
        if (self::$native64BitPack) {
            $s = pack("Q", $value);
            if (self::$isLittleEndian) {
                $s = self::swapEndian64($s);
            }
        } else {
            $s = pack("LL", ($value & 0xffffffff00000000) >> 32, $value & 0x00000000ffffffff);
            if (self::$isLittleEndian) {
                $s = self::swapHalvedEndian64($s);
            }
        }

        return $this->append($s);
    }
111561
protected function getExtraLengthBits($value)
    {
        if (($value >= 257 && $value <= 260) || $value === 285) {
            return 0;
        } elseif ($value >= 261 && $value <= 284) {
            return (($value - 257) >> 2) - 1;
        } else {
            throw new Exception\InvalidArgumentException('value', 'Invalid value');
        }
    }
1289475
public static function convertBytes($value)
    {
        if (is_numeric($value)) {
            return $value;
        }

        $value_length = \strlen($value);
        $qty = (int)substr($value, 0, $value_length - 1);
        $unit = Str::strtolower(substr($value, $value_length - 1));
        switch ($unit) {
            case 'k':
                $qty *= 1024;
                break;
            case 'm':
                $qty *= 1048576;
                break;
            case 'g':
                $qty *= 1073741824;
                break;
        }

        return $qty;
    }
592076
private function fixUtf8Encoding($value) {
        $encoding = mb_detect_encoding($value, null, true);
        if ($encoding!='ASCII' && $encoding!='UTF-8')
            $value = utf8_encode($value);
        return $value;
    }
1369498
public function addValue($value)
    {
        $this->assertCanHaveValue();
        $this->assertValueIsValid($value);

        if ($this->canHaveMultipleValues() && ! $this->hasValue($value)) {
            $value = array_merge($this->values, (array) $value);
        }

        $this->values = (array) $value;

        return $this;
    }
1345688
public function plus($value): IP
    {
        if ($value < 0) {
            return $this->minus(-1 * $value);
        }

        if ($value == 0) {
            return clone $this;
        }

        if (!$value instanceof self) {
            $value = new static($value);
        }

        $result = gmp_add($this->ip, $value->ip);

        if (!self::isValid($result)) {
            throw new \OutOfBoundsException(sprintf(
                'The sum of "%s" and "%s" is not a valid IPv%d address.',
                $this->humanReadable(),
                $value->humanReadable(),
                static::IP_VERSION
            ));
        }

        return new static($result);
    }
531257
public function prepend($value)
	{
		$value = $this->normalizeValue($value);

		array_unshift($this->items, $value);

		return $value;
	}
1183479
public function writeUInt32(int $value): self
    {
        $this->bytes .= Writer::bit32($value);

        return $this;
    }
854383
public function append($value)
    {
        $values = $this->sanitize($value);

        foreach ($values as $class) {
            parent::append($class);
        }

        return $this;
    }
1316064
public static function isIsbn($value)
    {
        $value = str_replace(array(' ', '-', '.'), '', $value);
        $length = strlen($value);
        $checkdigit = substr($value, -1);

        if ($length == 10) {

            if ( ! is_numeric(substr($value, -10, 9))) {
                return false;
            }

            $checkdigit = ( ! is_numeric($checkdigit)) ? $checkdigit : strtoupper($checkdigit);
            $checkdigit = ($checkdigit == 'X') ? '10' : $checkdigit;

            $sum = 0;

            for ($i = 0; $i < 9; $i++) {
                $sum = $sum + ($value[$i] * (10 - $i));
            }

            $sum = $sum + $checkdigit;
            $mod = $sum % 11;

            return ($mod == 0);

        } elseif ($length == 13) {

            $sum = 0;

            $sum =  $value[0] + ($value[1] * 3) + $value[2] + ($value[3] * 3) +
                    $value[4] + ($value[5] * 3) + $value[6] + ($value[7] * 3) +
                    $value[8] + ($value[9] * 3) + $value[10] + ($value[11] * 3);

            $mod = $sum % 10;

            $correct_checkdigit = 10 - $mod;
            $correct_checkdigit = ($correct_checkdigit == "10") ? "0" : $correct_checkdigit;

            return ($checkdigit == $correct_checkdigit);

        }

        return false;
    }
772681
protected function intToBinary($value)
    {
        $nbytes = 0;
        if ($value > 0xFF) {
            $nbytes = 1; // 1 byte integer
        }
        if ($value > 0xFFFF) {
            $nbytes += 1; // 4 byte integer
        }
        if ($value > 0xFFFFFFFF) {
            $nbytes += 1; // 8 byte integer
        }
        if ($value < 0) {
            $nbytes = 3; // 8 byte integer, since signed
        }

        $bdata = self::typeBytes("1", $nbytes); // 1 is 0001, type indicator for integer
        $buff = "";

        if ($nbytes < 3) {
            if ($nbytes == 0) {
                $fmt = "C";
            } elseif ($nbytes == 1) {
                $fmt = "n";
            } else {
                $fmt = "N";
            }

            $buff = pack($fmt, $value);
        } else {
            if (PHP_INT_SIZE > 4) {
              // 64 bit signed integer; we need the higher and the lower 32 bit of the value
                $high_word = $value >> 32;
                $low_word = $value & 0xFFFFFFFF;
            } else {
                // since PHP can only handle 32bit signed, we can only get 32bit signed values at this point - values above 0x7FFFFFFF are
                // floats. So we ignore the existance of 64bit on non-64bit-machines
                if ($value < 0) {
                    $high_word = 0xFFFFFFFF;
                } else {
                    $high_word = 0;
                }
                $low_word = $value;
            }
            $buff = pack("N", $high_word).pack("N", $low_word);
        }

        return $bdata.$buff;
    }
59186
public function packInteger($value)
    {
        $pow15 = pow(2, 15);
        $pow31 = pow(2, 31);
        $b = '';

        if ($value > -16 && $value < 128) {
            //$b .= chr(Constants::INT_8);
            //$b .= $this->packBigEndian($value, 2);
            return $this->packSignedShortShort($value);
        }

        if ($value > -129 && $value < -16) {
            $b .= chr(Constants::INT_8);
            $b .= $this->packSignedShortShort($value);

            return $b;
        }

        if ($value < -16 && $value > -129) {
            $b .= chr(Constants::INT_8);
            $b .= $this->packSignedShortShort($value);

            return $b;
        }

        if ($value < -128 && $value > -32769) {
            $b .= chr(Constants::INT_16);
            $b .= $this->packBigEndian($value, 2);

            return $b;
        }

        if ($value >= -16 && $value < 128) {
            return $this->packSignedShortShort($value);
        }

        if ($value > 127 && $value < $pow15) {
            $b .= chr(Constants::INT_16);
            $b .= pack('n', $value);

            return $b;
        }

        if ($value > 32767 && $value < $pow31) {
            $b .= chr(Constants::INT_32);
            $b .= pack('N', $value);

            return $b;
        }

        // 32 INTEGERS MINUS
        if ($value >= (-1 * abs(pow(2, 31))) && $value < (-1 * abs(pow(2, 15)))) {
            $b .= chr(Constants::INT_32);
            $b .= pack('N', $value);

            return $b;
        }

        // 64 INTEGERS POS
        if ($value >= pow(2, 31) && $value < pow(2, 63)) {
            $b .= chr(Constants::INT_64);
            //$b .= $this->packBigEndian($value, 8);
            $b .= pack('J', $value);

            return $b;
        }

        // 64 INTEGERS MINUS
        if ($value >= ((-1 * abs(pow(2, 63))) - 1) && $value < (-1 * abs(pow(2, 31)))) {
            $b .= chr(Constants::INT_64);
            $b .= pack('J', $value);

            return $b;
        }

        throw new BoltOutOfBoundsException(sprintf('Out of bound value, max is %d and you give %d', PHP_INT_MAX, $value));
    }
693019
public function writeInt($value)
    {
        settype($value, 'integer');
        $this->_fwrite(
            chr($value>>24 & 0xFF) .
                        chr($value>>16 & 0xFF) .
                        chr($value>>8  & 0xFF) .
            chr($value     & 0xFF),   4  
        );
    }