public function testTypes() { $this->assertTrue(Directory::create('') instanceof Directory); $this->assertTrue(File::create('') instanceof File); $this->assertTrue(FileDescriptor::create('') instanceof FileDescriptor); $this->assertTrue(is_string(File::create('/path/to/dir')->getPathname())); $this->assertTrue(is_string(Directory::create(new Path('/path/to/dir'))->getPathname())); $this->assertTrue(is_string(FileDescriptor::create(new Text('/path/to/dir'))->getPathname())); }
/** * Creates a symlink to the given destination * * @param string|Path $destination */ public function linkTo($destination) { $target = new FileDescriptor($destination); $targetDir = new Directory($target->getDirname()); $targetDir->make(); $ok = false; if ($target->isLink()) { if (!$target->getLinkTarget()->equals($this->pathname)) { $target->delete(); } else { $ok = true; } } if (!$ok && @symlink($this->pathname, $target->getPathname()) !== true) { $report = error_get_last(); if (is_array($report) && DIRECTORY_SEPARATOR === '\\' && strpos($report['message'], 'error code(1314)') !== false) { throw new FileException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?'); } throw new FileException(sprintf('Failed to create symbolic link from %s to %s', $this->pathname, $targetDir)); } }
/** * @return FileDescriptor * @internal */ public function current() { return FileDescriptor::fromFileInfo($this->getIterator()->current()); }