Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Validator / File / NotExists.php
blobdf13531d8d2a8c2dd2ef3ce98b63099a72400047
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Validator\File;
12 use Zend\Validator\Exception;
14 /**
15 * Validator which checks if the destination file does not exist
17 class NotExists extends Exists
19 /**
20 * @const string Error constants
22 const DOES_EXIST = 'fileNotExistsDoesExist';
24 /**
25 * @var array Error message templates
27 protected $messageTemplates = array(
28 self::DOES_EXIST => "File exists",
31 /**
32 * Returns true if and only if the file does not exist in the set destinations
34 * @param string|array $value Real file to check for existence
35 * @param array $file File data from \Zend\File\Transfer\Transfer (optional)
36 * @return bool
38 public function isValid($value, $file = null)
40 if (is_string($value) && is_array($file)) {
41 // Legacy Zend\Transfer API support
42 $filename = $file['name'];
43 $file = $file['tmp_name'];
44 $this->setValue($filename);
45 } elseif (is_array($value)) {
46 if (!isset($value['tmp_name']) || !isset($value['name'])) {
47 throw new Exception\InvalidArgumentException(
48 'Value array must be in $_FILES format'
51 $file = $value['tmp_name'];
52 $filename = basename($file);
53 $this->setValue($value['name']);
54 } else {
55 $file = $value;
56 $filename = basename($file);
57 $this->setValue($filename);
60 $check = false;
61 $directories = $this->getDirectory(true);
62 if (!isset($directories)) {
63 $check = true;
64 if (file_exists($file)) {
65 $this->error(self::DOES_EXIST);
66 return false;
68 } else {
69 foreach ($directories as $directory) {
70 if (!isset($directory) || '' === $directory) {
71 continue;
74 $check = true;
75 if (file_exists($directory . DIRECTORY_SEPARATOR . $filename)) {
76 $this->error(self::DOES_EXIST);
77 return false;
82 if (!$check) {
83 $this->error(self::DOES_EXIST);
84 return false;
87 return true;