1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
<?php
class Core_File_ReadWrite extends Core_File_Read implements Core_Stream_IO {
/**
* Class constructor.
*
* @access public
* @param string $fileName
* @param string $mode
* @param string $context
*/
public function __construct ($fileName, $mode = self::MODE_READ_WRITE, $context = null) {
parent::__construct($fileName, $mode, $context);
}
/**
* Ecrit n caractères dans le flux
*
* @access public
* @param string $string
* @param int $length
* @return mixed
*/
public function write ($string, $length = null) {
$length = ($length !== null) ? $length : strlen($string);
return fwrite($this->getStream(), $string, $length);
}
/**
* Ecrit une ligne dans le flux
*
* @access public
* @param string $line
* @return mixed
*/
public function writeLine ($line) {
if ( false === ($n = strpos($line, "\n")) )
return $this->write($line . "\n");
return $this->write( substr($line, 0, $n) . "\n" );
}
/**
* Vide le flux et réécrit par dessus les données précédantes
*
* @access public
* @param string $string
* @return mixed
*/
public function writeAll ($string) {
$this->seek(0, self::SEEK_SET);
return $this->write($string, strlen($string));
}
/**
* Tronque un le flux
*
* @access public
* @param string $size
* @return bool
*/
public function truncate($size) {
return ftruncate($this->getStream(), $size);
} |
Partager