/**
  * {@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}
  * 
  * @todo the call to setMessage will override custom message if one is set
  */
 public function validate()
 {
     $path = Path::normalize($this->value);
     $test = Path::test($path, $this->bitmask);
     if ($test === true) {
         $this->value = $path;
         return true;
     } else {
         $this->setMessage($test);
         return false;
     }
 }
Exemple #3
0
 /**
  * Set the root temp directory (overrides use of the system temp directory)
  * 
  * @param string|null $path
  * @return void
  * @throws InvalidArgumentException If the provided path isn't usable
  */
 public static function setDir($path)
 {
     if ($path === null) {
         self::$dir = null;
         return;
     }
     if (!is_string($path)) {
         throw new InvalidArgumentException("invalid value provided for 'path'; " . "expecting an absolute directory path as string");
     } else {
         if (($test = Path::test($path, Dir::READABLE_WRITABLE)) !== true) {
             throw new InvalidArgumentException("invalid value provided for 'path'; {$test}");
         }
     }
     self::$dir = $path;
 }
Exemple #4
0
 /**
  * A convience method to create a filesystem iterator
  * 
  * @param string $dir An absolute path to the directory to search
  * @param integer $options A bitmask of iterator options
  * @return DirectoryIterator|RecursiveIteratorIterator
  */
 public static function getIterator($dir, $options = 0)
 {
     if (is_string($dir) === false) {
         throw new InvalidArgumentException("invalid value provided for 'dir'; " . "expecting an absolute directory path as string");
     } else {
         if (($test = Dir::isReadable($dir)) !== true) {
             throw new InvalidArgumentException("invalid value provided for 'dir'; {$test}");
         } else {
             if (!is_int($options)) {
                 throw new InvalidArgumentException("invalid value provided for 'options'; " . "expecting an integer");
             }
         }
     }
     return self::createIterator(Path::normalize($dir), $options);
 }
Exemple #5
0
 /**
  * Combine prepare, chmod, and rename into a single step
  * 
  * @param string $from An absolute path to the file before moving
  * @param string $to An absolute path to the file after moving
  * @param octal $fperm An octal to pass to chmod
  * @param octal $dperm New directory permissions
  * @return boolean|string All operations were successful
  * @return boolean:true All operations were successful
  * @return string Error message indicating which operation failed
  */
 public static function rename($from, $to, $fperm = 0664, $dperm = 0775)
 {
     if (($test = Path::test($from, self::READABLE_WRITABLE)) !== true) {
         return $test;
     } else {
         if (($test = self::prepare($to, $dperm)) !== true) {
             return $test;
         } else {
             if (@rename($from, $to) === false) {
                 return "failed to move '{$from}' to '{$to}'";
             } else {
                 if ($fperm !== null && @chmod($to, $fperm) === false) {
                     return "failed to set permissions for '{$from}' to '{$fperm}'";
                 }
             }
         }
     }
     return true;
 }
Exemple #6
0
 /**
  * Recursively remove a directory
  * 
  * @param string $dir An absolute path to a directory
  * @return boolean|string
  * @return boolean:true The directory was removed
  * @return string An error message describing the failure
  */
 public static function remove($dir)
 {
     if (($test = Path::test($dir, Dir::READABLE_WRITABLE)) !== true) {
         return "failed to remove directory '{$dir}'; {$test}";
     }
     $files = array_diff(scandir($dir), ['.', '..']);
     foreach ($files as $file) {
         $path = $dir . DIRECTORY_SEPARATOR . $file;
         $isDir = is_dir($path);
         $result = $isDir ? self::remove($path) : @unlink($path);
         if ($result !== true) {
             return $isDir ? $result : "failed to remove file '{$path}'";
         }
     }
     return @rmdir($dir) !== true ? "failed to remove directory '{$dir}'" : true;
 }