PHP Class Box\Spout\Writer\AbstractWriter

Inheritance: implements Box\Spout\Writer\WriterInterface
Show file Open project: box/spout

Protected Properties

Property Type Description
$defaultRowStyle Default row style. Each writer can have its own default style
$filePointer Pointer to the file/stream we will write to
$globalFunctionsHelper Helper to work with global functions
$headerContentType Content-Type value for the header - to be defined by child class
$isWriterOpened Indicates whether the writer has been opened or not
$outputFilePath Path to the output file
$rowStyle Style to be applied to the next written row(s)

Public Methods

Method Description
__construct ( )
addRow ( array $dataRow ) : AbstractWriter Write given data to the output. New data will be appended to end of stream.
addRowWithStyle ( array $dataRow, Style $style ) : AbstractWriter Write given data to the output and apply the given style.
addRows ( array $dataRows ) : AbstractWriter Write given data to the output. New data will be appended to end of stream.
addRowsWithStyle ( array $dataRows, Style $style ) : AbstractWriter Write given data to the output and apply the given style.
close ( ) : void Closes the writer. This will close the streamer as well, preventing new data to be written to the file.
openToBrowser ( string $outputFileName ) : AbstractWriter Inits the writer and opens it to accept data.
openToFile ( string $outputFilePath ) : AbstractWriter Inits the writer and opens it to accept data.
setDefaultRowStyle ( Style $defaultStyle ) : AbstractWriter Sets the default styles for all rows added with "addRow".
setGlobalFunctionsHelper ( Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper ) : AbstractWriter

Protected Methods

Method Description
addRowToWriter ( array $dataRow, Style $style ) : void Adds data to the currently openned writer.
closeWriter ( ) : void Closes the streamer, preventing any additional writing.
getDefaultRowStyle ( ) : Style Returns the default style to be applied to rows.
openWriter ( ) : void Opens the streamer and makes it ready to accept data.
throwIfFilePointerIsNotAvailable ( ) : void Checks if the pointer to the file/stream to write to is available.
throwIfWriterAlreadyOpened ( string $message ) : void Checks if the writer has already been opened, since some actions must be done before it gets opened.

Private Methods

Method Description
closeAndAttemptToCleanupAllFiles ( ) : void Closes the writer and attempts to cleanup all files that were created during the writing process (temp files & final file).
resetRowStyleToDefault ( ) : void Resets the style to be applied to the next written rows.
setRowStyle ( Style $style ) : void Sets the style to be applied to the next written rows until it is changed or reset.

Method Details

__construct() public method

public __construct ( )

addRow() public method

Write given data to the output. New data will be appended to end of stream.
public addRow ( array $dataRow ) : AbstractWriter
$dataRow array Array containing data to be streamed. If empty, no data is added (i.e. not even as a blank row) Example: $dataRow = ['data1', 1234, null, '', 'data5', false];
return AbstractWriter

addRowToWriter() abstract protected method

Adds data to the currently openned writer.
abstract protected addRowToWriter ( array $dataRow, Style $style ) : void
$dataRow array Array containing data to be streamed. Example $dataRow = ['data1', 1234, null, '', 'data5'];
$style Box\Spout\Writer\Style\Style Style to be applied to the written row
return void

addRowWithStyle() public method

Write given data to the output and apply the given style.
See also: addRow
public addRowWithStyle ( array $dataRow, Style $style ) : AbstractWriter
$dataRow array Array of array containing data to be streamed.
$style Box\Spout\Writer\Style\Style Style to be applied to the row.
return AbstractWriter

addRows() public method

Write given data to the output. New data will be appended to end of stream.
public addRows ( array $dataRows ) : AbstractWriter
$dataRows array Array of array containing data to be streamed. If a row is empty, it won't be added (i.e. not even as a blank row) Example: $dataRows = [ ['data11', 12, , '', 'data13'], ['data21', 'data22', null, false], ];
return AbstractWriter

addRowsWithStyle() public method

Write given data to the output and apply the given style.
See also: addRows
public addRowsWithStyle ( array $dataRows, Style $style ) : AbstractWriter
$dataRows array Array of array containing data to be streamed.
$style Box\Spout\Writer\Style\Style Style to be applied to the rows.
return AbstractWriter

close() public method

Closes the writer. This will close the streamer as well, preventing new data to be written to the file.
public close ( ) : void
return void

closeWriter() abstract protected method

Closes the streamer, preventing any additional writing.
abstract protected closeWriter ( ) : void
return void

getDefaultRowStyle() protected method

Can be overriden by children to have a custom style.
protected getDefaultRowStyle ( ) : Style
return Box\Spout\Writer\Style\Style

openToBrowser() public method

By using this method, the data will be outputted directly to the browser.
public openToBrowser ( string $outputFileName ) : AbstractWriter
$outputFileName string Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
return AbstractWriter

openToFile() public method

By using this method, the data will be written to a file.
public openToFile ( string $outputFilePath ) : AbstractWriter
$outputFilePath string Path of the output file that will contain the data
return AbstractWriter

openWriter() abstract protected method

Opens the streamer and makes it ready to accept data.
abstract protected openWriter ( ) : void
return void

setDefaultRowStyle() public method

Overriding the default style instead of using "addRowWithStyle" improves performance by 20%.
See also: https://github.com/box/spout/issues/272
public setDefaultRowStyle ( Style $defaultStyle ) : AbstractWriter
$defaultStyle Box\Spout\Writer\Style\Style
return AbstractWriter

setGlobalFunctionsHelper() public method

public setGlobalFunctionsHelper ( Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper ) : AbstractWriter
$globalFunctionsHelper Box\Spout\Common\Helper\GlobalFunctionsHelper
return AbstractWriter

throwIfFilePointerIsNotAvailable() protected method

Will throw an exception if not available.
protected throwIfFilePointerIsNotAvailable ( ) : void
return void

throwIfWriterAlreadyOpened() protected method

Throws an exception if already opened.
protected throwIfWriterAlreadyOpened ( string $message ) : void
$message string Error message
return void

Property Details

$defaultRowStyle protected property

Default row style. Each writer can have its own default style
protected $defaultRowStyle

$filePointer protected property

Pointer to the file/stream we will write to
protected $filePointer

$globalFunctionsHelper protected property

Helper to work with global functions
protected $globalFunctionsHelper

$headerContentType protected static property

Content-Type value for the header - to be defined by child class
protected static $headerContentType

$isWriterOpened protected property

Indicates whether the writer has been opened or not
protected $isWriterOpened

$outputFilePath protected property

Path to the output file
protected $outputFilePath

$rowStyle protected property

Style to be applied to the next written row(s)
protected $rowStyle