Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/MLD/Console/Command/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ExportCommand extends Command
'csv' => ['class' => '\MLD\Converter\CsvConverter', 'output_file' => 'countries.csv'],
'xml' => ['class' => '\MLD\Converter\XmlConverter', 'output_file' => 'countries.xml'],
'yml' => ['class' => '\MLD\Converter\YamlConverter', 'output_file' => 'countries.yml'],
'php' => ['class' => '\MLD\Converter\PHPConverter', 'output_file' => 'countries.php']
];

/**
Expand Down
40 changes: 40 additions & 0 deletions src/MLD/Converter/PHPConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace MLD\Converter;

/**
* Class CsvConverter
*/
class PHPConverter extends AbstractConverter
{

/**
* @var string
*/
private $prefix = "<?php\nreturn [";

/**
* @var string
*/
private $suffix = '];';

/**
* @var array
*/
private $bodyChunks = [];

/**
* @return string data converted into CSV
*/
public function convert()
{
array_walk($this->countries, [$this, 'processCountry']);
return $this->prefix . "\n" . implode(",\n",$this->bodyChunks) . "\n" . $this->suffix;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the var_export function which produces a parsable string representation of a variable, that is what you want here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimitar-kunchev what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot about that PR. Yes, var_export should do the trick.

}

private function processCountry(&$array)
{
$this->bodyChunks[] =
"'".$array['cca2'] ."' => " . var_export($array, true);
}
}