'Path "%value%" contains not allowed characters', self::ERR_CREATE => 'Failed to create directory "%value%"', self::ERR_NOT_WRITABLE => 'Directory "%value%" is not writable', self::ERR_NOT_EXISTS => 'Directory "%value%" does not exists', self::ERR_NOT_DIR => 'File "%value%" is not directory', ); public function __construct($options = null) { if ($options) { if ($options instanceof Zend_Config) { $options = $options->toArray(); } if (is_array($options)) { $this->setOptions($options); } else { throw new Exception('Wrong options format'); } } return $this; } public function setOptions(array $options) { foreach ($options as $name => $value) { $method = 'set' . ucfirst($name); if (method_exists($this, $method)) { $this->$method($value); } } return $this; } public function isValid($value) { $value = Qs_Fs::normalize($value); $this->_setValue($value); if ($value !== Qs_Fs::filterDirName($value)) { $this->_error(self::ERR_WRONG_PATH); return false; } if (!is_dir($value)) { if (file_exists($value)) { $this->_error(self::ERR_NOT_DIR); return false; } else if ($this->getForceCreate()) { umask(0); if (!mkdir($value, 0777, true)) { $this->_error(self::ERR_CREATE); return false; } } } if (is_dir($value)) { if ($this->getCheckWritable() && !is_writable($value)) { $this->_error(self::ERR_NOT_WRITABLE); return false; } } else { $this->_error(self::ERR_NOT_EXISTS); return false; } return true; } public function getCheckWritable() { return $this->_checkWritable; } public function setCheckWritable($checkWritable) { $this->_checkWritable = $checkWritable; return $this; } public function getForceCreate() { return $this->_forceCreate; } public function setForceCreate($forceCreate) { $this->_forceCreate = $forceCreate; return $this; } }