"Fossies" - the Fresh Open Source Software Archive

Member "openmailadmin-1.0.1/inc/lib/Quota.php" (30 Jul 2007, 1430 Bytes) of package /linux/privat/old/openmailadmin-1.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Quota.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 /**
    3  * For formatting output.
    4  */
    5 class Quota
    6 {
    7     /** Used quota in kib or null. */
    8     private $used;
    9     /** Upper limit for quota in kib or null. */
   10     private $max;
   11 
   12     public function __construct($used = null, $max = null) {
   13         $this->used = $used;
   14         $this->max  = $max;
   15     }
   16 
   17     /**
   18      * @return      Format is concatenation of 'percent used', delimiter, upper limit. If no upper limit is set, $infin; will be returned.
   19      */
   20     public function format($delimiter = '/') {
   21         if(is_null($this->max)) {
   22             return '-'.$delimiter.'&infin;';
   23         } else if(round($this->used/$this->max*100) > 0) {
   24             return round($this->used/$this->max*100).'% '.$delimiter.' '.round($this->max/1024);
   25         } else if($this->used == 0) {
   26             return '0% '.$delimiter.' '.round($this->max/1024);
   27         } else {
   28             return '<1% '.$delimiter.' '.round($this->max/1024);
   29         }
   30     }
   31 
   32     public function __toString() {
   33         return $this->format();
   34     }
   35 
   36     /**
   37      * @throw       Exception if value does not exist.
   38      * @throw       OutOfRangeException if maximum is not set.
   39      */
   40     public function __get($key) {
   41         switch($key) {
   42             case 'is_set':
   43                 return !is_null($this->max);
   44             case 'used':
   45                 return $this->used;
   46             case 'max':
   47                 return $this->max;
   48             case 'free':
   49                 if(!is_null($this->max)) {
   50                     return ($this->max - $this->used);
   51                 } else {
   52                     return 1024*1024;
   53                     // throw new OutOfRangeException();
   54                 }
   55         }
   56         throw new Exception('Variable does not exist or has not been set.');
   57     }
   58 
   59 }
   60 ?>