Controls
A trait to configure and check CSV file and content
Tags
Table of Contents
- $delimiter : string
- the field delimiter (one character only)
- $enclosure : string
- the field enclosure character (one character only)
- $escape : string
- the field escape character (one character only)
- $newline : string
- newline character
- fetchDelimitersOccurrence() : array<string|int, mixed>
- Detect Delimiters occurences in the CSV
- getDelimiter() : string
- Returns the current field delimiter
- getEnclosure() : string
- Returns the current field enclosure
- getEscape() : string
- Returns the current field escape character
- getIterator() : SplFileObject
- Returns the CSV Iterator
- getNewline() : string
- Returns the current newline sequence characters
- setDelimiter() : $this
- Sets the field delimiter
- setEnclosure() : $this
- Sets the field enclosure
- setEscape() : $this
- Sets the field escape character
- setNewline() : static
- Sets the newline sequence characters
- isValidCsvControls() : bool
- Tell whether the submitted string is a valid CSV Control character
- validateInteger() : int
- Validate an integer
Properties
$delimiter
the field delimiter (one character only)
protected
string
$delimiter
= ','
$enclosure
the field enclosure character (one character only)
protected
string
$enclosure
= '"'
$escape
the field escape character (one character only)
protected
string
$escape
= '\'
$newline
newline character
protected
string
$newline
= "
"
Methods
fetchDelimitersOccurrence()
Detect Delimiters occurences in the CSV
public
fetchDelimitersOccurrence(array<string|int, string> $delimiters[, int $nb_rows = 1 ]) : array<string|int, mixed>
Returns a associative array where each key represents a valid delimiter and each value the number of occurences
Parameters
- $delimiters : array<string|int, string>
-
the delimiters to consider
- $nb_rows : int = 1
-
Detection is made using $nb_rows of the CSV
Return values
array<string|int, mixed> —getDelimiter()
Returns the current field delimiter
public
getDelimiter() : string
Return values
string —getEnclosure()
Returns the current field enclosure
public
getEnclosure() : string
Return values
string —getEscape()
Returns the current field escape character
public
getEscape() : string
Return values
string —getIterator()
Returns the CSV Iterator
public
abstract getIterator() : SplFileObject
Return values
SplFileObject —getNewline()
Returns the current newline sequence characters
public
getNewline() : string
Return values
string —setDelimiter()
Sets the field delimiter
public
setDelimiter(string $delimiter) : $this
Parameters
- $delimiter : string
Tags
Return values
$this —setEnclosure()
Sets the field enclosure
public
setEnclosure(string $enclosure) : $this
Parameters
- $enclosure : string
Tags
Return values
$this —setEscape()
Sets the field escape character
public
setEscape(string $escape) : $this
Parameters
- $escape : string
Tags
Return values
$this —setNewline()
Sets the newline sequence characters
public
setNewline(string $newline) : static
Parameters
- $newline : string
Return values
static —isValidCsvControls()
Tell whether the submitted string is a valid CSV Control character
protected
isValidCsvControls(string $str) : bool
Parameters
- $str : string
-
The submitted string
Return values
bool —validateInteger()
Validate an integer
protected
validateInteger(int $int, int $minValue, string $errorMessage) : int
Parameters
- $int : int
- $minValue : int
- $errorMessage : string