Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user