new export options
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Tables;
|
||||
|
||||
|
||||
class PhpExporter extends BaseExporter
|
||||
{
|
||||
/**
|
||||
* @return string - mime type for the downloaded file
|
||||
*/
|
||||
protected function getMimeType()
|
||||
{
|
||||
return $this->wantDownload ? 'application/x-php' : 'text/plain';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string - file extension for the downloaded file
|
||||
*/
|
||||
protected function getFileExtension()
|
||||
{
|
||||
return 'php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the document to stdout ('php://output')
|
||||
*/
|
||||
protected function writeDocument()
|
||||
{
|
||||
echo "<?php\n\n";
|
||||
|
||||
echo "/*\n" . $this->getHeaderComment(' ') . "*/\n\n";
|
||||
|
||||
echo "return [\n";
|
||||
|
||||
$first = true;
|
||||
foreach ($this->iterateRows() as $row) {
|
||||
if ($first) {
|
||||
$first = false;
|
||||
} else {
|
||||
echo ",\n";
|
||||
}
|
||||
|
||||
echo ' [';
|
||||
|
||||
$firstf = true;
|
||||
foreach ($this->columns as $column) {
|
||||
if ($firstf) {
|
||||
$firstf = false;
|
||||
} else {
|
||||
echo ", ";
|
||||
}
|
||||
|
||||
var_export($column->name);
|
||||
echo ' => ';
|
||||
var_export($row->{$column->name});
|
||||
}
|
||||
|
||||
echo ']';
|
||||
}
|
||||
|
||||
echo "\n];\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user