Exemplo n.º 1
0
 /**
  * test setting computed type
  * expected new type
  */
 public function testBinarySetComputedType2()
 {
     $value = new Zend_Measure_Binary('-100', Zend_Measure_Binary::TERABYTE, 'de');
     $value->setType(Zend_Measure_Binary::KILOBYTE);
     $this->assertEquals(Zend_Measure_Binary::KILOBYTE, $value->getType(), 'Zend_Measure_Binary type expected');
 }
Exemplo n.º 2
0
 /**
  * Formats filesize with specified precision
  *
  * @param integer $fileSize Filesize in bytes
  * @param integer $precision Precision
  * @param string $norm Which norm use - 'traditional' (1 KB = 2^10 B), 'si' (1 KB = 10^3 B), 'iec' (1 KiB = 2^10 B)
  * @param string $type Defined export type
  */
 public function fileSize($fileSize, $precision = 0, $norm = 'traditional', $type = null)
 {
     $m = new Zend_Measure_Binary($fileSize);
     $m->setType('BYTE');
     if (null === $norm) {
         $norm = 'traditional';
     }
     if (isset($type)) {
         $m->setType($type);
     } elseif ($norm === 'traditional') {
         if ($fileSize >= $this->_getUnitSize('TERABYTE')) {
             $m->setType(Zend_Measure_Binary::TERABYTE);
         } else {
             if ($fileSize >= $this->_getUnitSize('GIGABYTE')) {
                 $m->setType(Zend_Measure_Binary::GIGABYTE);
             } else {
                 if ($fileSize >= $this->_getUnitSize('MEGABYTE')) {
                     $m->setType(Zend_Measure_Binary::MEGABYTE);
                 } else {
                     if ($fileSize >= $this->_getUnitSize('KILOBYTE')) {
                         $m->setType(Zend_Measure_Binary::KILOBYTE);
                     }
                 }
             }
         }
     } elseif ($norm === 'si') {
         if ($fileSize >= $this->_getUnitSize('TERABYTE_SI')) {
             $m->setType(Zend_Measure_Binary::TERABYTE_SI);
         } else {
             if ($fileSize >= $this->_getUnitSize('GIGABYTE_SI')) {
                 $m->setType(Zend_Measure_Binary::GIGABYTE_SI);
             } else {
                 if ($fileSize >= $this->_getUnitSize('MEGABYTE_SI')) {
                     $m->setType(Zend_Measure_Binary::MEGABYTE_SI);
                 } else {
                     if ($fileSize >= $this->_getUnitSize('KILOBYTE_SI')) {
                         $m->setType(Zend_Measure_Binary::KILOBYTE_SI);
                     }
                 }
             }
         }
     } elseif ($norm === 'iec') {
         if ($fileSize >= $this->_getUnitSize('TEBIBYTE')) {
             $m->setType(Zend_Measure_Binary::TEBIBYTE);
         } else {
             if ($fileSize >= $this->_getUnitSize('GIBIBYTE')) {
                 $m->setType(Zend_Measure_Binary::GIBIBYTE);
             } else {
                 if ($fileSize >= $this->_getUnitSize('MEBIBYTE')) {
                     $m->setType(Zend_Measure_Binary::MEBIBYTE);
                 } else {
                     if ($fileSize >= $this->_getUnitSize('KIBIBYTE')) {
                         $m->setType(Zend_Measure_Binary::KIBIBYTE);
                     }
                 }
             }
         }
     }
     $value = $m->getValue($precision);
     $value = $this->_round($value, $precision);
     return $value . ' ' . $this->_getUnitAbr($m->getType());
 }