class StringBasedFileContent
Default implementation for file contents based on simple strings.
@since 1.3.0
Hierarchy
- class \org\bovigo\vfs\content\SeekableFileContent implements \org\bovigo\vfs\content\FileContent
- class \org\bovigo\vfs\content\StringBasedFileContent extends \org\bovigo\vfs\content\SeekableFileContent implements \org\bovigo\vfs\content\FileContent
Expanded class hierarchy of StringBasedFileContent
1 file declares its use of StringBasedFileContent
- vfsStreamFile.php in vendor/
mikey179/ vfsstream/ src/ main/ php/ org/ bovigo/ vfs/ vfsStreamFile.php
File
-
vendor/
mikey179/ vfsstream/ src/ main/ php/ org/ bovigo/ vfs/ content/ StringBasedFileContent.php, line 16
Namespace
org\bovigo\vfs\contentView source
class StringBasedFileContent extends SeekableFileContent implements FileContent {
/**
* actual content
*
* @type string
*/
private $content;
/**
* constructor
*
* @param string $content
*/
public function __construct($content) {
$this->content = $content;
}
/**
* returns actual content
*
* @return string
*/
public function content() {
return $this->content;
}
/**
* returns size of content
*
* @return int
*/
public function size() {
return strlen($this->content);
}
/**
* actual reading of length starting at given offset
*
* @param int $offset
* @param int $count
*/
protected function doRead($offset, $count) {
return (string) substr($this->content, $offset, $count);
}
/**
* actual writing of data with specified length at given offset
*
* @param string $data
* @param int $offset
* @param int $length
*/
protected function doWrite($data, $offset, $length) {
$this->content = substr($this->content, 0, $offset) . $data . substr($this->content, $offset + $length);
}
/**
* Truncates a file to a given length
*
* @param int $size length to truncate file to
* @return bool
*/
public function truncate($size) {
if ($size > $this->size()) {
// Pad with null-chars if we're "truncating up"
$this->content .= str_repeat("\x00", $size - $this->size());
}
else {
$this->content = substr($this->content, 0, $size);
}
return true;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
SeekableFileContent::$offset | private | property | current position within content | |
SeekableFileContent::bytesRead | public | function | for backwards compatibility with vfsStreamFile::bytesRead() | |
SeekableFileContent::eof | public | function | checks whether pointer is at end of file | Overrides FileContent::eof |
SeekableFileContent::read | public | function | reads the given amount of bytes from content | Overrides FileContent::read |
SeekableFileContent::readUntilEnd | public | function | for backwards compatibility with vfsStreamFile::readUntilEnd() | |
SeekableFileContent::seek | public | function | seeks to the given offset | Overrides FileContent::seek |
SeekableFileContent::write | public | function | writes an amount of data | Overrides FileContent::write |
StringBasedFileContent::$content | private | property | actual content | |
StringBasedFileContent::content | public | function | returns actual content | Overrides FileContent::content |
StringBasedFileContent::doRead | protected | function | actual reading of length starting at given offset | Overrides SeekableFileContent::doRead |
StringBasedFileContent::doWrite | protected | function | actual writing of data with specified length at given offset | Overrides SeekableFileContent::doWrite |
StringBasedFileContent::size | public | function | returns size of content | Overrides FileContent::size |
StringBasedFileContent::truncate | public | function | Truncates a file to a given length | Overrides FileContent::truncate |
StringBasedFileContent::__construct | public | function | constructor |