Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Validate_File_Exists Class Reference
Inheritance diagram for Zend_Validate_File_Exists:
Zend_Validate_Abstract Zend_Validate_Interface Zend_Validate_File_NotExists

Public Member Functions

 __construct ($directory=array())
 
 getDirectory ($asArray=false)
 
 setDirectory ($directory)
 
 addDirectory ($directory)
 
 isValid ($value, $file=null)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 
- Public Member Functions inherited from Zend_Validate_Interface
 isValid ($value)
 

Data Fields

const DOES_NOT_EXIST = 'fileExistsDoesNotExist'
 

Protected Member Functions

 _throw ($file, $errorType)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 

Protected Attributes

 $_messageTemplates
 
 $_directory = ''
 
 $_messageVariables
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 35 of file Exists.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $directory = array())

Sets validator options

Parameters
string | array | Zend_Config$directory
Exceptions
Zend_Validate_Exception

Definition at line 68 of file Exists.php.

69  {
70  if ($directory instanceof Zend_Config) {
71  $directory = $directory->toArray();
72  } else if (is_string($directory)) {
73  $directory = explode(',', $directory);
74  } else if (!is_array($directory)) {
75  #require_once 'Zend/Validate/Exception.php';
76  throw new Zend_Validate_Exception ('Invalid options to validator provided');
77  }
78 
79  $this->setDirectory($directory);
80  }
setDirectory($directory)
Definition: Exists.php:105

Member Function Documentation

◆ _throw()

_throw (   $file,
  $errorType 
)
protected

Throws an error of the given type

Parameters
string$file
string$errorType
Returns
false

Definition at line 195 of file Exists.php.

196  {
197  if ($file !== null) {
198  $this->_value = $file['name'];
199  }
200 
201  $this->_error($errorType);
202  return false;
203  }
_error($messageKey, $value=null)
Definition: Abstract.php:284

◆ addDirectory()

addDirectory (   $directory)

Adds the file directory which will be checked

Parameters
string | array$directoryThe directory to add for validation
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_File_Extension Provides a fluent interface

Definition at line 119 of file Exists.php.

120  {
121  $directories = $this->getDirectory(true);
122 
123  if (is_string($directory)) {
124  $directory = explode(',', $directory);
125  } else if (!is_array($directory)) {
126  #require_once 'Zend/Validate/Exception.php';
127  throw new Zend_Validate_Exception ('Invalid options to validator provided');
128  }
129 
130  foreach ($directory as $content) {
131  if (empty($content) || !is_string($content)) {
132  continue;
133  }
134 
135  $directories[] = trim($content);
136  }
137  $directories = array_unique($directories);
138 
139  // Sanity check to ensure no empty values
140  foreach ($directories as $key => $dir) {
141  if (empty($dir)) {
142  unset($directories[$key]);
143  }
144  }
145 
146  $this->_directory = implode(',', $directories);
147 
148  return $this;
149  }
getDirectory($asArray=false)
Definition: Exists.php:88

◆ getDirectory()

getDirectory (   $asArray = false)

Returns the set file directories which are checked

Parameters
boolean$asArrayReturns the values as array, when false an concated string is returned
Returns
string

Definition at line 88 of file Exists.php.

89  {
90  $asArray = (bool) $asArray;
91  $directory = (string) $this->_directory;
92  if ($asArray) {
93  $directory = explode(',', $directory);
94  }
95 
96  return $directory;
97  }

◆ isValid()

isValid (   $value,
  $file = null 
)

Defined by Zend_Validate_Interface

Returns true if and only if the file already exists in the set directories

Parameters
string$valueReal file to check for existance
array$fileFile data from Zend_File_Transfer
Returns
boolean

Definition at line 160 of file Exists.php.

161  {
162  $directories = $this->getDirectory(true);
163  if (($file !== null) and (!empty($file['destination']))) {
164  $directories[] = $file['destination'];
165  } else if (!isset($file['name'])) {
166  $file['name'] = $value;
167  }
168 
169  $check = false;
170  foreach ($directories as $directory) {
171  if (empty($directory)) {
172  continue;
173  }
174 
175  $check = true;
176  if (!file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) {
177  return $this->_throw($file, self::DOES_NOT_EXIST);
178  }
179  }
180 
181  if (!$check) {
182  return $this->_throw($file, self::DOES_NOT_EXIST);
183  }
184 
185  return true;
186  }
$value
Definition: gender.phtml:16
getDirectory($asArray=false)
Definition: Exists.php:88
_throw($file, $errorType)
Definition: Exists.php:195

◆ setDirectory()

setDirectory (   $directory)

Sets the file directory which will be checked

Parameters
string | array$directoryThe directories to validate
Returns
Zend_Validate_File_Extension Provides a fluent interface

Definition at line 105 of file Exists.php.

106  {
107  $this->_directory = null;
108  $this->addDirectory($directory);
109  return $this;
110  }
addDirectory($directory)
Definition: Exists.php:119

Field Documentation

◆ $_directory

$_directory = ''
protected

Definition at line 53 of file Exists.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::DOES_NOT_EXIST => "File '%value%' does not exist",
)

Definition at line 45 of file Exists.php.

◆ $_messageVariables

$_messageVariables
protected
Initial value:
= array(
'directory' => '_directory'
)

Definition at line 58 of file Exists.php.

◆ DOES_NOT_EXIST

const DOES_NOT_EXIST = 'fileExistsDoesNotExist'

@const string Error constants

Definition at line 40 of file Exists.php.


The documentation for this class was generated from the following file: