web/lib/Zend/Validate/File/FilesSize.php
author Nicolas Sauret <nicolas.sauret@iri.centrepompidou.fr>
Thu, 13 Mar 2014 15:27:13 +0100
changeset 1081 a1816934e459
parent 807 877f952ae2bd
child 1230 68c69c656a2c
permissions -rw-r--r--
add edito#4

<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category  Zend
 * @package   Zend_Validate
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 * @version   $Id: FilesSize.php 24593 2012-01-05 20:35:02Z matthew $
 */

/**
 * @see Zend_Validate_File_Size
 */
require_once 'Zend/Validate/File/Size.php';

/**
 * Validator for the size of all files which will be validated in sum
 *
 * @category  Zend
 * @package   Zend_Validate
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size
{
    /**
     * @const string Error constants
     */
    const TOO_BIG      = 'fileFilesSizeTooBig';
    const TOO_SMALL    = 'fileFilesSizeTooSmall';
    const NOT_READABLE = 'fileFilesSizeNotReadable';

    /**
     * @var array Error message templates
     */
    protected $_messageTemplates = array(
        self::TOO_BIG      => "All files in sum should have a maximum size of '%max%' but '%size%' were detected",
        self::TOO_SMALL    => "All files in sum should have a minimum size of '%min%' but '%size%' were detected",
        self::NOT_READABLE => "One or more files can not be read",
    );

    /**
     * Internal file array
     *
     * @var array
     */
    protected $_files;

    /**
     * Sets validator options
     *
     * Min limits the used diskspace for all files, when used with max=null it is the maximum filesize
     * It also accepts an array with the keys 'min' and 'max'
     *
     * @param  integer|array|Zend_Config $options Options for this validator
     * @return void
     */
    public function __construct($options)
    {
        $this->_files = array();
        $this->_setSize(0);

        if ($options instanceof Zend_Config) {
            $options = $options->toArray();
        } elseif (is_scalar($options)) {
            $options = array('max' => $options);
        } elseif (!is_array($options)) {
            require_once 'Zend/Validate/Exception.php';
            throw new Zend_Validate_Exception('Invalid options to validator provided');
        }

        if (1 < func_num_args()) {
            $argv = func_get_args();
            array_shift($argv);
            $options['max'] = array_shift($argv);
            if (!empty($argv)) {
                $options['bytestring'] = array_shift($argv);
            }
        }

        parent::__construct($options);
    }

    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if the disk usage of all files is at least min and
     * not bigger than max (when max is not null).
     *
     * @param  string|array $value Real file to check for size
     * @param  array        $file  File data from Zend_File_Transfer
     * @return boolean
     */
    public function isValid($value, $file = null)
    {
        require_once 'Zend/Loader.php';
        if (is_string($value)) {
            $value = array($value);
        }

        $min  = $this->getMin(true);
        $max  = $this->getMax(true);
        $size = $this->_getSize();
        foreach ($value as $files) {
            // Is file readable ?
            if (!Zend_Loader::isReadable($files)) {
                $this->_throw($file, self::NOT_READABLE);
                continue;
            }

            if (!isset($this->_files[$files])) {
                $this->_files[$files] = $files;
            } else {
                // file already counted... do not count twice
                continue;
            }

            // limited to 2GB files
            $size += @filesize($files);
            $this->_size = $size;
            if (($max !== null) && ($max < $size)) {
                if ($this->useByteString()) {
                    $this->_max  = $this->_toByteString($max);
                    $this->_size = $this->_toByteString($size);
                    $this->_throw($file, self::TOO_BIG);
                    $this->_max  = $max;
                    $this->_size = $size;
                } else {
                    $this->_throw($file, self::TOO_BIG);
                }
            }
        }

        // Check that aggregate files are >= minimum size
        if (($min !== null) && ($size < $min)) {
            if ($this->useByteString()) {
                $this->_min  = $this->_toByteString($min);
                $this->_size = $this->_toByteString($size);
                $this->_throw($file, self::TOO_SMALL);
                $this->_min  = $min;
                $this->_size = $size;
            } else {
                $this->_throw($file, self::TOO_SMALL);
            }
        }

        if (count($this->_messages) > 0) {
            return false;
        }

        return true;
    }
}
PKUM@7@3T metadataplayer-8407313c144f/test/emission_fichiers/1219830366Middlex02BottomRight.jsUT8OPKUM@˛-` B Rmetadataplayer-8407313c144f/test/emission_fichiers/265074200838.jsUT8OPKUM@4Z 01P +metadataplayer-8407313c144f/test/emission_fichiers/97820204039860-2000020811.jpgUT8OPKUM@756? SEmetadataplayer-8407313c144f/test/emission_fichiers/Garrigou.jpgUT8OPKUM@/ 7eD {metadataplayer-8407313c144f/test/emission_fichiers/addthis_widget.jsUT8OPKUM@ᙛ (D metadataplayer-8407313c144f/test/emission_fichiers/ajax-responder.jsUT8OPKUM@N56= metadataplayer-8407313c144f/test/emission_fichiers/baudin.jpgUT8OPKUM@S5S= metadataplayer-8407313c144f/test/emission_fichiers/comment.jsUT8OPKUM@{S[ \metadataplayer-8407313c144f/test/emission_fichiers/css_8af77a07a1f960afe4e4736580827c7c.cssUT8OPKUM@]D[[ metadataplayer-8407313c144f/test/emission_fichiers/css_bf9cf64d750be06f6006828a2bed7b98.cssUT8OPKUM@|Ij[ 8metadataplayer-8407313c144f/test/emission_fichiers/css_e94d821d2c09c140834405452127e5ae.cssUT8OPKUM@/' V fmetadataplayer-8407313c144f/test/emission_fichiers/culture_les_retours_du_dimanche.jpgUT8OPKUM@(= metadataplayer-8407313c144f/test/emission_fichiers/direct.pngUT8OPKUM@b0C ?&< pmetadataplayer-8407313c144f/test/emission_fichiers/drupal.jsUT8OPKUM@O$J }metadataplayer-8407313c144f/test/emission_fichiers/fc_antidot_recherche.jsUT8OPKUM@G҇D metadataplayer-8407313c144f/test/emission_fichiers/fc_bloc_direct.jsUT8OPKUM@}KfG metadataplayer-8407313c144f/test/emission_fichiers/fc_widget_twitter.jsUT8OPKUM@YA> metadataplayer-8407313c144f/test/emission_fichiers/fivestar.jsUT8OPKUM@!@I߼< 6metadataplayer-8407313c144f/test/emission_fichiers/footer.jsUT8OPKUM@yfY emetadataplayer-8407313c144f/test/emission_fichiers/fr_4fb8f115d8d263374d07dafa1b2a40b5.jsUT8OPKUM@Fʝ D [metadataplayer-8407313c144f/test/emission_fichiers/franceculture.pngUT8OPKUM@/& : smetadataplayer-8407313c144f/test/emission_fichiers/high.jsUT8OPKUM@&QfB metadataplayer-8407313c144f/test/emission_fichiers/inscription.pngUT8OPKUM@ԓ Ү < Xmetadataplayer-8407313c144f/test/emission_fichiers/jquery.jsUT8OPKUM@KP.@ ymetadataplayer-8407313c144f/test/emission_fichiers/jquery_002.jsUT8OPKUM@V (@ metadataplayer-8407313c144f/test/emission_fichiers/jquery_003.jsUT8OPKUM@/ AL$@ %metadataplayer-8407313c144f/test/emission_fichiers/jquery_004.jsUT8OPKUM@^C@ metadataplayer-8407313c144f/test/emission_fichiers/jquery_005.jsUT8OPKUM@ @ gmetadataplayer-8407313c144f/test/emission_fichiers/jquery_006.jsUT8OPKUM@-B$g m!O ѣmetadataplayer-8407313c144f/test/emission_fichiers/la_nuit_du_monde20100423.jpgUT8OPKUM@醛.6n7k metadataplayer-8407313c144f/test/emission_fichiers/le_mal_du_pays_autobiographie_de_la_belgique20100424.jpgUT8OPKUM@H._0s metadataplayer-8407313c144f/test/emission_fichiers/les_lites_contre_la_rpublique_histoire_et_mutations_de_scien.jpgUT8OPKUM@xӪc}= +metadataplayer-8407313c144f/test/emission_fichiers/listen.pngUT8OPKUM@; 2metadataplayer-8407313c144f/test/emission_fichiers/logo.pngUT8OPKUM@ ? 6metadataplayer-8407313c144f/test/emission_fichiers/more-red.pngUT8OPKUM@%k9:< 7metadataplayer-8407313c144f/test/emission_fichiers/panels.jsUT8OPKUM@I 09metadataplayer-8407313c144f/test/emission_fichiers/picto-ecoute-rouge.pngUT8OPKUM@ݕLC y:metadataplayer-8407313c144f/test/emission_fichiers/picto-mobile.pngUT8OPKUM@!@ ;metadataplayer-8407313c144f/test/emission_fichiers/picto-rss.gifUT8OPKUM@J`\< <metadataplayer-8407313c144f/test/emission_fichiers/popups.jsUT8OPKUM@)>@ _>metadataplayer-8407313c144f/test/emission_fichiers/popups_002.jsUT8OPKUM@ʙ F bhmetadataplayer-8407313c144f/test/emission_fichiers/retour_dimanche.pngUT8OPKUM@RuoE? metadataplayer-8407313c144f/test/emission_fichiers/rf_player.jsUT8OPKUM@px> metadataplayer-8407313c144f/test/emission_fichiers/rollover.jsUT8OPKUM@ Zd?< vmetadataplayer-8407313c144f/test/emission_fichiers/script.jsUT8OPKUM@pD ďmetadataplayer-8407313c144f/test/emission_fichiers/search-submit.pngUT8OPKUM@^3f4; metadataplayer-8407313c144f/test/emission_fichiers/sh20.htmUT8OPKUM@Qt_'@ metadataplayer-8407313c144f/test/emission_fichiers/swfobject.txtUT8OPKUM@1A ̹metadataplayer-8407313c144f/test/emission_fichiers/tableheader.jsUT8OPKUM@ rM> metadataplayer-8407313c144f/test/emission_fichiers/textarea.jsUT8OPKUM@ $? metadataplayer-8407313c144f/test/emission_fichiers/widget40.cssUT8OPKUM@@:8< umetadataplayer-8407313c144f/test/emission_fichiers/xtcore.jsUT8OPKUM@7"2= metadataplayer-8407313c144f/test/emission_fichiers/youtube.jsUT8OPKUM@#;&6 metadataplayer-8407313c144f/test/index-dailymotion.htmUT8OPKUM@%!7 /metadataplayer-8407313c144f/test/index-videoelement.htmUT8OPKUM@F/) 2 metadataplayer-8407313c144f/test/index-youtube.htmUT8OPKUM@p8r*  metadataplayer-8407313c144f/test/index.htmUT8OPKUM@-#>, Mmetadataplayer-8407313c144f/test/indexFC.htmUT8OPKUM@oz!>- Ometadataplayer-8407313c144f/test/indexFC2.htmUT8OPKUM@a!4< Xmetadataplayer-8407313c144f/test/integration/html5-video.htmUT8OPKUM@=!٥? metadataplayer-8407313c144f/test/integration/jwplayer-video.htmUT8OPKUM@NA  D metadataplayer-8407313c144f/test/integration/polemic-dailymotion.htmUT8OPKUM@z*,A $metadataplayer-8407313c144f/test/integration/polemic-festival.htmUT8OPKUM@F(a}> 4metadataplayer-8407313c144f/test/integration/polemic-jsonp.htmUT8OPKUM@:,QA (metadataplayer-8407313c144f/test/integration/polemic-platform.htmUT8OPKUM@lj5 g @ metadataplayer-8407313c144f/test/integration/polemic-youtube.htmUT8OPKUM@8 umetadataplayer-8407313c144f/test/integration/polemic.htmUT8OPKUM@pz?< metadataplayer-8407313c144f/test/integration/polemic_fr.jsonUT8OPKUM@< /metadataplayer-8407313c144f/test/integration/polemic_jp.jsonUT8OPKUM@!P6 ^ metadataplayer-8407313c144f/test/integration/radio.htmUT8OPKUM@ U'=  metadataplayer-8407313c144f/test/integration/twitterized.jsonUT8OPKUM@ F: 8 Z metadataplayer-8407313c144f/test/integration/youtube.htmUT8OPKUM@bJ0 ^ metadataplayer-8407313c144f/test/libs/player.swfUT8OPKUM@rc݇52 W metadataplayer-8407313c144f/test/test-youtube.jsonUT8OPKUM@!Hr(C*  metadataplayer-8407313c144f/test/test.jsonUT8OPKKK#~