Class luya\yii\helpers\XLSXWriter_BuffererWriter

Inheritanceluya\yii\helpers\XLSXWriter_BuffererWriter
Source Code https://github.com/luyadev/yii-helpers/blob/master/src/helpers/XLSXWriter_BuffererWriter.php

Property Details

Hide inherited properties

$buffer protected property
protected $buffer ''
$check_utf8 protected property
protected $check_utf8 false
$fd protected property
protected $fd null

Method Details

Hide inherited methods

__construct() public method

public void __construct ( $filename, $fd_fopen_flags 'w', $check_utf8 false )
$filename
$fd_fopen_flags
$check_utf8

                public function __construct($filename, $fd_fopen_flags = 'w', $check_utf8 = false)
{
    $this->check_utf8 = $check_utf8;
    $this->fd = fopen($filename, $fd_fopen_flags);
    if ($this->fd === false) {
        XLSXWriter::log("Unable to open $filename for writing.");
    }
}

            
__destruct() public method

public void __destruct ( )

                public function __destruct()
{
    $this->close();
}

            
close() public method

public void close ( )

                public function close()
{
    $this->purge();
    if ($this->fd) {
        fclose($this->fd);
        $this->fd = null;
    }
}

            
fseek() public method

public void fseek ( $pos )
$pos

                public function fseek($pos)
{
    if ($this->fd) {
        $this->purge();
        return fseek($this->fd, $pos);
    }
    return -1;
}

            
ftell() public method

public void ftell ( )

                public function ftell()
{
    if ($this->fd) {
        $this->purge();
        return ftell($this->fd);
    }
    return -1;
}

            
isValidUTF8() protected static method

protected static void isValidUTF8 ( $string )
$string

                protected static function isValidUTF8($string)
{
    if (function_exists('mb_check_encoding')) {
        return mb_check_encoding($string, 'UTF-8') ? true : false;
    }
    return preg_match("//u", $string) ? true : false;
}

            
purge() protected method

protected void purge ( )

                protected function purge()
{
    if ($this->fd) {
        if ($this->check_utf8 && !self::isValidUTF8($this->buffer)) {
            XLSXWriter::log("Error, invalid UTF8 encoding detected.");
            $this->check_utf8 = false;
        }
        fwrite($this->fd, $this->buffer);
        $this->buffer = '';
    }
}

            
write() public method

public void write ( $string )
$string

                public function write($string)
{
    $this->buffer .= $string;
    if (isset($this->buffer[8191])) {
        $this->purge();
    }
}