Source for file SafeStream.php
Documentation is available at SafeStream.php
- 1: <?php
- 3: /**
- 4: * Nette Framework
- 5: *
- 11: */
- 15: /**
- 16: * Thread safe / atomic file manipulation. Stream safe://
- 17: *
- 18: * <code>
- 19: * file_put_contents('safe://myfile.txt', $content);
- 20: *
- 21: * $content = file_get_contents('safe://myfile.txt');
- 22: *
- 23: * unlink('safe://myfile.txt');
- 24: * </code>
- 25: *
- 26: *
- 29: */
- 31: {
- 32: /**
- 33: * Name of stream protocol - safe://
- 34: */
- 37: /**
- 38: * Current file handle.
- 39: */
- 42: /**
- 43: * Renaming of temporary file.
- 44: */
- 48: /**
- 49: * Starting position in file (for appending).
- 50: */
- 53: /**
- 54: * Write-error detected?
- 55: */
- 60: /**
- 61: * Registers protocol 'safe://'.
- 62: *
- 64: */
- 66: {
- 68: }
- 72: /**
- 73: * Opens file.
- 74: *
- 80: */
- 82: {
- 94: // enter critical section: open and lock EXISTING file for reading/writing
- 100: }
- 108: // try enter critical section: open and lock EXISTING file for rewriting
- 118: }
- 121: }
- 123: }
- 124: // file doesn't exists, continue...
- 131: // create temporary file in the same directory
- 134: // enter critical section: create temporary file
- 140: // rename later - for windows
- 143: }
- 145: }
- 148: }
- 151: default:
- 160: /**
- 161: * Closes file.
- 162: *
- 164: */
- 166: {
- 169: }
- 173: // are we working with temporary file?
- 175: // try to rename temp file, otherwise delete temp file
- 178: }
- 179: }
- 180: }
- 184: /**
- 185: * Reads up to length bytes from the file.
- 186: *
- 189: */
- 191: {
- 193: }
- 197: /**
- 198: * Writes the string to the file.
- 199: *
- 202: */
- 204: {
- 210: }
- 213: }
- 217: /**
- 218: * Returns the position of the file.
- 219: *
- 221: */
- 223: {
- 225: }
- 229: /**
- 230: * Returns TRUE if the file pointer is at end-of-file.
- 231: *
- 233: */
- 235: {
- 237: }
- 241: /**
- 242: * Sets the file position indicator for the file.
- 243: *
- 247: */
- 249: {
- 251: }
- 255: /**
- 256: * Gets information about a file referenced by $this->handle.
- 257: *
- 259: */
- 261: {
- 263: }
- 267: /**
- 268: * Gets information about a file referenced by filename.
- 269: *
- 273: */
- 275: {
- 276: // This is not thread safe
- 279: }
- 283: /**
- 284: * Deletes a file.
- 285: * On Windows unlink is not allowed till file is opened
- 286: *
- 289: */
- 291: {
- 294: }
- 296: }