Static Public Member Functions

Robo47_Convert Class Reference

List of all members.

Static Public Member Functions

static shortHandToBytes ($value)
 Converts shorthand value to bytes.

Detailed Description

Definition at line 33 of file Convert.php.


Member Function Documentation

static Robo47_Convert::shortHandToBytes ( value  )  [static]

Converts shorthand value to bytes.

Shorthand values are used for example in the php.ini

See also:
http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
Returns:
integer upload_max_filesize as integer in bytes
Exceptions:
Robo47_Convert_Exception 

Definition at line 45 of file Convert.php.

    {
        if (is_numeric($value)) {
            if ($value >= PHP_INT_MAX) {
                $message = 'input is greater than PHP_INT_MAX on this ' .
                    'plattform (' . PHP_INT_MAX . ')';
                throw new Robo47_Convert_Exception($message);
            }
            return (int) $value;
        } else {
            $lastSign = strtolower($value{strlen($value) - 1});
            $valueBytes = (int) mb_substr($value, 0, strlen($value) - 1);
            switch ($lastSign) {
                case 'k':
                    $valueBytes *= 1024;
                    break;
                case 'm':
                    $valueBytes *= 1024 * 1024;
                    break;
                case 'g':
                    $valueBytes *= 1024 * 1024 * 1024;
                    break;
                default:
                    $message = 'invalid last sign in ' . $value;
                    throw new Robo47_Convert_Exception($message);
                    break;
            }
            if ($valueBytes >= PHP_INT_MAX) {
                $message = 'input is greater than PHP_INT_MAX on this ' .
                    'plattform (' . PHP_INT_MAX . ')';
                throw new Robo47_Convert_Exception($message);
            }
            return $valueBytes;
        }
    }


The documentation for this class was generated from the following file: