Represents a file in the filesystem.
More...
Represents a file in the filesystem.
- Warning
- Be sure to distinguish between get() and write() versus read() and put(), the former operates on the entire file, while the latter operates on a handle.
Definition at line 10 of file File.php.
◆ __construct()
FSTools_File::__construct |
( |
|
$name, |
|
|
|
$fs = false |
|
) |
| |
◆ __destruct()
FSTools_File::__destruct |
( |
| ) |
|
◆ chmod()
FSTools_File::chmod |
( |
|
$octal_code | ) |
|
Chmod a file.
- Note
- We ignore errors because of some weird owner trickery due to SVN duality
Definition at line 76 of file File.php.
77 {
78 return @$this->fs->chmod($this->name, $octal_code);
79 }
◆ close()
Closes file's handle.
Definition at line 90 of file File.php.
91 {
92 if (!$this->handle) return false;
93 $status = $this->fs->fclose($this->handle);
94 $this->handle = false;
95 return $status;
96 }
Referenced by __destruct(), and open().
◆ delete()
Deletes the file.
Definition at line 54 of file File.php.
55 {
56 return $this->fs->unlink($this->name);
57 }
◆ eof()
Returns TRUE if the end of the file has been reached.
Definition at line 128 of file File.php.
129 {
130 if (!$this->handle) return true;
131 return $this->fs->feof($this->handle);
132 }
◆ exists()
Returns true if file exists and is a file.
Definition at line 60 of file File.php.
61 {
62 return $this->fs->is_file($this->name);
63 }
◆ get()
Retrieves the contents of a file.
- Todo:
- Throw an exception if file doesn't exist
Definition at line 42 of file File.php.
43 {
44 return $this->fs->file_get_contents($this->name);
45 }
◆ getChar()
FSTools_File::getChar |
( |
| ) |
|
Retrieves a character from an open file.
Definition at line 107 of file File.php.
108 {
109 if (!$this->handle) $this->
open(
'r');
110 return $this->fs->fgetc($this->handle);
111 }
References open().
◆ getDirectory()
FSTools_File::getDirectory |
( |
| ) |
|
Returns directory of the file without trailing slash.
Definition at line 36 of file File.php.
36{return $this->fs->dirname($this->name);}
◆ getLine()
FSTools_File::getLine |
( |
|
$length = null | ) |
|
Retrieves a line from an open file, with optional max length $length.
Definition at line 99 of file File.php.
100 {
101 if (!$this->handle) $this->
open(
'r');
102 if ($length === null) return $this->fs->fgets($this->handle);
103 else return $this->fs->fgets($this->handle, $length);
104 }
References open().
◆ getMTime()
FSTools_File::getMTime |
( |
| ) |
|
Returns last file modification time.
Definition at line 66 of file File.php.
67 {
68 return $this->fs->filemtime($this->name);
69 }
◆ getName()
FSTools_File::getName |
( |
| ) |
|
Returns the filename of the file.
Definition at line 33 of file File.php.
References $name.
◆ open()
FSTools_File::open |
( |
|
$mode | ) |
|
Opens file's handle.
Definition at line 82 of file File.php.
83 {
84 if ($this->handle) $this->
close();
85 $this->handle = $this->fs->fopen($this->name, $mode);
86 return true;
87 }
References close().
Referenced by getChar(), getLine(), put(), and read().
◆ put()
FSTools_File::put |
( |
|
$string | ) |
|
Writes to an open file.
Definition at line 121 of file File.php.
122 {
123 if (!$this->handle) $this->
open(
'a');
124 return $this->fs->fwrite($this->handle, $string);
125 }
References open().
◆ read()
FSTools_File::read |
( |
|
$length | ) |
|
Retrieves an $length bytes of data from an open data.
Definition at line 114 of file File.php.
115 {
116 if (!$this->handle) $this->
open(
'r');
117 return $this->fs->fread($this->handle, $length);
118 }
References open().
◆ write()
FSTools_File::write |
( |
|
$contents | ) |
|
Writes contents to a file, creates new file if necessary.
Definition at line 48 of file File.php.
49 {
50 return $this->fs->file_put_contents($this->name,
$contents);
51 }
References $contents.
◆ $fs
◆ $handle
FSTools_File::$handle = false |
|
protected |
Handle for the file.
Definition at line 17 of file File.php.
◆ $name
The documentation for this class was generated from the following file:
- libs/composer/vendor/ezyang/htmlpurifier/extras/FSTools/File.php