public function equals($other, $sameType = true) { // Make sure the types are equal if ($sameType && !(get_class() === get_class($other))) { return false; } // Convert $other into a string, return false if failed if (($other = FilesystemObjectHelper::asPath($other, false)) === null) { return false; } // Compare the paths, return the result return StringUtils::equals($this->getPath(), $other, false, true); }
/** * Validate a file instance or the path of a file. The file doesn't need to exist. * The file may not be an existing directory or symbolic link. * * @param \carbon\core\io\filesystem\FilesystemObject|string $path Filesystem object instance or the path of a file as a string. * * @return bool True if the file path seems to be valid, false otherwise. */ public static function isValid($path) { // Convert the file into a string, return the false if failed if (($path = self::asPath($path, false)) === null) { return false; } // Make sure the file is valid as FileSystemObject if (!FilesystemObjectHelper::isValid($path)) { return false; } // Make sure the file isn't a directory or symbolic link, return the result return !(FilesystemObjectHelper::isDirectory($path) || FilesystemObjectHelper::isSymbolicLink($path)); }
/** * Validate the path of the symbolic link object. The link doesn't need to exist. * The symbolic link may not be an existing file or directory. * * @param FilesystemObject|string $path Filesystem object instance or the path as a string. * * @return bool True if the path of the filesystem object seems to be valid, false otherwise. */ public static function isValid($path) { // Convert the path into a string, return false if failed if (($path = self::asPath($path, false)) === null) { return false; } // Make sure the file is valid as FileSystemObject if (!FilesystemObjectHelper::isValid($path)) { return false; } // TODO: Use better validation! // Make sure the symbolic link isn't a an existing file or directory, return the result. return !(FilesystemObjectHelper::isFile($path) || FilesystemObjectHelper::isDirectory($path)); }
public static function copy($source, $destination, $overwrite = false, $context = null) { // Convert $oldPath and $newPath into an absolute oldPath string, return false on failure if (($source = self::getAbsolutePath($source)) === null) { return false; } if (($destination = self::getAbsolutePath($destination)) === null) { return false; } // Make sure the old oldPath exists, and the new oldPath is valid if (!self::exists($source) || !self::isValid($destination)) { return false; } // Make sure the new oldPath may be overwritten if it already exists if (self::exists($destination) & !$overwrite) { return false; } // Check whether a symbolic link must be copied if (self::isSymbolicLink($source)) { // Delete the filesystem object that will be overwritten before copying the object if (FilesystemObjectHelper::exists($destination)) { if (FilesystemObjectHelper::delete($destination, true) <= 0) { return false; } } // Read the newPath of the symlink $link = SymbolicLink::asSymbolicLink($source); // Create the new symbolic link, and make sure it was made successfully return SymbolicLinkHelper::createSymbolicLink($link->getTarget(), $destination) !== null; } // Copy the object, return the result if ($context !== null) { return copy($source, $destination, $context); } return copy($source, $destination); }