33 public function create( array $data,
$header =
'Automatically generated' ) {
34 return self::write( $data,
$header );
47 .
"// " . implode(
"\n// ", explode(
"\n",
$header ) ) .
"\n"
49 foreach ( $data as $key => $value ) {
50 $code .= self::encodePair( $key, $value, 1 );
67 public static function writeClass( array $data, array $layout ) {
69 .
"// " . implode(
"\n// ", explode(
"\n", $layout[
'header'] ) ) .
"\n"
71 .
"namespace {$layout['namespace']};\n"
73 .
"class {$layout['class']} {\n"
74 .
"\tpublic const {$layout['const']} = [\n";
75 foreach ( $data as $key => $value ) {
76 $code .= self::encodePair( $key, $value, 2 );
92 private static function encodePair( $key, $value, $indent = 0 ) {
93 $tabs = str_repeat(
"\t", $indent );
94 $line = $tabs . var_export( $key,
true ) .
' => ';
95 $line .= self::encodeValue( $value, $indent );
111 if ( is_array( $value ) ) {
112 $tabs = str_repeat(
"\t", $indent );
114 foreach ( $value as $subkey => $subvalue ) {
115 $line .= self::encodePair( $subkey, $subvalue, $indent + 1 );
120 $exportedValue = var_export( $value,
true );
121 if ( $exportedValue ===
'NULL' ) {
124 $exportedValue =
'null';
126 return $exportedValue;