diff --git a/src/main/php/org/bovigo/vfs/Symlink.php b/src/main/php/org/bovigo/vfs/Symlink.php new file mode 100644 index 00000000..fd72d14f --- /dev/null +++ b/src/main/php/org/bovigo/vfs/Symlink.php @@ -0,0 +1,310 @@ +name = $name; + $this->target = $target; + } + + /** + * resolves the link + * + * @return \org\bovigo\vfs\vfsStreamContent + */ + public function resolve() + { + return $this->target; + } + + public function targetName() + { + return $this->target->getName(); + } + + /** + * returns the file name of the content + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * renames the content + * + * @param string $newName + */ + public function rename($newName) + { + $this->name = $newName; + } + + /** + * checks whether the container can be applied to given name + * + * @param string $name + * @return bool + */ + public function appliesTo($name) + { + if ($name === $this->name) { + return true; + } + + $segment_name = $this->name.'/'; + return (strncmp($segment_name, $name, strlen($segment_name)) == 0); + } + + /** + * returns the type of the container + * + * @return int + */ + public function getType() + { + return vfsStreamContent::TYPE_LINK; + } + + /** + * returns size of content + * + * @return int + */ + public function size() + { + return $this->target->size(); + } + + /** + * sets the last modification time of the stream content + * + * @param int $filemtime + * @return vfsStreamContent + */ + public function lastModified($filemtime) + { + $this->target->lastModified($filemtime); + return $this; + } + + /** + * returns the last modification time of the stream content + * + * @return int + */ + public function filemtime() + { + return $this->target->filemtime(); + } + + /** + * adds content to given container + * + * @param vfsStreamContainer $container + * @return vfsStreamContent + */ + public function at(vfsStreamContainer $container) + { + $container->addChild($this); + return $this; + } + + /** + * change file mode to given permissions + * + * @param int $permissions + * @return vfsStreamContent + */ + public function chmod($permissions) + { + $this->target->chmod($permissions); + return $this; + } + + /** + * returns permissions + * + * @return int + */ + public function getPermissions() + { + return $this->target->getPermissions(); + } + + /** + * checks whether content is readable + * + * @param int $user id of user to check for + * @param int $group id of group to check for + * @return bool + */ + public function isReadable($user, $group) + { + # self or target? + } + + /** + * checks whether content is writable + * + * @param int $user id of user to check for + * @param int $group id of group to check for + * @return bool + */ + public function isWritable($user, $group) + { + # self or target? + } + + /** + * checks whether content is executable + * + * @param int $user id of user to check for + * @param int $group id of group to check for + * @return bool + */ + public function isExecutable($user, $group) + { + # self or target? + } + + /** + * change owner of file to given user + * + * @param int $user + * @return vfsStreamContent + */ + public function chown($user) + { + # self or target? + } + + /** + * checks whether file is owned by given user + * + * @param int $user + * @return bool + */ + public function isOwnedByUser($user) + { + # self or target? + } + + /** + * returns owner of file + * + * @return int + */ + public function getUser() + { + # self or target? + } + + /** + * change owner group of file to given group + * + * @param int $group + * @return vfsStreamContent + */ + public function chgrp($group) + { + # self or target? + } + + /** + * checks whether file is owned by group + * + * @param int $group + * @return bool + */ + public function isOwnedByGroup($group) + { + # self or target? + } + + /** + * returns owner group of file + * + * @return int + */ + public function getGroup() + { + # self or target? + } + + /** + * sets parent path + * + * @param string $parentPath + * @internal only to be set by parent + */ + public function setParentPath($parentPath) + { + $this->parentPath = $parentPath; + } + + /** + * returns path to this content + * + * @return string + */ + public function path() + { + if (null === $this->parentPath) { + return $this->name; + } + + return $this->parentPath . '/' . $this->name; + } + + /** + * returns complete vfsStream url for this content + * + * @return string + */ + public function url() + { + return vfsStream::url($this->path()); + } +} diff --git a/src/main/php/org/bovigo/vfs/vfsStream.php b/src/main/php/org/bovigo/vfs/vfsStream.php index a41c24ff..a5004457 100644 --- a/src/main/php/org/bovigo/vfs/vfsStream.php +++ b/src/main/php/org/bovigo/vfs/vfsStream.php @@ -339,13 +339,26 @@ public static function newDirectory($name, $permissions = null) * * @param string $name name of the block device * @param int $permissions permissions of block to create - * @return vfsStreamBlock + * @return \org\bovigo\vfs\vfsStreamBlock */ public static function newBlock($name, $permissions = null) { return new vfsStreamBlock($name, $permissions); } + /** + * returns a new symbolic link with given name pointing to target + * + * @param string $name + * @param \org\bovigo\vfs\vfsStreamContent $target + * @return \org\bovigo\vfs\Symlink + * @since 1.?.0 + */ + public static function newSymlink($name, vfsStreamContent $target) + { + return new Symlink($name, $target); + } + /** * returns current user * diff --git a/src/main/php/org/bovigo/vfs/vfsStreamContent.php b/src/main/php/org/bovigo/vfs/vfsStreamContent.php index efccccec..4879daeb 100644 --- a/src/main/php/org/bovigo/vfs/vfsStreamContent.php +++ b/src/main/php/org/bovigo/vfs/vfsStreamContent.php @@ -30,8 +30,7 @@ interface vfsStreamContent * * @see getType(); */ - #const TYPE_LINK = 0120000; - + const TYPE_LINK = 0120000; /** * stream content type: block * @@ -211,4 +210,4 @@ public function path(); */ public function url(); } -?> + diff --git a/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php b/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php index c059e6ab..3dd96183 100644 --- a/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php +++ b/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php @@ -977,5 +977,20 @@ public function url_stat($path, $flags) ); return array_merge(array_values($fileStat), $fileStat); } + + public function url_readlink($path) + { + $content = $this->getContent($this->resolvePath(vfsStream::path($path))); + if (null === $content) { + trigger_error(' Does not exist: ' . $path, E_USER_WARNING); + return false; + } + + if ($content->getType() !== vfsStreamContent::TYPE_LINK) { + trigger_error(' Not a link: ' . $path, E_USER_WARNING); + return false; + } + + return $content->targetName(); + } } -?>