• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Validate/File/FilesSize.php

00001 <?php
00025 require_once 'Zend/Validate/File/Size.php';
00026 
00035 class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size
00036 {
00040     const TOO_BIG      = 'fileFilesSizeTooBig';
00041     const TOO_SMALL    = 'fileFilesSizeTooSmall';
00042     const NOT_READABLE = 'fileFilesSizeNotReadable';
00043 
00047     protected $_messageTemplates = array(
00048         self::TOO_BIG      => "All files in sum should have a maximum size of '%max%' but '%size%' were detected",
00049         self::TOO_SMALL    => "All files in sum should have a minimum size of '%min%' but '%size%' were detected",
00050         self::NOT_READABLE => "One or more files can not be read"
00051     );
00052 
00058     protected $_files;
00059 
00069     public function __construct($options)
00070     {
00071         $this->_files = array();
00072         $this->_setSize(0);
00073 
00074         if ($options instanceof Zend_Config) {
00075             $options = $options->toArray();
00076         } elseif (is_scalar($options)) {
00077             $options = array('max' => $options);
00078         } elseif (!is_array($options)) {
00079             require_once 'Zend/Validate/Exception.php';
00080             throw new Zend_Validate_Exception('Invalid options to validator provided');
00081         }
00082 
00083         if (1 < func_num_args()) {
00084 // @todo: Preperation for 2.0... needs to be cleared with the dev-team
00085 //          trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
00086 
00087             $argv = func_get_args();
00088             array_shift($argv);
00089             $options['max'] = array_shift($argv);
00090             if (!empty($argv)) {
00091                 $options['bytestring'] = array_shift($argv);
00092             }
00093         }
00094 
00095         parent::__construct($options);
00096     }
00097 
00108     public function isValid($value, $file = null)
00109     {
00110         require_once 'Zend/Loader.php';
00111         if (is_string($value)) {
00112             $value = array($value);
00113         }
00114 
00115         $min  = $this->getMin(true);
00116         $max  = $this->getMax(true);
00117         $size = $this->_getSize();
00118         foreach ($value as $files) {
00119             // Is file readable ?
00120             if (!Zend_Loader::isReadable($files)) {
00121                 $this->_throw($file, self::NOT_READABLE);
00122                 continue;
00123             }
00124 
00125             if (!isset($this->_files[$files])) {
00126                 $this->_files[$files] = $files;
00127             } else {
00128                 // file already counted... do not count twice
00129                 continue;
00130             }
00131 
00132             // limited to 2GB files
00133             $size += @filesize($files);
00134             $this->_setSize($size);
00135             if (($max !== null) && ($max < $size)) {
00136                 if ($this->useByteString()) {
00137                     $this->setMax($this->_toByteString($max));
00138                     $this->_throw($file, self::TOO_BIG);
00139                     $this->setMax($max);
00140                 } else {
00141                     $this->_throw($file, self::TOO_BIG);
00142                 }
00143             }
00144         }
00145 
00146         // Check that aggregate files are >= minimum size
00147         if (($min !== null) && ($size < $min)) {
00148             if ($this->useByteString()) {
00149                 $this->setMin($this->_toByteString($min));
00150                 $this->_throw($file, self::TOO_SMALL);
00151                 $this->setMin($min);
00152             } else {
00153                 $this->_throw($file, self::TOO_SMALL);
00154             }
00155         }
00156 
00157         if (count($this->_messages) > 0) {
00158             return false;
00159         }
00160 
00161         return true;
00162     }
00163 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2