42 if (!isset($this->config[
'filename'], $this->config[
'count'])) {
43 throw new \InvalidArgumentException(
44 'Configuration for file is bad. You must specify "filename" and "count" in configuration.' 50 if (!file_exists($filename)) {
51 throw new \Exception(
'File "' . $filename .
'" does not exist.');
54 $fh =
fopen(
'php://temp',
'rw');
55 $fh = $this->addEntitiesData($fh);
57 $this->csv = stream_get_contents($fh);
71 basename($this->config[
'filename'])
81 private function addEntitiesData($stream)
84 $entitiesData = include $filename;
87 if (!empty($this->config[
'placeholders'])) {
88 $placeholders = $this->config[
'placeholders'];
91 fputcsv($stream, array_keys($entitiesData[
'entity_0'][
'data_0']));
92 foreach ($placeholders as $entityKey => $entityData) {
93 foreach ($entityData as $dataKey => $dataValue) {
95 function (
$value) use ($placeholders, $entityKey, $dataKey, $dataValue) {
96 if (is_string(
$value) && isset($placeholders[$entityKey][$dataKey])) {
97 return strtr(
$value, $dataValue);
101 $entitiesData[$entityKey][$dataKey]
103 fputcsv($stream,
$row);
__construct(array $config)