<?php
namespace Moto\Application\FileManager\Validator; use Moto\Validator\AbstractValidator; class EmptyDir extends AbstractValidator { const NOT_EXISTS = 'notExists'; const NOT_EMPTY = 'notEmpty'; protected $messageTemplates = array( self::NOT_EMPTY => "Folder is not empty", self::NOT_EXISTS => "Folder is not exists", ); public function isValid($value) { $this->setValue($value); if (is_file($value)) { return true; } if (!is_readable($value) || !is_dir($value)) { $this->error(self::NOT_EXISTS); return false; } if (count(scandir($value)) > 2) { $this->error(self::NOT_EMPTY); return false; } return true; } } 