summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/lib
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-07-12 22:26:21 +0300
committerAndrew Dolgov <[email protected]>2022-07-12 22:26:21 +0300
commit80d3db1dcf8fe9ca66d4e3f2e2116d3bc39ae2b4 (patch)
tree04b33bfb9c9368c4a31e287153abec690b9014e0 /vendor/thecodingmachine/safe/lib
parent4b6161892000cb2b8392dce92a9cf2cabdf2d20e (diff)
upgrade idiorm to php8.1-patched version (aaronpk/idiorm)
Diffstat (limited to 'vendor/thecodingmachine/safe/lib')
-rw-r--r--vendor/thecodingmachine/safe/lib/DateTime.php2
-rw-r--r--vendor/thecodingmachine/safe/lib/DateTimeImmutable.php30
-rw-r--r--vendor/thecodingmachine/safe/lib/Exceptions/CurlException.php4
-rw-r--r--vendor/thecodingmachine/safe/lib/Exceptions/JsonException.php2
-rw-r--r--vendor/thecodingmachine/safe/lib/Exceptions/SimplexmlException.php11
-rw-r--r--vendor/thecodingmachine/safe/lib/special_cases.php178
6 files changed, 201 insertions, 26 deletions
diff --git a/vendor/thecodingmachine/safe/lib/DateTime.php b/vendor/thecodingmachine/safe/lib/DateTime.php
index 581ef35c0..56eb809f8 100644
--- a/vendor/thecodingmachine/safe/lib/DateTime.php
+++ b/vendor/thecodingmachine/safe/lib/DateTime.php
@@ -24,7 +24,7 @@ class DateTime extends \DateTime
*/
public static function createFromFormat($format, $time, $timezone = null): self
{
- $datetime = parent::createFromFormat($format, $time, $timezone);
+ $datetime = \DateTime::createFromFormat($format, $time, $timezone);
if ($datetime === false) {
throw DatetimeException::createFromPhpError();
}
diff --git a/vendor/thecodingmachine/safe/lib/DateTimeImmutable.php b/vendor/thecodingmachine/safe/lib/DateTimeImmutable.php
index 114ec3a3d..5cedd24a0 100644
--- a/vendor/thecodingmachine/safe/lib/DateTimeImmutable.php
+++ b/vendor/thecodingmachine/safe/lib/DateTimeImmutable.php
@@ -2,10 +2,6 @@
namespace Safe;
-use DateInterval;
-use DateTime;
-use DateTimeInterface;
-use DateTimeZone;
use Safe\Exceptions\DatetimeException;
/**
@@ -23,7 +19,7 @@ class DateTimeImmutable extends \DateTimeImmutable
/**
* DateTimeImmutable constructor.
* @param string $time
- * @param DateTimeZone|null $timezone
+ * @param \DateTimeZone|null $timezone
* @throws \Exception
*/
public function __construct($time = 'now', $timezone = null)
@@ -52,12 +48,12 @@ class DateTimeImmutable extends \DateTimeImmutable
/**
* @param string $format
* @param string $time
- * @param DateTimeZone|null $timezone
+ * @param \DateTimeZone|null $timezone
* @throws DatetimeException
*/
public static function createFromFormat($format, $time, $timezone = null): self
{
- $datetime = parent::createFromFormat($format, $time, $timezone);
+ $datetime = \DateTimeImmutable::createFromFormat($format, $time, $timezone);
if ($datetime === false) {
throw DatetimeException::createFromPhpError();
}
@@ -80,12 +76,12 @@ class DateTimeImmutable extends \DateTimeImmutable
}
/**
- * @param DateTimeInterface $datetime2
+ * @param \DateTimeInterface $datetime2
* @param bool $absolute
- * @return DateInterval
+ * @return \DateInterval
* @throws DatetimeException
*/
- public function diff($datetime2, $absolute = false): DateInterval
+ public function diff($datetime2, $absolute = false): \DateInterval
{
/** @var \DateInterval|false $result */
$result = $this->innerDateTime->diff($datetime2, $absolute);
@@ -178,7 +174,7 @@ class DateTimeImmutable extends \DateTimeImmutable
}
/**
- * @param DateTimeZone $timezone
+ * @param \DateTimeZone $timezone
* @return DateTimeImmutable
* @throws DatetimeException
*/
@@ -193,7 +189,7 @@ class DateTimeImmutable extends \DateTimeImmutable
}
/**
- * @param DateInterval $interval
+ * @param \DateInterval $interval
* @return DateTimeImmutable
* @throws DatetimeException
*/
@@ -224,7 +220,7 @@ class DateTimeImmutable extends \DateTimeImmutable
//overload getters to use the inner datetime immutable instead of itself
/**
- * @param DateInterval $interval
+ * @param \DateInterval $interval
* @return DateTimeImmutable
*/
public function add($interval): self
@@ -233,12 +229,14 @@ class DateTimeImmutable extends \DateTimeImmutable
}
/**
- * @param DateTime $dateTime
+ * @param \DateTime $dateTime
* @return DateTimeImmutable
*/
public static function createFromMutable($dateTime): self
{
- return self::createFromRegular(parent::createFromMutable($dateTime));
+ $date = \DateTimeImmutable::createFromMutable($dateTime);
+
+ return self::createFromRegular($date);
}
/**
@@ -250,7 +248,7 @@ class DateTimeImmutable extends \DateTimeImmutable
return self::createFromRegular(parent::__set_state($array));
}
- public function getTimezone(): DateTimeZone
+ public function getTimezone(): \DateTimeZone
{
return $this->innerDateTime->getTimezone();
}
diff --git a/vendor/thecodingmachine/safe/lib/Exceptions/CurlException.php b/vendor/thecodingmachine/safe/lib/Exceptions/CurlException.php
index 2814066b0..d0dbdb695 100644
--- a/vendor/thecodingmachine/safe/lib/Exceptions/CurlException.php
+++ b/vendor/thecodingmachine/safe/lib/Exceptions/CurlException.php
@@ -6,9 +6,9 @@ namespace Safe\Exceptions;
class CurlException extends \Exception implements SafeExceptionInterface
{
/**
- * @param resource $ch
+ * @param \CurlHandle $ch
*/
- public static function createFromCurlResource($ch): self
+ public static function createFromPhpError($ch): self
{
return new self(\curl_error($ch), \curl_errno($ch));
}
diff --git a/vendor/thecodingmachine/safe/lib/Exceptions/JsonException.php b/vendor/thecodingmachine/safe/lib/Exceptions/JsonException.php
index 4300d29e9..d7d5a010d 100644
--- a/vendor/thecodingmachine/safe/lib/Exceptions/JsonException.php
+++ b/vendor/thecodingmachine/safe/lib/Exceptions/JsonException.php
@@ -3,7 +3,7 @@
namespace Safe\Exceptions;
-class JsonException extends \Exception implements SafeExceptionInterface
+class JsonException extends \JsonException implements SafeExceptionInterface
{
public static function createFromPhpError(): self
{
diff --git a/vendor/thecodingmachine/safe/lib/Exceptions/SimplexmlException.php b/vendor/thecodingmachine/safe/lib/Exceptions/SimplexmlException.php
new file mode 100644
index 000000000..477a9151c
--- /dev/null
+++ b/vendor/thecodingmachine/safe/lib/Exceptions/SimplexmlException.php
@@ -0,0 +1,11 @@
+<?php
+namespace Safe\Exceptions;
+
+class SimplexmlException extends \ErrorException implements SafeExceptionInterface
+{
+ public static function createFromPhpError(): self
+ {
+ $error = \error_get_last();
+ return new self($error['message'] ?? 'An error occured', 0, $error['type'] ?? 1);
+ }
+}
diff --git a/vendor/thecodingmachine/safe/lib/special_cases.php b/vendor/thecodingmachine/safe/lib/special_cases.php
index d18e2118b..b95fe0b77 100644
--- a/vendor/thecodingmachine/safe/lib/special_cases.php
+++ b/vendor/thecodingmachine/safe/lib/special_cases.php
@@ -7,13 +7,18 @@
namespace Safe;
-use Safe\Exceptions\SocketsException;
+use Safe\Exceptions\FilesystemException;
use const PREG_NO_ERROR;
+
+use Safe\Exceptions\MiscException;
+use Safe\Exceptions\PosixException;
+use Safe\Exceptions\SocketsException;
use Safe\Exceptions\ApcException;
use Safe\Exceptions\ApcuException;
use Safe\Exceptions\JsonException;
use Safe\Exceptions\OpensslException;
use Safe\Exceptions\PcreException;
+use Safe\Exceptions\SimplexmlException;
/**
* Wrapper for json_decode that throws when an error occurs.
@@ -21,7 +26,7 @@ use Safe\Exceptions\PcreException;
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted
* into associative arrays.
- * @param int $depth User specified recursion depth.
+ * @param int<1, max> $depth User specified recursion depth.
* @param int $options Bitmask of JSON decode options.
*
* @return mixed
@@ -83,12 +88,12 @@ function apcu_fetch($key)
* pattern and replaces them with
* replacement.
*
- * @param mixed $pattern The pattern to search for. It can be either a string or an array with
+ * @param string[]|string $pattern The pattern to search for. It can be either a string or an array with
* strings.
*
* Several PCRE modifiers
* are also available.
- * @param mixed $replacement The string or an array with strings to replace. If this parameter is a
+ * @param string[]|string $replacement The string or an array with strings to replace. If this parameter is a
* string and the pattern parameter is an array,
* all patterns will be replaced by that string. If both
* pattern and replacement
@@ -216,7 +221,7 @@ function openssl_encrypt(string $data, string $method, string $key, int $options
* socket from the given
* buffer.
*
- * @param resource $socket
+ * @param \Socket $socket
* @param string $buffer The buffer to be written.
* @param int $length The optional parameter length can specify an
* alternate length of bytes written to the socket. If this length is
@@ -230,7 +235,7 @@ function openssl_encrypt(string $data, string $method, string $key, int $options
* @throws SocketsException
*
*/
-function socket_write($socket, string $buffer, int $length = 0): int
+function socket_write(\Socket $socket, string $buffer, int $length = 0): int
{
error_clear_last();
$result = $length === 0 ? \socket_write($socket, $buffer) : \socket_write($socket, $buffer, $length);
@@ -239,3 +244,164 @@ function socket_write($socket, string $buffer, int $length = 0): int
}
return $result;
}
+
+/**
+ * This function takes a node of a DOM
+ * document and makes it into a SimpleXML node. This new object can
+ * then be used as a native SimpleXML element.
+ *
+ * @param \DOMNode $node A DOM Element node
+ * @param string $class_name You may use this optional parameter so that
+ * simplexml_import_dom will return an object of
+ * the specified class. That class should extend the
+ * SimpleXMLElement class.
+ * @return \SimpleXMLElement Returns a SimpleXMLElement.
+ * @throws SimplexmlException
+ *
+ */
+function simplexml_import_dom(\DOMNode $node, string $class_name = \SimpleXMLElement::class): \SimpleXMLElement
+{
+ error_clear_last();
+ $result = \simplexml_import_dom($node, $class_name);
+ if ($result === null) {
+ throw SimplexmlException::createFromPhpError();
+ }
+ return $result;
+}
+
+/**
+ * Convert the well-formed XML document in the given file to an object.
+ *
+ * @param string $filename Path to the XML file
+ * @param string $class_name You may use this optional parameter so that
+ * simplexml_load_file will return an object of
+ * the specified class. That class should extend the
+ * SimpleXMLElement class.
+ * @param int $options Since Libxml 2.6.0, you may also use the
+ * options parameter to specify additional Libxml parameters.
+ * @param string $namespace_or_prefix Namespace prefix or URI.
+ * @param bool $is_prefix TRUE if namespace_or_prefix is a prefix, FALSE if it's a URI;
+ * defaults to FALSE.
+ * @return \SimpleXMLElement Returns an object of class SimpleXMLElement with
+ * properties containing the data held within the XML document.
+ * @throws SimplexmlException
+ *
+ */
+function simplexml_load_file(string $filename, string $class_name = \SimpleXMLElement::class, int $options = 0, string $namespace_or_prefix = "", bool $is_prefix = false): \SimpleXMLElement
+{
+ error_clear_last();
+ $result = \simplexml_load_file($filename, $class_name, $options, $namespace_or_prefix, $is_prefix);
+ if ($result === false) {
+ throw SimplexmlException::createFromPhpError();
+ }
+ return $result;
+}
+
+
+/**
+ * Takes a well-formed XML string and returns it as an object.
+ *
+ * @param string $data A well-formed XML string
+ * @param string $class_name You may use this optional parameter so that
+ * simplexml_load_string will return an object of
+ * the specified class. That class should extend the
+ * SimpleXMLElement class.
+ * @param int $options Since Libxml 2.6.0, you may also use the
+ * options parameter to specify additional Libxml parameters.
+ * @param string $namespace_or_prefix Namespace prefix or URI.
+ * @param bool $is_prefix TRUE if namespace_or_prefix is a prefix, FALSE if it's a URI;
+ * defaults to FALSE.
+ * @return \SimpleXMLElement Returns an object of class SimpleXMLElement with
+ * properties containing the data held within the xml document.
+ * @throws SimplexmlException
+ *
+ */
+function simplexml_load_string(string $data, string $class_name = \SimpleXMLElement::class, int $options = 0, string $namespace_or_prefix = "", bool $is_prefix = false): \SimpleXMLElement
+{
+ error_clear_last();
+ $result = \simplexml_load_string($data, $class_name, $options, $namespace_or_prefix, $is_prefix);
+ if ($result === false) {
+ throw SimplexmlException::createFromPhpError();
+ }
+ return $result;
+}
+
+/**
+ * Returns three samples representing the average system load
+ * (the number of processes in the system run queue) over the last 1, 5 and 15
+ * minutes, respectively. Returns FALSE on failure.
+ *
+ * @return array<int,float> Returns an array with three samples (last 1, 5 and 15
+ * minutes).
+ * @throws MiscException
+ *
+ */
+function sys_getloadavg(): array
+{
+ error_clear_last();
+ $result = \sys_getloadavg();
+ if ($result === false) {
+ throw MiscException::createFromPhpError();
+ }
+ return $result;
+}
+
+/**
+ * Returns the process group identifier of the process
+ * process_id.
+ *
+ * @param int $process_id The process id.
+ * @return int Returns the identifier, as an int.
+ * @throws PosixException
+ *
+ */
+function posix_getpgid(int $process_id): int
+{
+ error_clear_last();
+ $result = \posix_getpgid($process_id);
+ if ($result === false) {
+ throw PosixException::createFromPhpError();
+ }
+ return $result;
+}
+
+
+/**
+ * fputcsv formats a line (passed as a
+ * fields array) as CSV and writes it (terminated by a
+ * newline) to the specified file stream.
+ *
+ * @param resource $stream The file pointer must be valid, and must point to
+ * a file successfully opened by fopen or
+ * fsockopen (and not yet closed by
+ * fclose).
+ * @phpstan-param (scalar|\Stringable|null)[] $fields
+ * @param array $fields An array of strings.
+ * @param string $separator The optional separator parameter sets the field
+ * delimiter (one single-byte character only).
+ * @param string $enclosure The optional enclosure parameter sets the field
+ * enclosure (one single-byte character only).
+ * @param string $escape The optional escape parameter sets the
+ * escape character (at most one single-byte character).
+ * An empty string ("") disables the proprietary escape mechanism.
+ * @param string $eol The optional eol parameter sets
+ * a custom End of Line sequence.
+ * @return int Returns the length of the written string.
+ * @throws FilesystemException
+ *
+ */
+function fputcsv($stream, array $fields, string $separator = ",", string $enclosure = "\"", string $escape = "\\", string $eol = "\n"): int
+{
+ error_clear_last();
+ if (PHP_VERSION_ID >= 80100) {
+ /** @phpstan-ignore-next-line */
+ $result = \fputcsv($stream, $fields, $separator, $enclosure, $escape, $eol);
+ } else {
+ $result = \fputcsv($stream, $fields, $separator, $enclosure, $escape);
+ }
+
+ if ($result === false) {
+ throw FilesystemException::createFromPhpError();
+ }
+ return $result;
+}