Beispiel #1
0
 /**
  * Determine if a file path can be written to
  * 
  * NOTE: if the path does not exist, the parent directories will be analyzed
  * @param string $path An absolute path to the file to test
  * @return boolean:true The file is writable
  * @return string An error message indicating why the path test failed
  */
 public static function isWritable($path)
 {
     # if the file doesn't exist, ensure its parent dir is writable
     if (!file_exists($path)) {
         return Dir::isWritable(dirname($path));
     }
     return Path::test($path, self::WRITABLE);
 }
 /**
  * {@inheritdoc}
  */
 public function validate()
 {
     $path = Path::normalize($this->value);
     $test = $this->isDir === true ? Dir::isWritable($path) : File::isWritable($path);
     if ($test === true) {
         $this->value = $path;
         return true;
     }
     $this->message = $test;
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function validate()
 {
     if (($test = Dir::isWritable($this->value)) !== true) {
         $this->message = $test;
         return false;
     } else {
         if (file_exists($this->value) && $this->mustBeEmpty === true && count(scandir($this->value)) !== 2) {
             $this->message = "'{$this->value}' must be an empty directory";
             return false;
         }
     }
     return true;
 }