Lib.hx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (C)2005-2017 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package php;
  23. import haxe.ds.StringMap;
  24. /**
  25. Platform-specific PHP Library. Provides some platform-specific functions
  26. for the PHP target, such as conversion from Haxe types to native types
  27. and vice-versa.
  28. **/
  29. class Lib {
  30. /**
  31. Print the specified value on the default output.
  32. **/
  33. public static inline function print( v : Dynamic ) : Void {
  34. Global.echo(Std.string(v));
  35. }
  36. /**
  37. Print the specified value on the default output followed by
  38. a newline character.
  39. **/
  40. public static function println( v : Dynamic ) : Void {
  41. print(v);
  42. print("\n");
  43. }
  44. /**
  45. Displays structured information about one or more expressions
  46. that includes its type and value. Arrays and objects are
  47. explored recursively with values indented to show structure.
  48. */
  49. public static inline function dump(v : Dynamic) : Void {
  50. Global.var_dump(v);
  51. }
  52. /**
  53. Serialize using native PHP serialization. This will return a binary
  54. `String` that can be stored for long term usage.
  55. **/
  56. public static inline function serialize( v : Dynamic ) : String {
  57. return Global.serialize(v);
  58. }
  59. /**
  60. Unserialize a `String` using native PHP serialization. See `php.Lib.serialize()`.
  61. **/
  62. public static inline function unserialize( s : String ) : Dynamic {
  63. return Global.unserialize(s);
  64. }
  65. /**
  66. Find out whether an extension is loaded.
  67. */
  68. public static inline function extensionLoaded(name : String) {
  69. return Global.extension_loaded(name);
  70. }
  71. public static inline function isCli() : Bool {
  72. return 0 == Global.strncasecmp(Const.PHP_SAPI, 'cli', 3);
  73. }
  74. /**
  75. Output file content from the given file name.
  76. */
  77. public static inline function printFile(file : String) {
  78. return Global.fpassthru(Global.fopen(file, "r"));
  79. }
  80. public static inline function toPhpArray(a : Array<Dynamic>) : NativeArray {
  81. return @:privateAccess a.arr;
  82. }
  83. public static inline function toHaxeArray(a : NativeArray) : Array<Dynamic> {
  84. return @:privateAccess Array.wrap(a);
  85. }
  86. public static function hashOfAssociativeArray<T>(arr : NativeAssocArray<T>) : Map<String,T> {
  87. var result = new StringMap();
  88. @:privateAccess result.data = arr;
  89. return result;
  90. }
  91. public static inline function associativeArrayOfHash(hash : haxe.ds.StringMap<Dynamic>) : NativeArray {
  92. return @:privateAccess hash.data;
  93. }
  94. public static inline function objectOfAssociativeArray(arr : NativeArray) : Dynamic {
  95. return Boot.createAnon(arr);
  96. }
  97. public static inline function associativeArrayOfObject(ob : Dynamic) : NativeArray {
  98. return Syntax.array(ob);
  99. }
  100. /**
  101. * See the documentation for the equivalent PHP function for details on usage:
  102. * <http://php.net/manual/en/function.mail.php>
  103. * @param to
  104. * @param subject
  105. * @param message
  106. * @param ?additionalHeaders
  107. * @param ?additionalParameters
  108. */
  109. public static function mail(to : String, subject : String, message : String, ?additionalHeaders : String, ?additionalParameters : String) : Bool
  110. {
  111. throw "Not implemented";
  112. }
  113. /**
  114. For neko compatibility only.
  115. **/
  116. public static function rethrow( e : Dynamic ) {
  117. throw "Not implemented";
  118. }
  119. static function appendType(o : Dynamic, path : Array<String>, t : Dynamic) {
  120. throw "Not implemented";
  121. }
  122. public static function getClasses() {
  123. throw "Not implemented";
  124. }
  125. /**
  126. * Loads types defined in the specified directory.
  127. */
  128. public static function loadLib(pathToLib : String) : Void
  129. {
  130. throw "Not implemented";
  131. }
  132. }