Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExcludeExtension.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Validate/File/Extension.php';
26 
36 {
40  const FALSE_EXTENSION = 'fileExcludeExtensionFalse';
41  const NOT_FOUND = 'fileExcludeExtensionNotFound';
42 
46  protected $_messageTemplates = array(
47  self::FALSE_EXTENSION => "File '%value%' has a false extension",
48  self::NOT_FOUND => "File '%value%' is not readable or does not exist",
49  );
50 
61  public function isValid($value, $file = null)
62  {
63  // Is file readable ?
64  #require_once 'Zend/Loader.php';
66  return $this->_throw($file, self::NOT_FOUND);
67  }
68 
69  if ($file !== null) {
70  $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
71  } else {
72  $info = pathinfo($value);
73  }
74 
75  $extensions = $this->getExtension();
76 
77  if ($this->_case and (!in_array($info['extension'], $extensions))) {
78  return true;
79  } else if (!$this->_case) {
80  $found = false;
81  foreach ($extensions as $extension) {
82  if (strtolower($extension) == strtolower($info['extension'])) {
83  $found = true;
84  }
85  }
86 
87  if (!$found) {
88  return true;
89  }
90  }
91 
92  return $this->_throw($file, self::FALSE_EXTENSION);
93  }
94 }
static isReadable($filename)
Definition: Loader.php:162
$value
Definition: gender.phtml:16
_throw($file, $errorType)
Definition: Extension.php:228
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52