datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
datatable.directory/app/Tables/PhpExporter.php

64 lines
1.3 KiB

<?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";
}
}