1: <?php
2: 3: 4: 5: 6:
7:
8: namespace Peg\Lib\Definitions;
9:
10: use Peg\Lib\Utilities\Json;
11: use Peg\Lib\Utilities\FileSystem;
12:
13: 14: 15:
16: class Exporter extends \Peg\Lib\Signals\Signal
17: {
18: 19: 20: 21:
22: public $symbols;
23:
24: 25: 26: 27:
28: public $definitions_path;
29:
30: 31: 32: 33: 34:
35: public $export_type;
36:
37: 38: 39: 40:
41: private $signal_data;
42:
43: 44: 45: 46: 47: 48:
49: public function __construct(
50: \Peg\Lib\Definitions\Symbols &$symbols,
51: $path = null,
52: $export_type=\Peg\Lib\Definitions\Type::JSON
53: )
54: {
55: $this->symbols =& $symbols;
56: $this->definitions_path = $path;
57: $this->export_type = $export_type;
58: $this->signal_data = new \Peg\Lib\Signals\Data\Definitions\ExportMessage;
59: }
60:
61: 62: 63:
64: public function Start()
65: {
66: if(!$this->definitions_path)
67: {
68: throw new \Exception(
69: t("Your are trying to export definitions without setting a path first.")
70: );
71: }
72: elseif(!file_exists($this->definitions_path))
73: {
74: FileSystem::MakeDir(
75: $this->definitions_path,
76: 0755,
77: true
78: );
79: }
80:
81: $this->definitions_path = rtrim($this->definitions_path, "\\/") . "/";
82:
83: $this->SendMessage(
84: sprintf(
85: t("Starting export of definitions to %s format."),
86: $this->export_type
87: )
88: );
89:
90: if($this->export_type == Type::JSON)
91: {
92: $this->SaveToJSON($this->definitions_path);
93: }
94: else
95: {
96: $this->SaveToPHP($this->definitions_path);
97: }
98:
99: $this->SendMessage(t("Export completed."));
100: }
101:
102: 103: 104: 105:
106: private function SaveToPHP($path)
107: {
108: $this->definitions_path = rtrim($path, "/\\") . "/";
109: $this->export_type = Type::PHP;
110:
111: $this->SendMessage(t("Creating constants.php"));
112: $this->SaveConstantsToPHP();
113:
114: $this->SendMessage(t("Creating enumerations.php"));
115: $this->SaveEnumerationsToPHP();
116:
117: $this->SendMessage(t("Creating type_definitions.php"));
118: $this->SaveTypeDefToPHP();
119:
120: $this->SendMessage(t("Creating variables.php"));
121: $this->SaveGloablVariablesToPHP();
122:
123: $this->SendMessage(t("Creating functions.php"));
124: $this->SaveFunctionsToPHP();
125:
126: $this->SendMessage(t("Creating classes.php"));
127: $this->SaveClassesToPHP();
128: }
129:
130: 131: 132:
133: private function SaveConstantsToPHP()
134: {
135: $output_file = fopen(
136: $this->definitions_path . "constants.php",
137: "w"
138: );
139:
140: fwrite($output_file, "<?php\n\n");
141:
142: fwrite($output_file, "use Peg\Lib\Definitions\Element\Constant;\n");
143:
144: foreach($this->symbols->headers as $header)
145: {
146: if(!$header->HasConstants())
147: continue;
148:
149: foreach($header->namespaces as $namespace)
150: {
151: if(!$namespace->HasConstants())
152: continue;
153:
154: foreach($namespace->constants as $constant)
155: {
156: $value = addslashes($constant->value);
157: $description = addslashes($constant->description);
158: $namespace_name = addslashes($namespace->name);
159:
160: $output = "\n";
161: $output .= '$symbols->AddConstant(' . "\n";
162: $output .= ' new Constant(' . "\n";
163: $output .= ' "'.$constant->name.'",' . "\n";
164: $output .= ' "'.$value.'",' . "\n";
165: $output .= ' "'.$description.'"' . "\n";
166: $output .= ' ),' . "\n";
167: $output .= ' "'.$header->name.'",' . "\n";
168: $output .= ' "'.$namespace_name.'"' . "\n";
169: $output .= ');' . "\n";
170:
171: fwrite($output_file, $output);
172: }
173: }
174: }
175:
176: fclose($output_file);
177: }
178:
179: 180: 181:
182: private function SaveEnumerationsToPHP()
183: {
184: $output_file = fopen(
185: $this->definitions_path . "enumerations.php",
186: "w"
187: );
188:
189: fwrite($output_file, "<?php\n\n");
190:
191: fwrite($output_file, "use Peg\Lib\Definitions\Element\Enumeration;\n");
192:
193: foreach($this->symbols->headers as $header)
194: {
195: if(!$header->HasEnumerations())
196: continue;
197:
198: foreach($header->namespaces as $namespace)
199: {
200: if(!$namespace->HasEnumerations())
201: continue;
202:
203: foreach($namespace->enumerations as $enumeration)
204: {
205: $description = addslashes($enumeration->description);
206: $namespace_name = addslashes($namespace->name);
207:
208: $output = "\n";
209: $output .= '$symbols->AddEnumeration(' . "\n";
210: $output .= ' new Enumeration(' . "\n";
211: $output .= ' "'.$enumeration->name.'",' . "\n";
212:
213: $output .= ' [' . "\n";
214: foreach($enumeration->options as $option)
215: {
216: $output .= ' "'.$option.'",' . "\n";
217: }
218: $output = rtrim($output, ",\n") . "\n";
219: $output .= ' ],' . "\n";
220:
221: $output .= ' "'.$description.'"' . "\n";
222: $output .= ' ),' . "\n";
223: $output .= ' "'.$header->name.'",' . "\n";
224: $output .= ' "'.$namespace_name.'"' . "\n";
225: $output .= ');' . "\n";
226:
227: fwrite($output_file, $output);
228: }
229: }
230: }
231:
232: fclose($output_file);
233: }
234:
235: 236: 237:
238: private function SaveTypeDefToPHP()
239: {
240: $output_file = fopen(
241: $this->definitions_path . "type_definitions.php",
242: "w"
243: );
244:
245: fwrite($output_file, "<?php\n\n");
246:
247: fwrite($output_file, "use Peg\Lib\Definitions\Element\TypeDef;\n");
248:
249: foreach($this->symbols->headers as $header)
250: {
251: if(!$header->HasTypeDefs())
252: continue;
253:
254: foreach($header->namespaces as $namespace)
255: {
256: if(!$namespace->HasTypeDefs())
257: continue;
258:
259: foreach($namespace->type_definitions as $typedef)
260: {
261: $type = addslashes($typedef->original_type);
262: $description = addslashes($typedef->description);
263: $namespace_name = addslashes($namespace->name);
264:
265: $output = "\n";
266: $output .= '$symbols->AddTypeDef(' . "\n";
267: $output .= ' new TypeDef(' . "\n";
268: $output .= ' "'.$typedef->name.'",' . "\n";
269: $output .= ' "'.$type.'",' . "\n";
270: $output .= ' "'.$description.'"' . "\n";
271: $output .= ' ),' . "\n";
272: $output .= ' "'.$header->name.'",' . "\n";
273: $output .= ' "'.$namespace_name.'"' . "\n";
274: $output .= ');' . "\n";
275:
276: fwrite($output_file, $output);
277: }
278: }
279: }
280:
281: fclose($output_file);
282: }
283:
284: 285: 286:
287: private function SaveGloablVariablesToPHP()
288: {
289: $output_file = fopen(
290: $this->definitions_path . "variables.php",
291: "w"
292: );
293:
294: fwrite($output_file, "<?php\n\n");
295:
296: fwrite($output_file, "use Peg\Lib\Definitions\Element\GlobalVariable;\n");
297:
298: foreach($this->symbols->headers as $header)
299: {
300: if(!$header->HasGlobalVariables())
301: continue;
302:
303: foreach($header->namespaces as $namespace)
304: {
305: if(!$namespace->HasGlobalVariables())
306: continue;
307:
308: foreach($namespace->global_variables as $variable)
309: {
310: $type = addslashes($variable->original_type);
311: $description = addslashes($variable->description);
312: $namespace_name = addslashes($namespace->name);
313:
314: $output = "\n";
315: $output .= '$symbols->AddGlobalVar(' . "\n";
316: $output .= ' new GlobalVariable(' . "\n";
317: $output .= ' "'.$variable->name.'",' . "\n";
318: $output .= ' "'.$type.'",' . "\n";
319: $output .= ' "'.$description.'"' . "\n";
320: $output .= ' ),' . "\n";
321: $output .= ' "'.$header->name.'",' . "\n";
322: $output .= ' "'.$namespace_name.'"' . "\n";
323: $output .= ');' . "\n";
324:
325: fwrite($output_file, $output);
326: }
327: }
328: }
329:
330: fclose($output_file);
331: }
332:
333: 334: 335:
336: private function SaveFunctionsToPHP()
337: {
338: $output_file = fopen(
339: $this->definitions_path . "functions.php",
340: "w"
341: );
342:
343: fwrite($output_file, "<?php\n\n");
344:
345: fwrite($output_file, "use Peg\Lib\Definitions\Element\FunctionElement;\n");
346: fwrite($output_file, "use Peg\Lib\Definitions\Element\Overload;\n");
347: fwrite($output_file, "use Peg\Lib\Definitions\Element\ReturnType;\n");
348: fwrite($output_file, "use Peg\Lib\Definitions\Element\Parameter;\n");
349:
350: foreach($this->symbols->headers as $header)
351: {
352: if(!$header->HasFunctions())
353: continue;
354:
355: foreach($header->namespaces as $namespace)
356: {
357: if(!$namespace->HasFunctions())
358: continue;
359:
360: foreach($namespace->functions as $function)
361: {
362: $description = addslashes($function->description);
363: $namespace_name = addslashes($namespace->name);
364:
365: $output = "\n";
366:
367: $output .= '// Function ' . $function->name . "\n";
368: $output .= '$function = new FunctionElement(' . "\n";
369: $output .= ' "'.$function->name.'",' . "\n";
370: $output .= ' "'.$description.'"' . "\n";
371: $output .= ');' . "\n\n";
372:
373: foreach($function->overloads as $overload_index=>$overload)
374: {
375: $overload_description = addslashes($overload->description);
376:
377: $output .= '// Overload ' . $overload_index . "\n";
378: $output .= '$overload = new Overload(' . "\n";
379: $output .= ' "'.$overload_description.'"' . "\n";
380: $output .= ');' . "\n";
381:
382: $output .= '$overload->SetReturnType(' . "\n";
383: $output .= ' new ReturnType(' . "\n";
384: $output .= ' "'.$overload->return_type->original_type.'"' . "\n";
385: $output .= ' )' . "\n";
386: $output .= ');' . "\n";
387:
388: if($overload->HasParameters())
389: {
390: foreach($overload->parameters as $parameter)
391: {
392: $parameter_value = addslashes($parameter->default_value);
393: $parameter_description = addslashes($parameter->description);
394:
395: $output .= '$parameter = new Parameter(' . "\n";
396: $output .= ' "'.$parameter->name.'",' . "\n";
397: $output .= ' "'.$parameter->original_type.'",' . "\n";
398: $output .= ' "'.$parameter_value.'",' . "\n";
399: $output .= ' "'.$parameter_description.'"' . "\n";
400: $output .= ');' . "\n";
401:
402: if($parameter->is_array)
403: {
404: $output .= '$parameter->is_array = true;' . "\n";
405: }
406:
407: $output .= '$overload->AddParameter(' . "\n";
408: $output .= ' $parameter' . "\n";
409: $output .= ');' . "\n";
410: }
411: }
412:
413: $output .= '$function->AddOverload($overload);' . "\n\n";
414: }
415:
416: $output .= '$symbols->AddFunction(' . "\n";
417: $output .= ' $function,' . "\n";
418: $output .= ' "'.$header->name.'",' . "\n";
419: $output .= ' "'.$namespace_name.'"' . "\n";
420: $output .= ');' . "\n\n";
421:
422: fwrite($output_file, $output);
423: }
424: }
425: }
426:
427: fclose($output_file);
428: }
429:
430: 431: 432:
433: private function SaveClassesToPHP()
434: {
435: $output_file = fopen(
436: $this->definitions_path . "classes.php",
437: "w"
438: );
439:
440: fwrite($output_file, "<?php\n\n");
441:
442: fwrite($output_file, "use Peg\Lib\Definitions\Element\ClassElement;\n");
443: fwrite($output_file, "use Peg\Lib\Definitions\Element\FunctionElement;\n");
444: fwrite($output_file, "use Peg\Lib\Definitions\Element\Overload;\n");
445: fwrite($output_file, "use Peg\Lib\Definitions\Element\ReturnType;\n");
446: fwrite($output_file, "use Peg\Lib\Definitions\Element\Parameter;\n");
447: fwrite($output_file, "use Peg\Lib\Definitions\Element\Enumeration;\n");
448: fwrite($output_file, "use Peg\Lib\Definitions\Element\ClassVariable;\n");
449:
450: foreach($this->symbols->headers as $header)
451: {
452: if(!$header->HasClasses())
453: continue;
454:
455: foreach($header->namespaces as $namespace)
456: {
457: if(!$namespace->HasClasses())
458: continue;
459:
460: foreach($namespace->classes as $class)
461: {
462: $description = addslashes($class->description);
463: $namespace_name = addslashes($namespace->name);
464:
465: $output = "\n";
466: $output .= '// Class ' . $class->name . "\n";
467: $output .= '$class = new ClassElement(' . "\n";
468: $output .= ' "'.$class->name.'",' . "\n";
469: $output .= ' "'.$description.'"' . "\n";
470: $output .= ');' . "\n\n";
471:
472:
473: foreach($class->methods as $method)
474: {
475: $description = addslashes($method->description);
476:
477: $output .= "\n";
478:
479: $output .= '// Method ' . $class->name . '::' . $method->name . "\n";
480: $output .= '$method = new FunctionElement(' . "\n";
481: $output .= ' "'.$method->name.'",' . "\n";
482: $output .= ' "'.$description.'"' . "\n";
483: $output .= ');' . "\n\n";
484:
485: foreach($method->overloads as $overload_index=>$overload)
486: {
487: $overload_description = addslashes($overload->description);
488:
489: $output .= '// Overload ' . $overload_index . "\n";
490: $output .= '$overload = new Overload(' . "\n";
491: $output .= ' "'.$overload_description.'"' . "\n";
492: $output .= ');' . "\n";
493:
494: $output .= '$overload->SetReturnType(' . "\n";
495: $output .= ' new ReturnType(' . "\n";
496: $output .= ' "'.$overload->return_type->original_type.'"' . "\n";
497: $output .= ' )' . "\n";
498: $output .= ');' . "\n";
499:
500: if($overload->static)
501: $output .= '$overload->static = true;' . "\n";
502:
503: if($overload->protected)
504: $output .= '$overload->protected = true;' . "\n";
505:
506: if($overload->virtual)
507: $output .= '$overload->virtual = true;' . "\n";
508:
509: if($overload->pure_virtual)
510: $output .= '$overload->pure_virtual = true;' . "\n";
511:
512: if($overload->constant)
513: $output .= '$overload->constant = true;' . "\n";
514:
515: if($overload->HasParameters())
516: {
517: foreach($overload->parameters as $parameter)
518: {
519: $parameter_value = addslashes($parameter->default_value);
520: $parameter_description = addslashes($parameter->description);
521:
522: $output .= '$parameter = new Parameter(' . "\n";
523: $output .= ' "'.$parameter->name.'",' . "\n";
524: $output .= ' "'.$parameter->original_type.'",' . "\n";
525: $output .= ' "'.$parameter_value.'",' . "\n";
526: $output .= ' "'.$parameter_description.'"' . "\n";
527: $output .= ');' . "\n";
528:
529: if($parameter->is_array)
530: {
531: $output .= '$parameter->is_array = true;' . "\n";
532: }
533:
534: $output .= '$overload->AddParameter(' . "\n";
535: $output .= ' $parameter' . "\n";
536: $output .= ');' . "\n";
537: }
538: }
539:
540: $output .= '$method->AddOverload($overload);' . "\n\n";
541: }
542:
543: $output .= '$class->AddMethod(' . "\n";
544: $output .= ' $method' . "\n";
545: $output .= ');' . "\n\n";
546: }
547:
548:
549: foreach($class->enumerations as $enumeration)
550: {
551: $description = addslashes($enumeration->description);
552:
553: $output .= "\n";
554: $output .= '// Enumeration ' . $class->name . '::' . $enumeration->name . "\n";
555: $output .= '$class->AddEnumeration(' . "\n";
556: $output .= ' new Enumeration(' . "\n";
557: $output .= ' "'.$enumeration->name.'",' . "\n";
558:
559: $output .= ' [' . "\n";
560: foreach($enumeration->options as $option)
561: {
562: $output .= ' "'.$option.'",' . "\n";
563: }
564: $output = rtrim($output, ",\n") . "\n";
565: $output .= ' ],' . "\n";
566:
567: $output .= ' "'.$description.'"' . "\n";
568: $output .= ' )' . "\n";
569: $output .= ');' . "\n";
570:
571: fwrite($output_file, $output);
572: }
573:
574:
575: foreach($class->variables as $variable)
576: {
577: $type = addslashes($variable->original_type);
578: $description = addslashes($variable->description);
579:
580: $output .= "\n";
581: $output .= '$class->AddVariable(' . "\n";
582: $output .= ' new ClassVariable(' . "\n";
583: $output .= ' "'.$variable->name.'",' . "\n";
584: $output .= ' "'.$type.'",' . "\n";
585: $output .= ' "'.$description.'"' . "\n";
586: $output .= ' )' . "\n";
587: $output .= ');' . "\n";
588:
589: fwrite($output_file, $output);
590: }
591:
592: $output .= '$symbols->AddClass(' . "\n";
593: $output .= ' $class,' . "\n";
594: $output .= ' "'.$header->name.'",' . "\n";
595: $output .= ' "'.$namespace_name.'"' . "\n";
596: $output .= ');' . "\n\n";
597:
598: fwrite($output_file, $output);
599: }
600: }
601: }
602:
603: fclose($output_file);
604: }
605:
606: 607: 608: 609:
610: private function SaveToJSON($path)
611: {
612: $this->definitions_path = rtrim($path, "/\\") . "/";
613: $this->export_type = Type::JSON;
614:
615: $this->SendMessage(t("Creating constants.json"));
616: $this->SaveConstantsToJson();
617:
618: $this->SendMessage(t("Creating enumerations.json"));
619: $this->SaveEnumerationsToJson();
620:
621: $this->SendMessage(t("Creating type_definitions.json"));
622: $this->SaveTypeDefToJson();
623:
624: $this->SendMessage(t("Creating variables.json"));
625: $this->SaveGlobalVariablesToJson();
626:
627: $this->SendMessage(t("Creating functions.json"));
628: $this->SaveFunctionsToJson();
629:
630: $this->SendMessage(t("Creating classes.json"));
631: $this->SaveClassesToJson();
632: }
633:
634: 635: 636:
637: private function SaveConstantsToJson()
638: {
639: $constants = array();
640:
641: foreach($this->symbols->headers as $header)
642: {
643: if(!$header->HasConstants())
644: continue;
645:
646: foreach($header->namespaces as $namespace)
647: {
648: if(!$namespace->HasConstants())
649: continue;
650:
651: foreach($namespace->constants as $constant)
652: {
653: if(trim($constant->description))
654: {
655: $constants[$header->name][$namespace->name]
656: [$constant->name] = [
657: "value" => $constant->value,
658: "description" => $constant->description
659: ]
660: ;
661: }
662: else
663: {
664: $constants[$header->name][$namespace->name]
665: [$constant->name] = [
666: "value" => $constant->value
667: ]
668: ;
669: }
670: }
671: }
672: }
673:
674: if(count($constants) > 0)
675: {
676: file_put_contents(
677: $this->definitions_path . "constants.json",
678: Json::Encode($constants)
679: );
680:
681: unset($constants);
682: }
683: }
684:
685: 686: 687:
688: private function SaveEnumerationsToJson()
689: {
690: $enumerations = array();
691:
692: foreach($this->symbols->headers as $header)
693: {
694: if(!$header->HasEnumerations())
695: continue;
696:
697: foreach($header->namespaces as $namespace)
698: {
699: if(!$namespace->HasEnumerations())
700: continue;
701:
702: foreach($namespace->enumerations as $enumeration)
703: {
704: if(trim($enumeration->description))
705: {
706: $enumerations[$header->name][$namespace->name]
707: [$enumeration->name] = [
708: "options" => $enumeration->options,
709: "description" => $enumeration->description
710: ]
711: ;
712: }
713: else
714: {
715: $enumerations[$header->name][$namespace->name]
716: [$enumeration->name] = [
717: "options" => $enumeration->options
718: ]
719: ;
720: }
721: }
722: }
723: }
724:
725: if(count($enumerations) > 0)
726: {
727: file_put_contents(
728: $this->definitions_path . "enumerations.json",
729: Json::Encode($enumerations)
730: );
731:
732: unset($enumerations);
733: }
734: }
735:
736: 737: 738:
739: private function SaveTypeDefToJson()
740: {
741: $typedefs = array();
742:
743: foreach($this->symbols->headers as $header)
744: {
745: if(!$header->HasTypeDefs())
746: continue;
747:
748: foreach($header->namespaces as $namespace)
749: {
750: if(!$namespace->HasTypeDefs())
751: continue;
752:
753: foreach($namespace->type_definitions as $typedef)
754: {
755: if(trim($typedef->description))
756: {
757: $typedefs[$header->name][$namespace->name]
758: [$typedef->name] = [
759: "type" => $typedef->original_type,
760: "description" => $typedef->description
761: ]
762: ;
763: }
764: else
765: {
766: $typedefs[$header->name][$namespace->name]
767: [$typedef->name] = [
768: "type" => $typedef->original_type
769: ]
770: ;
771: }
772: }
773: }
774: }
775:
776: if(count($typedefs) > 0)
777: {
778: file_put_contents(
779: $this->definitions_path . "type_definitions.json",
780: Json::Encode($typedefs)
781: );
782:
783: unset($typedefs);
784: }
785: }
786:
787: 788: 789:
790: private function SaveGlobalVariablesToJson()
791: {
792: $variables = array();
793:
794: foreach($this->symbols->headers as $header)
795: {
796: if(!$header->HasGlobalVariables())
797: continue;
798:
799: foreach($header->namespaces as $namespace)
800: {
801: if(!$namespace->HasGlobalVariables())
802: continue;
803:
804: foreach($namespace->global_variables as $variable)
805: {
806: if(trim($variable->description))
807: {
808: $variables[$header->name][$namespace->name]
809: [$variable->name] = [
810: "type" => $variable->original_type,
811: "description" => $variable->description
812: ]
813: ;
814: }
815: else
816: {
817: $variables[$header->name][$namespace->name]
818: [$variable->name] = [
819: "type" => $variable->original_type
820: ]
821: ;
822: }
823: }
824: }
825: }
826:
827: if(count($variables) > 0)
828: {
829: file_put_contents(
830: $this->definitions_path . "variables.json",
831: Json::Encode($variables)
832: );
833:
834: unset($variables);
835: }
836: }
837:
838: 839: 840:
841: private function SaveFunctionsToJson()
842: {
843: $functions = array();
844:
845: foreach($this->symbols->headers as $header)
846: {
847: if(!$header->HasFunctions())
848: continue;
849:
850: foreach($header->namespaces as $namespace)
851: {
852: if(!$namespace->HasFunctions())
853: continue;
854:
855: foreach($namespace->functions as $function)
856: {
857: foreach($function->overloads as $overload)
858: {
859: $parameters = array();
860:
861: if($overload->HasParameters())
862: {
863: foreach($overload->parameters as $parameter)
864: {
865: $parameter_array = array();
866:
867: $parameter_array["name"] = $parameter->name;
868: $parameter_array["type"] = $parameter->original_type;
869:
870: if($parameter->is_array)
871: $parameter_array["is_array"] = $parameter->is_array;
872:
873: if($parameter->default_value)
874: $parameter_array["value"] = $parameter->default_value;
875:
876:
877: if(trim($parameter->description))
878: $parameter_array["description"] = $parameter->description;
879:
880: $parameters[] = $parameter_array;
881:
882: }
883:
884: $functions[$header->name][$namespace->name]
885: [$function->name][] = [
886: "description" => $overload->description,
887: "return_type" => $overload->return_type->original_type,
888: "parameters" => $parameters
889: ]
890: ;
891: }
892: else
893: {
894: $functions[$header->name][$namespace->name]
895: [$function->name][] = [
896: "description" => $overload->description,
897: "return_type" => $overload->return_type->original_type
898: ]
899: ;
900: }
901: }
902: }
903: }
904: }
905:
906: if(count($functions) > 0)
907: {
908: file_put_contents(
909: $this->definitions_path . "functions.json",
910: Json::Encode($functions)
911: );
912:
913: unset($functions);
914: }
915: }
916:
917: 918: 919: 920: 921:
922: private function SaveClassesToJson()
923: {
924: $classes = array();
925: $enumerations = array();
926: $variables = array();
927:
928: foreach($this->symbols->headers as $header)
929: {
930: if(!$header->HasClasses())
931: continue;
932:
933: foreach($header->namespaces as $namespace)
934: {
935: if(!$namespace->HasClasses())
936: continue;
937:
938: foreach($namespace->classes as $class)
939: {
940:
941: if($class->description)
942: {
943: $classes[$header->name][$namespace->name]
944: [$class->name]
945: ["_description"] = $class->description
946: ;
947: }
948:
949: if($class->parents)
950: {
951: foreach($class->parents as $parent)
952: {
953: $classes[$header->name][$namespace->name]
954: [$class->name]
955: ["_parents"][] = $parent
956: ;
957: }
958: }
959:
960: if($class->struct)
961: {
962: $classes[$header->name][$namespace->name]
963: [$class->name]
964: ["_struct"] = $class->struct
965: ;
966: }
967:
968: if($class->forward_declaration)
969: {
970: $classes[$header->name][$namespace->name]
971: [$class->name]
972: ["_forward_declaration"] = $class->forward_declaration
973: ;
974: }
975:
976: if($class->platforms)
977: {
978: $classes[$header->name][$namespace->name]
979: [$class->name]
980: ["_platforms"] = $class->platforms
981: ;
982: }
983:
984:
985: foreach($class->methods as $function)
986: {
987: foreach($function->overloads as $overload)
988: {
989: $parameters = array();
990:
991: if($overload->HasParameters())
992: {
993: foreach($overload->parameters as $parameter)
994: {
995: $parameter_array = array();
996:
997: $parameter_array["name"] = $parameter->name;
998: $parameter_array["type"] = $parameter->original_type;
999:
1000: if($parameter->is_array)
1001: $parameter_array["is_array"] = $parameter->is_array;
1002:
1003: if($parameter->default_value)
1004: $parameter_array["value"] = $parameter->default_value;
1005:
1006:
1007: if(trim($parameter->description))
1008: $parameter_array["description"] = $parameter->description;
1009:
1010: $parameters[] = $parameter_array;
1011: }
1012:
1013: $classes[$header->name][$namespace->name]
1014: [$class->name][$function->name][] = [
1015: "description" => $overload->description,
1016: "return_type" => $overload->return_type->original_type,
1017: "parameters" => $parameters
1018: ]
1019: ;
1020: }
1021: else
1022: {
1023: $classes[$header->name][$namespace->name]
1024: [$class->name][$function->name][] = [
1025: "description" => $overload->description,
1026: "return_type" => $overload->return_type->original_type
1027: ]
1028: ;
1029: }
1030: }
1031: }
1032:
1033:
1034: foreach($class->enumerations as $enumeration)
1035: {
1036: if(trim($enumeration->description))
1037: {
1038: $enumerations[$header->name][$namespace->name]
1039: [$class->name][$enumeration->name] = [
1040: "options" => $enumeration->options,
1041: "description" => $enumeration->description
1042: ]
1043: ;
1044: }
1045: else
1046: {
1047: $enumerations[$header->name][$namespace->name]
1048: [$class->name][$enumeration->name] = [
1049: "options" => $enumeration->options
1050: ]
1051: ;
1052: }
1053: }
1054:
1055:
1056: foreach($class->variables as $variable)
1057: {
1058: $variable_array = array();
1059:
1060: if(trim($variable->type))
1061: $variable_array["type"] = $variable->type;
1062:
1063: if(trim($variable->static))
1064: $variable_array["static"] = $variable->static;
1065:
1066: if(trim($variable->protected))
1067: $variable_array["protected"] = $variable->protected;
1068:
1069: if(trim($variable->mutable))
1070: $variable_array["mutable"] = $variable->mutable;
1071:
1072: if(trim($variable->description))
1073: $variable_array["description"] = $variable->description;
1074:
1075: $variables[$header->name][$namespace->name]
1076: [$class->name][$variable->name] = $variable_array
1077: ;
1078: }
1079: }
1080: }
1081: }
1082:
1083: if(count($classes) > 0)
1084: {
1085: file_put_contents(
1086: $this->definitions_path . "classes.json",
1087: Json::Encode($classes)
1088: );
1089:
1090: unset($classes);
1091: }
1092:
1093: if(count($enumerations) > 0)
1094: {
1095: file_put_contents(
1096: $this->definitions_path . "class_enumerations.json",
1097: Json::Encode($enumerations)
1098: );
1099:
1100: unset($enumerations);
1101: }
1102:
1103: if(count($variables) > 0)
1104: {
1105: file_put_contents(
1106: $this->definitions_path . "class_variables.json",
1107: Json::Encode($variables)
1108: );
1109:
1110: unset($variables);
1111: }
1112: }
1113:
1114: 1115: 1116: 1117:
1118: private function SendMessage($message)
1119: {
1120: $this->signal_data->message = $message;
1121:
1122: $this->Send(
1123: \Peg\Lib\Signals\Type\Definitions::EXPORT_MESSAGE,
1124: $this->signal_data
1125: );
1126: }
1127: }