File indexing completed on 2024-12-22 05:37:11
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Validate 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Validate_File_Exists 0024 */ 0025 // require_once 'Zend/Validate/File/Exists.php'; 0026 0027 /** 0028 * Validator which checks if the destination file does not exist 0029 * 0030 * @category Zend 0031 * @package Zend_Validate 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Validate_File_NotExists extends Zend_Validate_File_Exists 0036 { 0037 /** 0038 * @const string Error constants 0039 */ 0040 const DOES_EXIST = 'fileNotExistsDoesExist'; 0041 0042 /** 0043 * @var array Error message templates 0044 */ 0045 protected $_messageTemplates = array( 0046 self::DOES_EXIST => "File '%value%' exists", 0047 ); 0048 0049 /** 0050 * Defined by Zend_Validate_Interface 0051 * 0052 * Returns true if and only if the file does not exist in the set destinations 0053 * 0054 * @param string $value Real file to check for 0055 * @param array $file File data from Zend_File_Transfer 0056 * @return boolean 0057 */ 0058 public function isValid($value, $file = null) 0059 { 0060 $directories = $this->getDirectory(true); 0061 if (($file !== null) and (!empty($file['destination']))) { 0062 $directories[] = $file['destination']; 0063 } else if (!isset($file['name'])) { 0064 $file['name'] = $value; 0065 } 0066 0067 foreach ($directories as $directory) { 0068 if (empty($directory)) { 0069 continue; 0070 } 0071 0072 $check = true; 0073 if (file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) { 0074 return $this->_throw($file, self::DOES_EXIST); 0075 } 0076 } 0077 0078 if (!isset($check)) { 0079 return $this->_throw($file, self::DOES_EXIST); 0080 } 0081 0082 return true; 0083 } 0084 }