Tools.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Tools;
  3. use Illuminate\Support\Facades\Log;
  4. class Tools{
  5. public static function zip($zipFile,$files){
  6. $zip = new \ZipArchive;
  7. $res = $zip->open($zipFile, \ZipArchive::CREATE);
  8. if ($res === TRUE) {
  9. foreach ($files as $key => $value) {
  10. $zip->addFromString($key, $value);
  11. }
  12. $zip->close();
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }
  18. public static function isStop(){
  19. if(file_exists(base_path('.stop'))){
  20. Log::debug('.stop exists');
  21. return true;
  22. }else{
  23. return false;
  24. }
  25. }
  26. public static function getWordEn($strIn)
  27. {
  28. $out = str_replace(["ā","ī","ū","ṅ","ñ","ṭ","ḍ","ṇ","ḷ","ṃ"],
  29. ["a","i","u","n","n","t","d","n","l","m"], $strIn);
  30. return ($out);
  31. }
  32. public static function PaliReal($inStr): string {
  33. if (!is_string($inStr)) {
  34. return "";
  35. }
  36. $paliLetter = "abcdefghijklmnoprstuvyāīūṅñṭḍṇḷṃ";
  37. $output = [];
  38. $inStr = strtolower($inStr);
  39. for ($i=0; $i < mb_strlen($inStr,"UTF-8"); $i++) {
  40. # code...
  41. if(strstr($paliLetter,$inStr[$i]) !==FALSE){
  42. $output[] = $inStr[$i];
  43. }
  44. }
  45. return implode('',$output);
  46. }
  47. private static function convert($array,$xml){
  48. foreach ($array as $key => $line) {
  49. # code...
  50. if(!is_array($line)){
  51. $data = $xml->addChild($key,$line);
  52. }else{
  53. if(isset($line['value'])){
  54. $value = $line['value'];
  55. unset($line['value']);
  56. }else{
  57. $value = "";
  58. }
  59. $obj = $xml->addChild($key,$value);
  60. if(isset($line['status'])){
  61. $obj->addAttribute('status',$line['status']);
  62. unset($line['status']);
  63. }
  64. Tools::convert($line,$obj);
  65. }
  66. }
  67. return $xml;
  68. }
  69. public static function JsonToXml($inArray){
  70. $xmlObj = simplexml_load_string("<word></word>");
  71. $xmlDoc = Tools::convert($inArray,$xmlObj);
  72. return $xmlDoc->asXml();
  73. }
  74. }