Converts an PHP INI-Value from string to integer (bytes).

@param string $value The value to convert

@author Benjamin Carl <opensource@clickalicious.de>

@return int The value in bytes
320251
protected function convertToBytes($value)
    {
        $value = trim($value);
        $last  = strtolower($value[strlen($value) - 1]);

        switch ($last) {
            // The 'G' modifier is available since PHP 5.1.0
            case 'g':
                $value *= 1024;
                break;

            case 'm':
                $value *= 1024;
                break;

            case 'k':
                $value *= 1024;
                break;
        }

        return $value;
    }
1138142
public function writeInt($value)
    {
        // We do not need to check if file position points to the end of "file".
        // Only append operation is supported now

        settype($value, 'integer');
        $this->_data .= chr($value>>24 & 0xFF) .
                        chr($value>>16 & 0xFF) .
                        chr($value>>8  & 0xFF) .
                        chr($value     & 0xFF);

        $this->_position = strlen($this->_data);
    }
21414
public static function toInteger($value, array $options = array())
    {
        $options['precision'] = 0;
        $options['number_format'] = Zend_Locale_Format::STANDARD;
        return self::toNumber($value, $options);
    }
306022
protected function inArray($value)
    {
        if ($this->strict) {
            $isIn = in_array($value, $this->range, true);
        } else {
            $isIn = false;
            foreach ($this->range as $r) {
                $isIn = (strcmp($r, $value) === 0);
                if ($isIn) break;
            }
        }
        return $isIn;
    }
294941
protected function getBoolFromStringInt($value)
    {
        if (!($value == '0' || $value == '1')) {
            $this->throwException(sprintf('Expected "0" or "1" but got: %s', $value));
        }

        return (bool) $value;
    }
8139
public static function numericId ($value)
    {
        // Check type and characters
        if (!is_int($value)
            &&
            !(is_string($value) && preg_match('/^[0-9]+$/', $value))
        ) {
            return false;
        }

        // Check range
        if ($value > 0) {
            return false;
        }

        // Valid
        return true;
    }
304424
public static function ToString( $value )
	{
		if ( is_string( $value ) )

			return $value;

		if ( is_null( $value ) )

			return "false";

		if ( is_bool( $value ) )

			return $value ? "true" : "false";

		if ( $value instanceof TrueValue )

			return "true";

		if ( $value instanceof FalseValue )

			return "false";

		if ( $value instanceof Integer )

			return $value->ToString( null );

		if ( $value instanceof DecimalValue )

			return $value->getRound( 18 )->ToString( null );

		if ( is_numeric( $value ) && ( is_int( $value ) || $value == PHP_INT_MIN ) ) // PHP does not seem to detect PHP_INT_MIN as an int

			return $value . "";

		if ( is_numeric( $value ) && is_nan( $value ) )
		{
			return "NaN";
		}

		if ( is_numeric( $value ) && is_double( $value ) )
		{
			// Using sprintf( "%e", $value ) is not good enough because it will
			// only produce number with a maximum of 7 significant digits
			/* if( preg_match( "/^(?<sign>-)?(?<zeros>0\.0*)/", $value, $m ) )
			{
				$zeroes = strlen( $m['zeros'] );
				$sign = strlen( $m['sign'] );
				return ( $sign ? "-" : "" ) . substr( $value, $zeroes + $sign, 1 ) . rtrim( "." . substr( $value, $zeroes + $sign + 1 ), "0." ) . "E-" . ( $zeroes-1 );
			}
			else
			 */
			if( preg_match( "/^(?<sign>-)?(?<digits>\d{7,})(?:\.(?<decimals>\d+))?/", $value, $m ) )
			{
				$zeroes = strlen( $m['digits'] );
				$sign = strlen( $m['sign'] );
				$d = rtrim( "." . substr( $m['digits'], 1 ) . ( isset( $m['decimals'] ) ? $m['decimals'] : "" ), "0." );
				if ( empty( $d ) ) $d = ".0";
				$x = ( $sign ? "-" : "" ) . substr( $value, 0 + $sign, 1 ) . $d . "E" . ( $zeroes - 1 );
				return $x;
			}

			return str_replace( "+", "", $value . "" );
		}

		if ( $value instanceof \DateInterval )
		{
			return ( new DurationValue( $value ) )->ToString();
			// return ( new YearMonthDurationValue( $value ) )->ToString();
			// return ( new DayTimeDurationValue( $value ) )->ToString();
		}

		if ( $value instanceof \DateTime )
		{
			$format = "";
			if ( property_exists( $value, "isDate" ) && $value->isDate ) $format .= "Y-m-d";
			if ( property_exists( $value, "isTime" ) && $value->isTime ) $format .= ( empty( $format ) ? "" :"\T" ) . "H:i:s";
			$format .= ( $value->getTimezone()->getName() == date_default_timezone_get() ? "" : "P" );
			return  $value->format( $format ); // DateTimeValue::fromDate( false, $value ) )->ToString();
		}

		return $value->ToString();
	}
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;
    }
126769
private function getNumericValue(string $value)
    {
        if (\strpos($value, '.') !== false) {
            return (float) $value;
        }

        return (int) $value;
    }
884800
private static function convertToString($value): string
    {
        // float value (INF and NAN are float type)
        if (is_float($value)) {
            if (is_infinite($value)) {
                $value = 'INF';
            } elseif (is_nan($value)) {
                $value = 'NAN';
            } else {
                $value = (string) $value;
                if (self::XML_PRESERVE_ZERO_FRACTION && strpos($value, '.') === false) {
                    $value .= '.0';
                }
            }
        }

        // bool value
        if (is_bool($value)) {
            $value = ($value === true) ? 'true' : 'false';
        }

        // class value
        if (is_object($value)) {
            $value = json_encode($value);
        }

        // int or string value.
        return (string) $value;
    }
851988
public static function ToInteger( $value, $provider = null )
	{
		if ( $value instanceof Integer)
		{
			return $value;
		}

		if ( is_int( $value ) )
		{
			$int = $value;
		}
		else
		{
			$int = Convert::ToDouble( $value, $provider );
			if ( is_null( $int ) ) throw new InvalidCastException("Unable to convert value '$value' to type Integer" );
		}

		return Integer::FromValue( $int );
	}
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');
        }
    }
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  
        );
    }
793889
public static function isInt($value) {
        if(is_object($value)) {
            $value = Assert::isString($value);
        }
        if(is_int($value)) {
            return $value;
        } elseif(is_scalar($value) && preg_match('@^-?[0-9]+$@', $value)) {
            return (int)$value;
        } else {
            throw new \InvalidArgumentException('Must be Int: ' . print_r($value, true));
        }
    }
1135346
public static function isInteger($value)
    {
        if (is_int($value)) {
            return true;
        } elseif (!is_string($value)) {
            return false;
        }

        return preg_match('/^\d+$/', $value) > 0;
    }
390573
private function calc_size( $value ) {

		$type = gettype( $value );

		switch ( $type ) {
			case 'string' :
				return function_exists( 'mb_strlen' ) ? mb_strlen( $value ) : strlen( $value );
			case 'integer' :
			case 'double' :
			case 'boolean' :
				return (int) $value;
			case 'array' :
			case 'object' :
				return count( $value );
		}

		return - 1;

	}
1072046
public function computeStringSize($value)
    {
        $length = mb_strlen($value, '8bit');
        $size   = $length + $this->computeVarintSize($length);

        return $size;
    }