mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-11-15 20:47:15 +01:00
33 lines
909 B
PHP
33 lines
909 B
PHP
<?php
|
|
|
|
namespace Xentral\Modules\TransferSmartyTemplate\TemplateHelper;
|
|
|
|
use Xentral\Modules\TransferSmartyTemplate\Exception\InvalidArgumentException;
|
|
|
|
final class CsvHelper
|
|
{
|
|
/**
|
|
* Quotes and escapes an CSV value
|
|
*
|
|
* @param string $string
|
|
* @param string $enclosure
|
|
*
|
|
* @throws InvalidArgumentException
|
|
*
|
|
* @return string
|
|
*/
|
|
public function quoteCsv($string, $enclosure = '"')
|
|
{
|
|
if (!is_string($enclosure)) {
|
|
throw new InvalidArgumentException('Invalid argument. Enclosure need to be type string.');
|
|
}
|
|
if (strlen($enclosure) !== 1) {
|
|
throw new InvalidArgumentException('Invalid argument. Enclosure can only be a single character.');
|
|
}
|
|
|
|
$escapedString = (string)str_replace($enclosure, $enclosure . $enclosure, $string);
|
|
|
|
return $enclosure . $escapedString . $enclosure;
|
|
}
|
|
}
|