Skip to content

Instantly share code, notes, and snippets.

@vadviktor
Forked from mca-gif/PHP Array.php.js
Created July 25, 2017 17:12
Show Gist options
  • Save vadviktor/7a22fc7999e5d57018ad1f01679cdeee to your computer and use it in GitHub Desktop.
Save vadviktor/7a22fc7999e5d57018ad1f01679cdeee to your computer and use it in GitHub Desktop.
PHP Array Data Extractor for the IntelliJ IDEA Platform
function eachWithIdx(iterable, f) { var i = iterable.iterator(); var idx = 0; while (i.hasNext()) f(i.next(), idx++); }
function mapEach(iterable, f) { var vs = []; eachWithIdx(iterable, function (i) { vs.push(f(i));}); return vs; }
function escape(str) {
str = com.intellij.openapi.util.text.StringUtil.escapeXml(str);
return str;
}
function quote(str) {
return '"' + str + '"';
}
var NEWLINE = "\n";
function output() { for (var i = 0; i < arguments.length; i++) { OUT.append(arguments[i]); } }
function outputRow(items) {
output("\tarray(", NEWLINE);
for (var i = 0; i < items.length; i++) {
if ( i > 0 ) { output(',', NEWLINE); }
output('\t\t', quote(items[i][0]), ' => ', quote(items[i][1]));
}
output(NEWLINE, "\t)");
}
output("<?php", NEWLINE,
"$exported_data = array(", NEWLINE);
eachWithIdx(ROWS, function (row, idx) {
if ( idx > 0 ) { output(',', NEWLINE); }
outputRow(mapEach(COLUMNS, function (col) { return [col.name(), FORMATTER.format(row, col)]; }))
});
output(NEWLINE, ")", NEWLINE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment