Browse Source

[php] Add externs for Phar classes (#10373)

Cédric Belin 4 years ago
parent
commit
3e04e91232
4 changed files with 239 additions and 0 deletions
  1. 104 0
      std/php/Phar.hx
  2. 59 0
      std/php/PharData.hx
  3. 30 0
      std/php/PharException.hx
  4. 46 0
      std/php/PharFileInfo.hx

+ 104 - 0
std/php/Phar.hx

@@ -0,0 +1,104 @@
+/*
+ * Copyright (C)2005-2021 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package php;
+
+import haxe.extern.EitherType;
+
+/**
+	The `Phar` class provides a high-level interface to accessing and creating PHAR archives.
+	@see https://www.php.net/manual/en/class.phar.php
+**/
+@:native("Phar")
+extern class Phar extends RecursiveDirectoryIterator implements Countable implements php.ArrayAccess<String, PharFileInfo> {
+	@:phpClassConst static final BZ2: Int;
+	@:phpClassConst static final COMPRESSED: Int;
+	@:phpClassConst static final GZ: Int;
+	@:phpClassConst static final MD5: Int;
+	@:phpClassConst static final NONE: Int;
+	@:phpClassConst static final OPENSSL: Int;
+	@:phpClassConst static final PHAR: Int;
+	@:phpClassConst static final PHP: Int;
+	@:phpClassConst static final PHPS: Int;
+	@:phpClassConst static final SHA1: Int;
+	@:phpClassConst static final SHA256: Int;
+	@:phpClassConst static final SHA512: Int;
+	@:phpClassConst static final TAR: Int;
+	@:phpClassConst static final ZIP: Int;
+
+	final static function apiVersion(): String;
+	final static function canCompress(type: Int = 0): Bool;
+	final static function canWrite(): Bool;
+	final static function createDefaultStub(?index: String, ?webIndex: String): String;
+	final static function getSupportedCompression(): NativeIndexedArray<String>;
+	final static function getSupportedSignatures(): NativeIndexedArray<String>;
+	final static function isValidPharFilename(filename: String, executable: Bool = true): Bool;
+	final static function loadPhar(filename: String, ?alias: String): Bool;
+	final static function mapPhar(?alias: String, dataoffset: Int = 0): Bool;
+	final static function mount(pharpath: String, externalpath: String): Void;
+	final static function mungServer(munglist: NativeIndexedArray<String>): Void;
+	final static function running(retphar: Bool = true): String;
+	final static function unlinkArchive(archive: String): Bool;
+	final static function webPhar(?alias: String, index: String = "index.php", ?f404: String, ?mimetypes: NativeAssocArray<String>, ?callable: String -> EitherType<String, Bool>): Void;
+
+	function new(fname: String, ?flags: Int, ?alias: String);
+
+	function addEmptyDir(dirname: String): Void;
+	function addFile(file: String, ?localname: String): Void;
+	function addFromString(localname: String, contents: String): Void;
+	function buildFromDirectory(base_dir: String, ?regex: String): NativeAssocArray<String>;
+	function buildFromIterator(iter: EitherType<NativeIterator<String, String>, NativeIterator<Int, SplFileInfo>>, ?base_directory: String): NativeAssocArray<String>;
+	function compress(compression: Int, ?extension: String): Phar;
+	function compressFiles(compression: Int): Void;
+	function convertToData(?format: Int, ?compression: Int, ?extension: String): PharData;
+	function convertToExecutable(?format: Int, ?compression: Int, ?extension: String): Phar;
+	function copy(oldfile: String, newfile: String): Bool;
+	function count(): Int;
+	function decompress(?extension: String): PharData;
+	function decompressFiles(): Void;
+	function delete(entry: String): Bool;
+	function delMetadata(): Bool;
+	function extractTo(pathto: String, ?files: EitherType<String, NativeIndexedArray<String>>, overwrite: Bool = false): Bool;
+	function getAlias(): String;
+	function getMetadata(): Dynamic;
+	function getModified(): Bool;
+	function getPath(): String;
+	function getSignature(): NativeAssocArray<String>;
+	function getStub(): String;
+	function getVersion(): String;
+	function hasMetadata(): Bool;
+	function isBuffering(): Bool;
+	function isCompressed(): EitherType<Int, Bool>;
+	function isFileFormat(format: Int): Bool;
+	function isWritable(): Bool;
+	function offsetExists(offset: String): Bool;
+	function offsetGet(offset: String): PharFileInfo;
+	function offsetSet(offset: String, value: Dynamic): Void;
+	function offsetUnset(offset: String): Void;
+	function setAlias(alias: String): Bool;
+	function setDefaultStub(?index: String, ?webindex: String): Bool;
+	function setMetadata(metadata: Any): Void;
+	function setSignatureAlgorithm(sigtype: Int, ?privatekey: String): Void;
+	function setStub(stub: String, len: Int = -1): Bool;
+	function startBuffering(): Void;
+	function stopBuffering(): Void;
+}

+ 59 - 0
std/php/PharData.hx

@@ -0,0 +1,59 @@
+/*
+ * Copyright (C)2005-2021 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package php;
+
+import haxe.extern.EitherType;
+
+/**
+	The `PharData` class provides a high-level interface to accessing and creating non-executable TAR and ZIP archives.
+	@see https://www.php.net/manual/en/class.phardata.php
+**/
+@:native("PharData")
+extern class PharData extends RecursiveDirectoryIterator implements Countable implements php.ArrayAccess<String, PharFileInfo> {
+	function new(fname: String, ?flags: Int, ?alias: String, ?format: Int);
+
+	function addEmptyDir(dirname: String): Void;
+	function addFile(file: String, ?localname: String): Void;
+	function addFromString(localname: String, contents: String): Void;
+	function buildFromDirectory(base_dir: String, ?regex: String): NativeAssocArray<String>;
+	function buildFromIterator(iter: EitherType<NativeIterator<String, String>, NativeIterator<Int, SplFileInfo>>, ?base_directory: String): NativeAssocArray<String>;
+	function compress(compression: Int, ?extension: String): PharData;
+	function compressFiles(compression: Int): Void;
+	function copy(oldfile: String, newfile: String): Bool;
+	function count(): Int;
+	function decompress(?extension: String): PharData;
+	function decompressFiles(): Void;
+	function delete(entry: String): Bool;
+	function delMetadata(): Bool;
+	function extractTo(pathto: String, ?files: EitherType<String, NativeIndexedArray<String>>, overwrite: Bool = false): Bool;
+	function isWritable(): Bool;
+	function offsetExists(offset: String): Bool;
+	function offsetGet(offset: String): PharFileInfo;
+	function offsetSet(offset: String, value: Dynamic): Void;
+	function offsetUnset(offset: String): Void;
+	function setAlias(alias: String): Bool;
+	function setDefaultStub(?index: String, ?webindex: String): Bool;
+	function setMetadata(metadata: Any): Void;
+	function setSignatureAlgorithm(sigtype: Int): Void;
+	function setStub(stub: String, len: Int = -1): Bool;
+}

+ 30 - 0
std/php/PharException.hx

@@ -0,0 +1,30 @@
+/*
+ * Copyright (C)2005-2021 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package php;
+
+/**
+	The `PharException` class provides a phar-specific exception class for try/catch blocks.
+	@see https://www.php.net/manual/en/class.pharexception.php
+**/
+@:native("PharException")
+extern class PharException extends Exception {}

+ 46 - 0
std/php/PharFileInfo.hx

@@ -0,0 +1,46 @@
+/*
+ * Copyright (C)2005-2021 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package php;
+
+/**
+	The `PharFileInfo` class provides a high-level interface to the contents and attributes of a single file within a PHAR archive.
+	@see https://www.php.net/manual/en/class.pharfileinfo
+**/
+@:native("PharFileInfo")
+extern class PharFileInfo extends SplFileInfo {
+	function new(entry: String);
+
+	function chmod(permissions: Int): Void;
+	function compress(compression: Int): Bool;
+	function decompress(): Bool;
+	function delMetadata(): Bool;
+	function getCompressedSize(): Int;
+	function getContent(): String;
+	function getCRC32(): Int;
+	function getMetadata(): Dynamic;
+	function getPharFlags(): Int;
+	function hasMetadata(): Bool;
+	function isCompressed(?compression_type: Int): Bool;
+	function isCRCChecked(): Bool;
+	function setMetadata(metadata: Any): Void;
+}