PHP Class Box\Spout\Writer\AbstractWriter

Inheritance: implements Box\Spout\Writer\WriterInterface
Afficher le fichier Open project: box/spout

Protected Properties

Свойство 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)

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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

Méthode 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 méthode

public __construct ( )

addRow() public méthode

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];
Résultat AbstractWriter

addRowToWriter() abstract protected méthode

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
Résultat void

addRowWithStyle() public méthode

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.
Résultat AbstractWriter

addRows() public méthode

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], ];
Résultat AbstractWriter

addRowsWithStyle() public méthode

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.
Résultat AbstractWriter

close() public méthode

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

closeWriter() abstract protected méthode

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

getDefaultRowStyle() protected méthode

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

openToBrowser() public méthode

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
Résultat AbstractWriter

openToFile() public méthode

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
Résultat AbstractWriter

openWriter() abstract protected méthode

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

setDefaultRowStyle() public méthode

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
Résultat AbstractWriter

setGlobalFunctionsHelper() public méthode

public setGlobalFunctionsHelper ( Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper ) : AbstractWriter
$globalFunctionsHelper Box\Spout\Common\Helper\GlobalFunctionsHelper
Résultat AbstractWriter

throwIfFilePointerIsNotAvailable() protected méthode

Will throw an exception if not available.
protected throwIfFilePointerIsNotAvailable ( ) : void
Résultat void

throwIfWriterAlreadyOpened() protected méthode

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

Property Details

$defaultRowStyle protected_oe property

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

$filePointer protected_oe property

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

$globalFunctionsHelper protected_oe property

Helper to work with global functions
protected $globalFunctionsHelper

$headerContentType protected_oe static_oe property

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

$isWriterOpened protected_oe property

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

$outputFilePath protected_oe property

Path to the output file
protected $outputFilePath

$rowStyle protected_oe property

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