class StringBasedFileContent in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/content/StringBasedFileContent.php \org\bovigo\vfs\content\StringBasedFileContent
Default implementation for file contents based on simple strings.
@since 1.3.0
Hierarchy
- class \org\bovigo\vfs\content\SeekableFileContent implements FileContent
- class \org\bovigo\vfs\content\StringBasedFileContent implements 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 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("\0", $size - $this
->size());
}
else {
$this->content = substr($this->content, 0, $size);
}
return true;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SeekableFileContent:: |
private | property | current position within content | |
SeekableFileContent:: |
public | function | for backwards compatibility with vfsStreamFile::bytesRead() | |
SeekableFileContent:: |
public | function |
checks whether pointer is at end of file Overrides FileContent:: |
|
SeekableFileContent:: |
public | function |
reads the given amount of bytes from content Overrides FileContent:: |
|
SeekableFileContent:: |
public | function | for backwards compatibility with vfsStreamFile::readUntilEnd() | |
SeekableFileContent:: |
public | function |
seeks to the given offset Overrides FileContent:: |
|
SeekableFileContent:: |
public | function |
writes an amount of data Overrides FileContent:: |
|
StringBasedFileContent:: |
private | property | actual content | |
StringBasedFileContent:: |
public | function |
returns actual content Overrides FileContent:: |
|
StringBasedFileContent:: |
protected | function |
actual reading of length starting at given offset Overrides SeekableFileContent:: |
|
StringBasedFileContent:: |
protected | function |
actual writing of data with specified length at given offset Overrides SeekableFileContent:: |
|
StringBasedFileContent:: |
public | function |
returns size of content Overrides FileContent:: |
|
StringBasedFileContent:: |
public | function |
Truncates a file to a given length Overrides FileContent:: |
|
StringBasedFileContent:: |
public | function | constructor |