neuralnet.php/build/filemanager/core/FileManager.php

84 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace filemanager\core;
class FileManager{
/* READS FILE'S CONTENT
*
* @file<String> File to read
*
*/
public static function read($file){
/* [1] Init driver
=========================================================*/
$driver = new \SplFileObject($file, 'r');
/* [2] Read lines
=========================================================*/
$read = '';
/* (1) Reads lines */
$line = 0;
while( $driver->current() ){
$read .= "\n".$driver->current();
$driver->next();
}
/* [3] Returns read content
=========================================================*/
/* (2) Destroy driver */
$driver = null;
/* (3) Returns result */
return $read;
}
/* WRITES CONTENT TO A FILE
*
* @file<String> File to write to
* @content<String> Content to write
*
*/
public static function write($file, $content){
/* (1) Erase file */
file_put_contents($file, '');
/* (2) Get driver (write-flag) */
$driver = new \SplFileObject($file, 'r+');
/* (3) Writes content */
$driver->fwrite($content);
/* (4) Free driver */
$driver = null;
}
/* APPENDS CONTENT TO A FILE
*
* @file<String> File to append content to
* @content<String> Content to append
*
*/
public static function append($file, $content){
/* (1) Get driver (append-flag) */
$driver = new \SplFileObject($file, 'a');
/* (2) append content */
$driver->fwrite($content.PHP_EOL);
/* (3) Free driver */
$driver = null;
}
}
?>