Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NotExists.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Validate/File/Exists.php';
26 
36 {
40  const DOES_EXIST = 'fileNotExistsDoesExist';
41 
45  protected $_messageTemplates = array(
46  self::DOES_EXIST => "File '%value%' exists",
47  );
48 
58  public function isValid($value, $file = null)
59  {
60  $directories = $this->getDirectory(true);
61  if (($file !== null) and (!empty($file['destination']))) {
62  $directories[] = $file['destination'];
63  } else if (!isset($file['name'])) {
64  $file['name'] = $value;
65  }
66 
67  foreach ($directories as $directory) {
68  if (empty($directory)) {
69  continue;
70  }
71 
72  $check = true;
73  if (file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) {
74  return $this->_throw($file, self::DOES_EXIST);
75  }
76  }
77 
78  if (!isset($check)) {
79  return $this->_throw($file, self::DOES_EXIST);
80  }
81 
82  return true;
83  }
84 }
$value
Definition: gender.phtml:16
getDirectory($asArray=false)
Definition: Exists.php:88
isValid($value, $file=null)
Definition: NotExists.php:58
_throw($file, $errorType)
Definition: Exists.php:195