protected function SampleCsv::wrap in Bulk User Registration 8
A simple treatment for strings in CSV.
Since this sample CSV generator uses controlled content, we can safely assume no double quotes or comma's are present in string content. Therefore no library is needed and we can use a simple treatment for stings.
Parameters
string|string[] $source: The string to check.
Return value
string|string[] When the source string contains a space it is wrapped in double quotes.
1 call to SampleCsv::wrap()
- SampleCsv::getCsvData in src/
Controller/ SampleCsv.php - Returns the sample CSV data.
File
- src/
Controller/ SampleCsv.php, line 94
Class
- SampleCsv
- Sample CSV controller.
Namespace
Drupal\bulk_user_registration\ControllerCode
protected function wrap($source) {
$strings = is_array($source) ? $source : [
$source,
];
$result = [];
foreach ($strings as $string) {
if (strpos($string, ' ') === FALSE) {
$result[] = $string;
}
else {
$result[] = '"' . $string . '"';
}
}
return is_array($source) ? $result : reset($result);
}