public function testSet() { $file = new File(uniqid('.test_')); $this->assertFalse($file->exists()); $file->createNewFile(); $this->assertTrue($file->exists()); $this->assertTrue($file->isReadable()); $this->assertTrue($file->isWritable()); $this->assertFalse($file->isExecutable()); $file->setReadable(true); $file->setWritable(true); $file->setExecutable(true); // var_dump($file->isReadable()); // var_dump($file->isWritable()); // var_dump($file->isExecutable()); }
public static function createFmpFile(string $prefix = null, string $suffix = null, File $directory = null) { $directory = $directory ?: new File(sys_get_temp_dir()); $directory = $directory->getPath(); $suffix = (string) ($suffix ?: 'tmp'); $prefix = (string) ($prefix ?: uniqid('tmp_file')); $name = tempnam($directory, $prefix); $name = sprintf("%s.%s", $name, $suffix); $file = new File($name); $file->createNewFile(); return $file; }
/** * Compute the hash code of an abstract pathname. * @param File $f * @return int */ public function hashCodeFile(File $f) { return (new String($f->getPath()))->hashCode() ^ 1234321; }
/** * Compare two pathnames lexicographically. * @param File $f1 * @param File $f2 * @return int */ public function compare(File $f1, File $f2) { return $f1->getAbsolutePath()->compareTo($f2->getAbsolutePath()); }