<?php
namespace Moto\Application\FileManager\Validator; use Zend\Validator\File; class ExcludeExtension extends File\ExcludeExtension { const NOT_STRING = 'notString'; protected $messageTemplates = array( self::FALSE_EXTENSION => "File has an incorrect extension", self::NOT_STRING => "File path is not string", ); public function isValid($value) { if (!is_string($value)) { $this->error(self::NOT_STRING); return false; } $filename = basename($value); $this->setValue($filename); $extension = substr($filename, strrpos($filename, '.') + 1); $extensions = $this->getExtension(); if ($this->getCase() && (!in_array($extension, $extensions))) { return true; } elseif (!$this->getCase()) { foreach ($extensions as $ext) { if (strtolower($ext) == strtolower($extension)) { $this->error(self::FALSE_EXTENSION); return false; } } return true; } $this->error(self::FALSE_EXTENSION); return false; } } 