harga pada beranda terhubung ke manage plans di dashboard admin
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m27s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 31s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
triagungbiantoro
2026-04-25 21:57:25 +07:00
parent f25542ea0d
commit 417b7b7453
21707 changed files with 179493 additions and 328 deletions

View File

@@ -0,0 +1,187 @@
<?php
namespace Safe;
use Safe\Exceptions\ApacheException;
/**
* Fetch the Apache version.
*
* @return string Returns the Apache version on success.
* @throws ApacheException
*
*/
function apache_get_version(): string
{
error_clear_last();
$safeResult = \apache_get_version();
if ($safeResult === false) {
throw ApacheException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieve an Apache environment variable specified by
* variable.
*
* @param string $variable The Apache environment variable
* @param bool $walk_to_top Whether to get the top-level variable available to all Apache layers.
* @return string The value of the Apache environment variable on success
* @throws ApacheException
*
*/
function apache_getenv(string $variable, bool $walk_to_top = false): string
{
error_clear_last();
$safeResult = \apache_getenv($variable, $walk_to_top);
if ($safeResult === false) {
throw ApacheException::createFromPhpError();
}
return $safeResult;
}
/**
* This performs a partial request for a URI. It goes just far
* enough to obtain all the important information about the given
* resource.
*
* @param string $filename The filename (URI) that's being requested.
* @return object An object of related URI information. The properties of
* this object are:
*
*
* status
* the_request
* status_line
* method
* content_type
* handler
* uri
* filename
* path_info
* args
* boundary
* no_cache
* no_local_copy
* allowed
* send_bodyct
* bytes_sent
* byterange
* clength
* unparsed_uri
* mtime
* request_time
*
*
* Returns FALSE on failure.
* @throws ApacheException
*
*/
function apache_lookup_uri(string $filename): object
{
error_clear_last();
$safeResult = \apache_lookup_uri($filename);
if ($safeResult === false) {
throw ApacheException::createFromPhpError();
}
return $safeResult;
}
/**
* Fetches all HTTP request headers from the current request. Works in the
* Apache, FastCGI, CLI, and FPM webservers.
*
* @return array|false An associative array of all the HTTP headers in the current request.
*
*/
function apache_request_headers()
{
error_clear_last();
$safeResult = \apache_request_headers();
return $safeResult;
}
/**
* Fetch all HTTP response headers. Works in the
* Apache, FastCGI, CLI, and FPM webservers.
*
* @return array|false An array of all Apache response headers on success.
*
*/
function apache_response_headers()
{
error_clear_last();
$safeResult = \apache_response_headers();
return $safeResult;
}
/**
* apache_setenv sets the value of the Apache
* environment variable specified by
* variable.
*
* @param string $variable The environment variable that's being set.
* @param string $value The new variable value.
* @param bool $walk_to_top Whether to set the top-level variable available to all Apache layers.
* @throws ApacheException
*
*/
function apache_setenv(string $variable, string $value, bool $walk_to_top = false): void
{
error_clear_last();
$safeResult = \apache_setenv($variable, $value, $walk_to_top);
if ($safeResult === false) {
throw ApacheException::createFromPhpError();
}
}
/**
* Fetches all HTTP headers from the current request.
*
* This function is an alias for apache_request_headers.
* Please read the apache_request_headers
* documentation for more information on how this function works.
*
* @return array An associative array of all the HTTP headers in the current request.
*
*/
function getallheaders(): array
{
error_clear_last();
$safeResult = \getallheaders();
return $safeResult;
}
/**
* virtual is an Apache-specific function which
* is similar to &lt;!--#include virtual...--&gt; in
* mod_include.
* It performs an Apache sub-request. It is useful for including
* CGI scripts or .shtml files, or anything else that you would
* parse through Apache. Note that for a CGI script, the script
* must generate valid CGI headers. At the minimum that means it
* must generate a Content-Type header.
*
* To run the sub-request, all buffers are terminated and flushed to the
* browser, pending headers are sent too.
*
* @param string $uri The file that the virtual command will be performed on.
* @throws ApacheException
*
*/
function virtual(string $uri): void
{
error_clear_last();
$safeResult = \virtual($uri);
if ($safeResult === false) {
throw ApacheException::createFromPhpError();
}
}

View File

@@ -0,0 +1,112 @@
<?php
namespace Safe;
use Safe\Exceptions\ApcuException;
/**
* Retrieves cached information and meta-data from APC's data store.
*
* @param bool $limited If limited is TRUE, the
* return value will exclude the individual list of cache entries. This
* is useful when trying to optimize calls for statistics gathering.
* @return array Array of cached data (and meta-data)
* @throws ApcuException
*
*/
function apcu_cache_info(bool $limited = false): array
{
error_clear_last();
$safeResult = \apcu_cache_info($limited);
if ($safeResult === false) {
throw ApcuException::createFromPhpError();
}
return $safeResult;
}
/**
* apcu_cas updates an already existing integer value if the
* old parameter matches the currently stored value
* with the value of the new parameter.
*
* @param string $key The key of the value being updated.
* @param int $old The old value (the value currently stored).
* @param int $new The new value to update to.
* @throws ApcuException
*
*/
function apcu_cas(string $key, int $old, int $new): void
{
error_clear_last();
$safeResult = \apcu_cas($key, $old, $new);
if ($safeResult === false) {
throw ApcuException::createFromPhpError();
}
}
/**
* Decreases a stored integer value.
*
* @param string $key The key of the value being decreased.
* @param int $step The step, or value to decrease.
* @param bool|null $success Optionally pass the success or fail boolean value to
* this referenced variable.
* @param int $ttl TTL to use if the operation inserts a new value (rather than decrementing an existing one).
* @return int Returns the current value of key's value on success
* @throws ApcuException
*
*/
function apcu_dec(string $key, int $step = 1, ?bool &$success = null, int $ttl = 0): int
{
error_clear_last();
$safeResult = \apcu_dec($key, $step, $success, $ttl);
if ($safeResult === false) {
throw ApcuException::createFromPhpError();
}
return $safeResult;
}
/**
* Increases a stored number.
*
* @param string $key The key of the value being increased.
* @param int $step The step, or value to increase.
* @param bool|null $success Optionally pass the success or fail boolean value to
* this referenced variable.
* @param int $ttl TTL to use if the operation inserts a new value (rather than incrementing an existing one).
* @return int Returns the current value of key's value on success
* @throws ApcuException
*
*/
function apcu_inc(string $key, int $step = 1, ?bool &$success = null, int $ttl = 0): int
{
error_clear_last();
$safeResult = \apcu_inc($key, $step, $success, $ttl);
if ($safeResult === false) {
throw ApcuException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves APCu Shared Memory Allocation information.
*
* @param bool $limited When set to FALSE (default) apcu_sma_info will
* return a detailed information about each segment.
* @return array Array of Shared Memory Allocation data; FALSE on failure.
* @throws ApcuException
*
*/
function apcu_sma_info(bool $limited = false): array
{
error_clear_last();
$safeResult = \apcu_sma_info($limited);
if ($safeResult === false) {
throw ApcuException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,186 @@
<?php
namespace Safe;
use Safe\Exceptions\ArrayException;
/**
*
*
* @param array $array
* @param callable $callback The callback function to call to check each element, which must be
*
* boolcallback
* mixedvalue
* mixedkey
*
* If this function returns FALSE, FALSE is returned from
* array_all and the callback will not be called for
* further elements.
* @throws ArrayException
*
*/
function array_all(array $array, callable $callback): void
{
error_clear_last();
$safeResult = \array_all($array, $callback);
if ($safeResult === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* Creates an array by using the values from the
* keys array as keys and the values from the
* values array as the corresponding values.
*
* @param array $keys Array of keys to be used. Illegal values for key will be
* converted to string.
* @param array $values Array of values to be used
* @return array Returns the combined array.
*
*/
function array_combine(array $keys, array $values): array
{
error_clear_last();
$safeResult = \array_combine($keys, $values);
return $safeResult;
}
/**
* array_flip returns an array in flip
* order, i.e. keys from array become values and values
* from array become keys.
*
* Note that the values of array need to be valid
* keys, i.e. they need to be either int or
* string. A warning will be emitted if a value has the wrong
* type, and the key/value pair in question will not be included
* in the result.
*
* If a value has several occurrences, the latest key will be
* used as its value, and all others will be lost.
*
* @param array $array An array of key/value pairs to be flipped.
* @return array Returns the flipped array.
*
*/
function array_flip(array $array): array
{
error_clear_last();
$safeResult = \array_flip($array);
return $safeResult;
}
/**
* array_replace_recursive replaces the values of
* array with the same values from all the following
* arrays. If a key from the first array exists in the second array, its value
* will be replaced by the value from the second array. If the key exists in the
* second array, and not the first, it will be created in the first array.
* If a key only exists in the first array, it will be left as is.
* If several arrays are passed for replacement, they will be processed
* in order, the later array overwriting the previous values.
*
* array_replace_recursive is recursive : it will recurse into
* arrays and apply the same process to the inner value.
*
* When the value in the first array is scalar, it will be replaced
* by the value in the second array, may it be scalar or array.
* When the value in the first array and the second array
* are both arrays, array_replace_recursive will replace
* their respective value recursively.
*
* @param array $array The array in which elements are replaced.
* @param array $replacements Arrays from which elements will be extracted.
* @return array Returns an array.
*
*/
function array_replace_recursive(array $array, array ...$replacements): array
{
error_clear_last();
if ($replacements !== []) {
$safeResult = \array_replace_recursive($array, ...$replacements);
} else {
$safeResult = \array_replace_recursive($array);
}
return $safeResult;
}
/**
* array_replace creates a new array and assigns items into
* it for each key in each of the provided arrays. If a key appears in multiple
* input arrays, the value from the right-most input array will be used.
*
* array_replace does not process elements items recursively,
* it replaces the entire value for each key when it does a replacement.
*
* @param array $array The array in which elements are replaced.
* @param array $replacements Arrays from which elements will be extracted.
* Values from later arrays overwrite the previous values.
* @return array Returns an array.
*
*/
function array_replace(array $array, array ...$replacements): array
{
error_clear_last();
if ($replacements !== []) {
$safeResult = \array_replace($array, ...$replacements);
} else {
$safeResult = \array_replace($array);
}
return $safeResult;
}
/**
* Applies the user-defined callback function to each
* element of the array. This function will recurse
* into deeper arrays.
*
* @param array|object $array The input array.
* @param callable $callback Typically, callback takes on two parameters.
* The array parameter's value being the first, and
* the key/index second.
*
* If callback needs to be working with the
* actual values of the array, specify the first parameter of
* callback as a
* reference. Then,
* any changes made to those elements will be made in the
* original array itself.
* @param mixed $arg If the optional arg parameter is supplied,
* it will be passed as the third parameter to the
* callback.
* @return bool Always returns TRUE.
*
*/
function array_walk_recursive(&$array, callable $callback, $arg = null): bool
{
error_clear_last();
if ($arg !== null) {
$safeResult = \array_walk_recursive($array, $callback, $arg);
} else {
$safeResult = \array_walk_recursive($array, $callback);
}
return $safeResult;
}
/**
* This function shuffles (randomizes the order of the elements in) an array.
*
* @param array $array The array.
* @return bool Always returns TRUE.
*
*/
function shuffle(array &$array): bool
{
error_clear_last();
$safeResult = \shuffle($array);
return $safeResult;
}

View File

@@ -0,0 +1,120 @@
<?php
namespace Safe;
use Safe\Exceptions\Bzip2Exception;
/**
* Closes the given bzip2 file pointer.
*
* @param resource $bz The file pointer. It must be valid and must point to a file
* successfully opened by bzopen.
* @throws Bzip2Exception
*
*/
function bzclose($bz): void
{
error_clear_last();
$safeResult = \bzclose($bz);
if ($safeResult === false) {
throw Bzip2Exception::createFromPhpError();
}
}
/**
* This function is supposed to force a write of all buffered bzip2 data for the file pointer
* bz,
* but is implemented as null function in libbz2, and as such does nothing.
*
* @param resource $bz The file pointer. It must be valid and must point to a file
* successfully opened by bzopen.
* @throws Bzip2Exception
*
*/
function bzflush($bz): void
{
error_clear_last();
$safeResult = \bzflush($bz);
if ($safeResult === false) {
throw Bzip2Exception::createFromPhpError();
}
}
/**
* bzopen opens a bzip2 (.bz2) file for reading or
* writing.
*
* @param resource|string $file The name of the file to open, or an existing stream resource.
* @param string $mode The modes 'r' (read), and 'w' (write) are supported.
* Everything else will cause bzopen to return FALSE.
* @return resource If the open fails, bzopen returns FALSE, otherwise
* it returns a pointer to the newly opened file.
* @throws Bzip2Exception
*
*/
function bzopen($file, string $mode)
{
error_clear_last();
$safeResult = \bzopen($file, $mode);
if ($safeResult === false) {
throw Bzip2Exception::createFromPhpError();
}
return $safeResult;
}
/**
* bzread reads from the given bzip2 file pointer.
*
* Reading stops when length (uncompressed) bytes have
* been read or EOF is reached, whichever comes first.
*
* @param resource $bz The file pointer. It must be valid and must point to a file
* successfully opened by bzopen.
* @param int $length If not specified, bzread will read 1024
* (uncompressed) bytes at a time. A maximum of 8192
* uncompressed bytes will be read at a time.
* @return string Returns the uncompressed data.
* @throws Bzip2Exception
*
*/
function bzread($bz, int $length = 1024): string
{
error_clear_last();
$safeResult = \bzread($bz, $length);
if ($safeResult === false) {
throw Bzip2Exception::createFromPhpError();
}
return $safeResult;
}
/**
* bzwrite writes a string into the given bzip2 file
* stream.
*
* @param resource $bz The file pointer. It must be valid and must point to a file
* successfully opened by bzopen.
* @param string $data The written data.
* @param int|null $length If supplied, writing will stop after length
* (uncompressed) bytes have been written or the end of
* data is reached, whichever comes first.
* @return int Returns the number of bytes written.
* @throws Bzip2Exception
*
*/
function bzwrite($bz, string $data, ?int $length = null): int
{
error_clear_last();
if ($length !== null) {
$safeResult = \bzwrite($bz, $data, $length);
} else {
$safeResult = \bzwrite($bz, $data);
}
if ($safeResult === false) {
throw Bzip2Exception::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Safe;
use Safe\Exceptions\CalendarException;
/**
* Return the Julian Day for a Unix timestamp
* (seconds since 1.1.1970), or for the current day if no
* timestamp is given. Either way, the time is regarded
* as local time (not UTC).
*
* @param int|null $timestamp A unix timestamp to convert.
* @return int A julian day number as integer.
* @throws CalendarException
*
*/
function unixtojd(?int $timestamp = null): int
{
error_clear_last();
if ($timestamp !== null) {
$safeResult = \unixtojd($timestamp);
} else {
$safeResult = \unixtojd();
}
if ($safeResult === false) {
throw CalendarException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Safe;
use Safe\Exceptions\ClassobjException;
/**
* Creates an alias named alias
* based on the user defined class class.
* The aliased class is exactly the same as the original class.
*
* @param string $class The original class.
* @param string $alias The alias name for the class.
* @param bool $autoload Whether to autoload
* if the original class is not found.
* @throws ClassobjException
*
*/
function class_alias(string $class, string $alias, bool $autoload = true): void
{
error_clear_last();
$safeResult = \class_alias($class, $alias, $autoload);
if ($safeResult === false) {
throw ClassobjException::createFromPhpError();
}
}

View File

@@ -0,0 +1,196 @@
<?php
namespace Safe;
use Safe\Exceptions\ComException;
/**
* Generates a Globally Unique Identifier (GUID).
*
* A GUID is generated in the same way as DCE UUID's, except that the
* Microsoft convention is to enclose a GUID in curly braces.
*
* @return string Returns the GUID as a string.
* @throws ComException
*
*/
function com_create_guid(): string
{
error_clear_last();
$safeResult = \com_create_guid();
if ($safeResult === false) {
throw ComException::createFromPhpError();
}
return $safeResult;
}
/**
* Instructs COM to sink events generated by
* variant into the PHP object
* sink_object.
*
* Be careful how you use this feature; if you are doing something similar
* to the example below, then it doesn't really make sense to run it in a
* web server context.
*
* @param object $variant
* @param object $sink_object sink_object should be an instance of a class with
* methods named after those of the desired dispinterface; you may use
* com_print_typeinfo to help generate a template class
* for this purpose.
* @param mixed $sink_interface PHP will attempt to use the default dispinterface type specified by
* the typelibrary associated with variant, but
* you may override this choice by setting
* sink_interface to the name of the dispinterface
* that you want to use.
* @throws ComException
*
*/
function com_event_sink(object $variant, object $sink_object, $sink_interface = null): void
{
error_clear_last();
if ($sink_interface !== null) {
$safeResult = \com_event_sink($variant, $sink_object, $sink_interface);
} else {
$safeResult = \com_event_sink($variant, $sink_object);
}
if ($safeResult === false) {
throw ComException::createFromPhpError();
}
}
/**
* Loads a type-library and registers its constants in the engine, as though
* they were defined using define.
*
* Note that it is much more efficient to use the com.typelib-file php.ini setting to pre-load and
* register the constants, although not so flexible.
*
* If com.autoregister-typelib is turned on, then
* PHP will attempt to automatically register the constants associated with a
* COM object when you instantiate it. This depends on the interfaces
* provided by the COM object itself, and may not always be possible.
*
* @param string $typelib typelib can be one of the following:
*
*
*
* The filename of a .tlb file or the executable module
* that contains the type library.
*
*
*
*
* The type library GUID, followed by its version number, for example
* {00000200-0000-0010-8000-00AA006D2EA4},2,0.
*
*
*
*
* The type library name, e.g. Microsoft OLE DB ActiveX Data
* Objects 1.0 Library.
*
*
*
* PHP will attempt to resolve the type library in this order, as the
* process gets more and more expensive as you progress down the list;
* searching for the type library by name is handled by physically
* enumerating the registry until we find a match.
*
* The filename of a .tlb file or the executable module
* that contains the type library.
*
* The type library GUID, followed by its version number, for example
* {00000200-0000-0010-8000-00AA006D2EA4},2,0.
*
* The type library name, e.g. Microsoft OLE DB ActiveX Data
* Objects 1.0 Library.
* @param bool $case_insensitive The case_insensitive behaves inversely to
* the parameter $case_insensitive in the define
* function.
* @throws ComException
*
*/
function com_load_typelib(string $typelib, bool $case_insensitive = true): void
{
error_clear_last();
$safeResult = \com_load_typelib($typelib, $case_insensitive);
if ($safeResult === false) {
throw ComException::createFromPhpError();
}
}
/**
* The purpose of this function is to help generate a skeleton class for use
* as an event sink. You may also use it to generate a dump of any COM
* object, provided that it supports enough of the introspection interfaces,
* and that you know the name of the interface you want to display.
*
* @param object $variant variant should be either an instance of a COM
* object, or be the name of a typelibrary (which will be resolved according
* to the rules set out in com_load_typelib).
* @param null|string $dispatch_interface The name of an IDispatch descendant interface that you want to display.
* @param bool $display_sink If set to TRUE, the corresponding sink interface will be displayed
* instead.
* @throws ComException
*
*/
function com_print_typeinfo(object $variant, ?string $dispatch_interface = null, bool $display_sink = false): void
{
error_clear_last();
if ($display_sink !== false) {
$safeResult = \com_print_typeinfo($variant, $dispatch_interface, $display_sink);
} elseif ($dispatch_interface !== null) {
$safeResult = \com_print_typeinfo($variant, $dispatch_interface);
} else {
$safeResult = \com_print_typeinfo($variant);
}
if ($safeResult === false) {
throw ComException::createFromPhpError();
}
}
/**
* Converts variant from a VT_DATE
* (or similar) value into a Unix timestamp. This allows easier
* interopability between the Unix-ish parts of PHP and COM.
*
* @param object $variant The variant.
* @return int Returns a unix timestamp.
* @throws ComException
*
*/
function variant_date_to_timestamp(object $variant): int
{
error_clear_last();
$safeResult = \variant_date_to_timestamp($variant);
if ($safeResult === null) {
throw ComException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the value of value rounded to
* decimals decimal places.
*
* @param mixed $value The variant.
* @param int $decimals Number of decimal places.
* @return mixed Returns the rounded value.
* @throws ComException
*
*/
function variant_round($value, int $decimals)
{
error_clear_last();
$safeResult = \variant_round($value, $decimals);
if ($safeResult === null) {
throw ComException::createFromPhpError();
}
return $safeResult;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,470 @@
<?php
namespace Safe;
use Safe\Exceptions\CurlException;
/**
* Copies a cURL handle keeping the same preferences.
*
* @param \CurlHandle $handle A cURL handle returned by
* curl_init.
* @return \CurlHandle Returns a new cURL handle.
* @throws CurlException
*
*/
function curl_copy_handle(\CurlHandle $handle): \CurlHandle
{
error_clear_last();
$safeResult = \curl_copy_handle($handle);
if ($safeResult === false) {
throw CurlException::createFromPhpError($handle);
}
return $safeResult;
}
/**
* This function URL encodes the given string according to RFC 3986.
*
* @param \CurlHandle $handle A cURL handle returned by
* curl_init.
* @param string $string The string to be encoded.
* @return string Returns escaped string.
* @throws CurlException
*
*/
function curl_escape(\CurlHandle $handle, string $string): string
{
error_clear_last();
$safeResult = \curl_escape($handle, $string);
if ($safeResult === false) {
throw CurlException::createFromPhpError($handle);
}
return $safeResult;
}
/**
* Execute the given cURL session.
*
* This function should be called after initializing a cURL session and all
* the options for the session are set.
*
* @param \CurlHandle $handle A cURL handle returned by
* curl_init.
* @return bool|string On success, this function flushes the result directly to the
* stdout and returns TRUE.
* However, if the CURLOPT_RETURNTRANSFER
* option is set, it will return
* the result on success.
* @throws CurlException
*
*/
function curl_exec(\CurlHandle $handle)
{
error_clear_last();
$safeResult = \curl_exec($handle);
if ($safeResult === false) {
throw CurlException::createFromPhpError($handle);
}
return $safeResult;
}
/**
* Gets information about the last transfer.
*
* @param \CurlHandle $handle A cURL handle returned by
* curl_init.
* @param int|null $option One of the CURLINFO_* constants.
* @return mixed If option is given, returns its value.
* Otherwise, returns an associative array with the following elements
* (which correspond to option):
*
*
*
* "url"
*
*
*
*
* "content_type"
*
*
*
*
* "http_code"
*
*
*
*
* "header_size"
*
*
*
*
* "request_size"
*
*
*
*
* "filetime"
*
*
*
*
* "ssl_verify_result"
*
*
*
*
* "redirect_count"
*
*
*
*
* "total_time"
*
*
*
*
* "namelookup_time"
*
*
*
*
* "connect_time"
*
*
*
*
* "pretransfer_time"
*
*
*
*
* "size_upload"
*
*
*
*
* "size_download"
*
*
*
*
* "speed_download"
*
*
*
*
* "speed_upload"
*
*
*
*
* "download_content_length"
*
*
*
*
* "upload_content_length"
*
*
*
*
* "starttransfer_time"
*
*
*
*
* "redirect_time"
*
*
*
*
* "certinfo"
*
*
*
*
* "primary_ip"
*
*
*
*
* "primary_port"
*
*
*
*
* "local_ip"
*
*
*
*
* "local_port"
*
*
*
*
* "redirect_url"
*
*
*
*
* "request_header" (This is only set if the CURLINFO_HEADER_OUT
* is set by a previous call to curl_setopt)
*
*
*
*
* "posttransfer_time_us" (Available as of PHP 8.4.0 and cURL 8.10.0)
*
*
*
* Note that private data is not included in the associative array and must be retrieved individually with the CURLINFO_PRIVATE option.
* @throws CurlException
*
*/
function curl_getinfo(\CurlHandle $handle, ?int $option = null)
{
error_clear_last();
if ($option !== null) {
$safeResult = \curl_getinfo($handle, $option);
} else {
$safeResult = \curl_getinfo($handle);
}
if ($safeResult === false) {
throw CurlException::createFromPhpError($handle);
}
return $safeResult;
}
/**
* Initializes a new session and returns a cURL handle.
*
* @param null|string $url If provided, the CURLOPT_URL option will be set
* to its value. This can be set manually using the
* curl_setopt function.
*
* The file protocol is disabled by cURL if
* open_basedir is set.
* @return \CurlHandle Returns a cURL handle on success.
* @throws CurlException
*
*/
function curl_init(?string $url = null): \CurlHandle
{
error_clear_last();
if ($url !== null) {
$safeResult = \curl_init($url);
} else {
$safeResult = \curl_init();
}
if ($safeResult === false) {
throw CurlException::createFromPhpError();
}
return $safeResult;
}
/**
* Ask the multi handle if there are any messages or information from the individual transfers.
* Messages may include information such as an error code from the transfer or just the fact
* that a transfer is completed.
*
* Repeated calls to this function will return a new result each time, until a FALSE is returned
* as a signal that there is no more to get at this point. The integer pointed to with
* queued_messages will contain the number of remaining messages after this
* function was called.
*
* @param \CurlMultiHandle $multi_handle A cURL multi handle returned by
* curl_multi_init.
* @param int|null $queued_messages Number of messages that are still in the queue
* @return array On success, returns an associative array for the message.
*
*
* Contents of the returned array
*
*
*
* Key:
* Value:
*
*
*
*
* msg
* The CURLMSG_DONE constant. Other return values
* are currently not available.
*
*
* result
* One of the CURLE_* constants. If everything is
* OK, the CURLE_OK will be the result.
*
*
* handle
* Resource of type curl indicates the handle which it concerns.
*
*
*
*
* @throws CurlException
*
*/
function curl_multi_info_read(\CurlMultiHandle $multi_handle, ?int &$queued_messages = null): array
{
error_clear_last();
$safeResult = \curl_multi_info_read($multi_handle, $queued_messages);
if ($safeResult === false) {
throw CurlException::createFromPhpError($multi_handle);
}
return $safeResult;
}
/**
* Allows the processing of multiple cURL handles asynchronously.
*
* @return \CurlMultiHandle Returns a cURL multi handle.
*
*/
function curl_multi_init(): \CurlMultiHandle
{
error_clear_last();
$safeResult = \curl_multi_init();
return $safeResult;
}
/**
* Sets an option on the given cURL multi handle.
*
* @param \CurlMultiHandle $multi_handle A cURL multi handle returned by
* curl_multi_init.
* @param int $option One of the CURLMOPT_* constants.
* @param mixed $value The value to be set on option.
* See the description of the
* CURLMOPT_* constants
* for details on the type of values each constant expects.
* @throws CurlException
*
*/
function curl_multi_setopt(\CurlMultiHandle $multi_handle, int $option, $value): void
{
error_clear_last();
$safeResult = \curl_multi_setopt($multi_handle, $option, $value);
if ($safeResult === false) {
throw CurlException::createFromPhpError($multi_handle);
}
}
/**
* Sets an option on the given cURL session handle.
*
* @param \CurlHandle $handle A cURL handle returned by
* curl_init.
* @param int $option The CURLOPT_* option to set.
* @param mixed $value The value to be set on option.
* See the description of the
* CURLOPT_* constants
* for details on the type of values each constant expects.
* @throws CurlException
*
*/
function curl_setopt(\CurlHandle $handle, int $option, $value): void
{
error_clear_last();
$safeResult = \curl_setopt($handle, $option, $value);
if ($safeResult === false) {
throw CurlException::createFromPhpError($handle);
}
}
/**
* Return an integer containing the last share curl error number.
*
* @param \CurlShareHandle $share_handle A cURL share handle returned by
* curl_share_init.
* @return int Returns an integer containing the last share curl error number.
*
*/
function curl_share_errno(\CurlShareHandle $share_handle): int
{
error_clear_last();
$safeResult = \curl_share_errno($share_handle);
return $safeResult;
}
/**
* Sets an option on the given cURL share handle.
*
* @param \CurlShareHandle $share_handle A cURL share handle returned by
* curl_share_init.
* @param int $option One of the CURLSHOPT_* constants.
* @param mixed $value One of the CURL_LOCK_DATA_* constants.
* @throws CurlException
*
*/
function curl_share_setopt(\CurlShareHandle $share_handle, int $option, $value): void
{
error_clear_last();
$safeResult = \curl_share_setopt($share_handle, $option, $value);
if ($safeResult === false) {
throw CurlException::createFromPhpError($share_handle);
}
}
/**
* This function decodes the given URL encoded string.
*
* @param \CurlHandle $handle A cURL handle returned by
* curl_init.
* @param string $string The URL encoded string to be decoded.
* @return string Returns decoded string.
* @throws CurlException
*
*/
function curl_unescape(\CurlHandle $handle, string $string): string
{
error_clear_last();
$safeResult = \curl_unescape($handle, $string);
if ($safeResult === false) {
throw CurlException::createFromPhpError($handle);
}
return $safeResult;
}
/**
* Available if built against libcurl &gt;= 7.62.0.
*
* Some protocols have "connection upkeep" mechanisms.
* These mechanisms usually send some traffic on existing connections in order to keep them alive;
* this can prevent connections from being closed due to overzealous firewalls, for example.
*
* Connection upkeep is currently available only for HTTP/2 connections.
* A small amount of traffic is usually sent to keep a connection alive.
* HTTP/2 maintains its connection by sending a HTTP/2 PING frame.
*
* @param \CurlHandle $handle A cURL handle returned by
* curl_init.
* @throws CurlException
*
*/
function curl_upkeep(\CurlHandle $handle): void
{
error_clear_last();
$safeResult = \curl_upkeep($handle);
if ($safeResult === false) {
throw CurlException::createFromPhpError($handle);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,160 @@
<?php
namespace Safe;
use Safe\Exceptions\DirException;
/**
* Changes PHP's current directory to
* directory.
*
* @param string $directory The new current directory
* @throws DirException
*
*/
function chdir(string $directory): void
{
error_clear_last();
$safeResult = \chdir($directory);
if ($safeResult === false) {
throw DirException::createFromPhpError();
}
}
/**
* Changes the root directory of the current process to
* directory, and changes the current
* working directory to "/".
*
* This function is only available to GNU and BSD systems, and
* only when using the CLI, CGI or Embed SAPI. Also, this function
* requires root privileges.
*
* Calling this function does not change the values of the __DIR__
* and __FILE__ magic constants.
*
* @param string $directory The path to change the root directory to.
* @throws DirException
*
*/
function chroot(string $directory): void
{
error_clear_last();
$safeResult = \chroot($directory);
if ($safeResult === false) {
throw DirException::createFromPhpError();
}
}
/**
* A pseudo-object-oriented mechanism for reading a directory. The
* given directory is opened.
*
* @param string $directory Directory to open
* @param null|resource $context A context stream
* resource.
* @return \Directory Returns an instance of Directory, or FALSE in case of error.
* @throws DirException
*
*/
function dir(string $directory, $context = null): \Directory
{
error_clear_last();
if ($context !== null) {
$safeResult = \dir($directory, $context);
} else {
$safeResult = \dir($directory);
}
if ($safeResult === false) {
throw DirException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets the current working directory.
*
* @return non-empty-string Returns the current working directory on success.
*
* On some Unix variants, getcwd will return
* FALSE if any one of the parent directories does not have the
* readable or search mode set, even if the current directory
* does. See chmod for more information on
* modes and permissions.
* @throws DirException
*
*/
function getcwd(): string
{
error_clear_last();
$safeResult = \getcwd();
if ($safeResult === false) {
throw DirException::createFromPhpError();
}
return $safeResult;
}
/**
* Opens up a directory handle to be used in subsequent
* closedir, readdir, and
* rewinddir calls.
*
* @param string $directory The directory path that is to be opened
* @param null|resource $context For a description of the context parameter,
* refer to the streams section of
* the manual.
* @return resource Returns a directory handle resource on success
* @throws DirException
*
*/
function opendir(string $directory, $context = null)
{
error_clear_last();
if ($context !== null) {
$safeResult = \opendir($directory, $context);
} else {
$safeResult = \opendir($directory);
}
if ($safeResult === false) {
throw DirException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns an array of files and directories from the
* directory.
*
* @param string $directory The directory that will be scanned.
* @param SCANDIR_SORT_ASCENDING|SCANDIR_SORT_DESCENDING|SCANDIR_SORT_NONE $sorting_order By default, the sorted order is alphabetical in ascending order. If
* the optional sorting_order is set to
* SCANDIR_SORT_DESCENDING, then the sort order is
* alphabetical in descending order. If it is set to
* SCANDIR_SORT_NONE then the result is unsorted.
* @param null|resource $context For a description of the context parameter,
* refer to the streams section of
* the manual.
* @return list Returns an array of filenames on success. If directory is not a directory, then
* boolean FALSE is returned, and an error of level
* E_WARNING is generated.
* @throws DirException
*
*/
function scandir(string $directory, int $sorting_order = SCANDIR_SORT_ASCENDING, $context = null): array
{
error_clear_last();
if ($context !== null) {
$safeResult = \scandir($directory, $sorting_order, $context);
} else {
$safeResult = \scandir($directory, $sorting_order);
}
if ($safeResult === false) {
throw DirException::createFromPhpError();
}
return $safeResult;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,82 @@
<?php
namespace Safe;
use Safe\Exceptions\ErrorfuncException;
/**
* Sends an error message to the web server's error log or to a file.
*
* @param string $message The error message that should be logged.
* @param 0|1|2|3|4 $message_type Says where the error should go. The possible message types are as
* follows:
*
*
* error_log log types
*
*
*
* 0
*
* message is sent to PHP's system logger, using
* the Operating System's system logging mechanism or a file, depending
* on what the error_log
* configuration directive is set to. This is the default option.
*
*
*
* 1
*
* message is sent by email to the address in
* the destination parameter. This is the only
* message type where the fourth parameter,
* additional_headers is used.
*
*
*
* 2
*
* No longer an option.
*
*
*
* 3
*
* message is appended to the file
* destination. A newline is not automatically
* added to the end of the message string.
*
*
*
* 4
*
* message is sent directly to the SAPI logging
* handler.
*
*
*
*
*
* @param null|string $destination The destination. Its meaning depends on the
* message_type parameter as described above.
* @param null|string $additional_headers The extra headers. It's used when the message_type
* parameter is set to 1.
* This message type uses the same internal function as
* mail does.
* @throws ErrorfuncException
*
*/
function error_log(string $message, int $message_type = 0, ?string $destination = null, ?string $additional_headers = null): void
{
error_clear_last();
if ($additional_headers !== null) {
$safeResult = \error_log($message, $message_type, $destination, $additional_headers);
} elseif ($destination !== null) {
$safeResult = \error_log($message, $message_type, $destination);
} else {
$safeResult = \error_log($message, $message_type);
}
if ($safeResult === false) {
throw ErrorfuncException::createFromPhpError();
}
}

View File

@@ -0,0 +1,278 @@
<?php
namespace Safe;
use Safe\Exceptions\ExecException;
/**
* exec executes the given
* command.
*
* @param string $command The command that will be executed.
* @param array|null $output If the output argument is present, then the
* specified array will be filled with every line of output from the
* command. Trailing whitespace, such as \n, is not
* included in this array. Note that if the array already contains some
* elements, exec will append to the end of the array.
* If you do not want the function to append elements, call
* unset on the array before passing it to
* exec.
* @param int|null $result_code If the result_code argument is present
* along with the output argument, then the
* return status of the executed command will be written to this
* variable.
* @return string The last line from the result of the command. If you need to execute a
* command and have all the data from the command passed directly back without
* any interference, use the passthru function.
*
* Returns FALSE on failure.
*
* To get the output of the executed command, be sure to set and use the
* output parameter.
* @throws ExecException
*
*/
function exec(string $command, ?array &$output = null, ?int &$result_code = null): string
{
error_clear_last();
$safeResult = \exec($command, $output, $result_code);
if ($safeResult === false) {
throw ExecException::createFromPhpError();
}
return $safeResult;
}
/**
* The passthru function is similar to the
* exec function in that it executes a
* command. This function
* should be used in place of exec or
* system when the output from the Unix command
* is binary data which needs to be passed directly back to the
* browser. A common use for this is to execute something like the
* pbmplus utilities that can output an image stream directly. By
* setting the Content-type to image/gif and
* then calling a pbmplus program to output a gif, you can create
* PHP scripts that output images directly.
*
* @param string $command The command that will be executed.
* @param int|null $result_code If the result_code argument is present, the
* return status of the Unix command will be placed here.
* @throws ExecException
*
*/
function passthru(string $command, ?int &$result_code = null): void
{
error_clear_last();
$safeResult = \passthru($command, $result_code);
if ($safeResult === false) {
throw ExecException::createFromPhpError();
}
}
/**
* proc_close is similar to pclose
* except that it only works on processes opened by
* proc_open.
* proc_close waits for the process to terminate, and
* returns its exit code. Open pipes to that process are closed
* when this function is called, in
* order to avoid a deadlock - the child process may not be able to exit
* while the pipes are open.
*
* @param resource $process The proc_open resource that will
* be closed.
* @return int Returns the termination status of the process that was run.
* @throws ExecException
*
*/
function proc_close($process): int
{
error_clear_last();
$safeResult = \proc_close($process);
if ($safeResult === -1) {
throw ExecException::createFromPhpError();
}
return $safeResult;
}
/**
* proc_nice changes the priority of the current
* process by the amount specified in priority. A
* positive priority will lower the priority of the
* current process, whereas a negative priority
* will raise the priority.
*
* proc_nice is not related to
* proc_open and its associated functions in any way.
*
* @param int $priority The new priority value, the value of this may differ on platforms.
*
* On Unix, a low value, such as -20 means high priority
* whereas positive values have a lower priority.
*
* For Windows the priority parameter has the
* following meaning:
* @throws ExecException
*
*/
function proc_nice(int $priority): void
{
error_clear_last();
$safeResult = \proc_nice($priority);
if ($safeResult === false) {
throw ExecException::createFromPhpError();
}
}
/**
* proc_open is similar to popen
* but provides a much greater degree of control over the program execution.
*
* @param string $command The commandline to execute as string. Special characters have to be properly escaped,
* and proper quoting has to be applied.
*
* As of PHP 7.4.0, command may be passed as array of command parameters.
* In this case the process will be opened directly (without going through a shell)
* and PHP will take care of any necessary argument escaping.
*
* On Windows, the argument escaping of the array elements assumes that the
* command line parsing of the executed command is compatible with the parsing
* of command line arguments done by the VC runtime.
* @param array $descriptor_spec An indexed array where the key represents the descriptor number and the
* value represents how PHP will pass that descriptor to the child
* process. 0 is stdin, 1 is stdout, while 2 is stderr.
*
* Each element can be:
*
* An array describing the pipe to pass to the process. The first
* element is the descriptor type and the second element is an option for
* the given type. Valid types are pipe (the second
* element is either r to pass the read end of the pipe
* to the process, or w to pass the write end) and
* file (the second element is a filename).
* Note that anything else than w is treated like r.
*
*
* A stream resource representing a real file descriptor (e.g. opened file,
* a socket, STDIN).
*
*
*
* The file descriptor numbers are not limited to 0, 1 and 2 - you may
* specify any valid file descriptor number and it will be passed to the
* child process. This allows your script to interoperate with other
* scripts that run as "co-processes". In particular, this is useful for
* passing passphrases to programs like PGP, GPG and openssl in a more
* secure manner. It is also useful for reading status information
* provided by those programs on auxiliary file descriptors.
* @param null|resource[] $pipes Will be set to an indexed array of file pointers that correspond to
* PHP's end of any pipes that are created.
* @param null|string $cwd The initial working dir for the command. This must be an
* absolute directory path, or NULL
* if you want to use the default value (the working dir of the current
* PHP process)
* @param array|null $env_vars An array with the environment variables for the command that will be
* run, or NULL to use the same environment as the current PHP process
* @param array|null $options Allows you to specify additional options. Currently supported options
* include:
*
*
* suppress_errors (windows only): suppresses errors
* generated by this function when it's set to TRUE
*
*
* bypass_shell (windows only): bypass
* cmd.exe shell when set to TRUE
*
*
* blocking_pipes (windows only): force
* blocking pipes when set to TRUE
*
*
* create_process_group (windows only): allow the
* child process to handle CTRL events when set to TRUE
*
*
* create_new_console (windows only): the new process
* has a new console, instead of inheriting its parent's console
*
*
* @return resource Returns a resource representing the process, which should be freed using
* proc_close when you are finished with it. On failure
* returns FALSE.
* @throws ExecException
*
*/
function proc_open(string $command, array $descriptor_spec, ?array &$pipes, ?string $cwd = null, ?array $env_vars = null, ?array $options = null)
{
error_clear_last();
if ($options !== null) {
$safeResult = \proc_open($command, $descriptor_spec, $pipes, $cwd, $env_vars, $options);
} elseif ($env_vars !== null) {
$safeResult = \proc_open($command, $descriptor_spec, $pipes, $cwd, $env_vars);
} elseif ($cwd !== null) {
$safeResult = \proc_open($command, $descriptor_spec, $pipes, $cwd);
} else {
$safeResult = \proc_open($command, $descriptor_spec, $pipes);
}
if ($safeResult === false) {
throw ExecException::createFromPhpError();
}
return $safeResult;
}
/**
* This function is identical to the backtick operator.
*
* @param string $command The command that will be executed.
* @return null|string A string containing the output from the executed command or NULL if an error occurs or the command produces no output.
* @throws ExecException
*
*/
function shell_exec(string $command): ?string
{
error_clear_last();
$safeResult = \shell_exec($command);
if ($safeResult === false) {
throw ExecException::createFromPhpError();
}
return $safeResult;
}
/**
* system is just like the C version of the
* function in that it executes the given
* command and outputs the result.
*
* The system call also tries to automatically
* flush the web server's output buffer after each line of output if
* PHP is running as a server module.
*
* If you need to execute a command and have all the data from the
* command passed directly back without any interference, use the
* passthru function.
*
* @param string $command The command that will be executed.
* @param int|null $result_code If the result_code argument is present, then the
* return status of the executed command will be written to this
* variable.
* @return string Returns the last line of the command output on success.
* @throws ExecException
*
*/
function system(string $command, ?int &$result_code = null): string
{
error_clear_last();
$safeResult = \system($command, $result_code);
if ($safeResult === false) {
throw ExecException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Safe;
use Safe\Exceptions\FileinfoException;
/**
* This function closes the instance opened by finfo_open.
*
* @param \finfo $finfo An finfo instance, returned by finfo_open.
* @throws FileinfoException
*
*/
function finfo_close(\finfo $finfo): void
{
error_clear_last();
$safeResult = \finfo_close($finfo);
if ($safeResult === false) {
throw FileinfoException::createFromPhpError();
}
}
/**
* Procedural style
*
* Object-oriented style (constructor):
*
* This function opens a magic database and returns its instance.
*
* @param int $flags One or disjunction of more Fileinfo
* constants.
* @param null|string $magic_database Name of a magic database file, usually something like
* /path/to/magic.mime. If not specified, the
* MAGIC environment variable is used. If the
* environment variable isn't set, then PHP's bundled magic database will
* be used.
*
* Passing NULL or an empty string will be equivalent to the default
* value.
* @return \finfo (Procedural style only)
* Returns an finfo instance on success.
* @throws FileinfoException
*
*/
function finfo_open(int $flags = FILEINFO_NONE, ?string $magic_database = null): \finfo
{
error_clear_last();
if ($magic_database !== null) {
$safeResult = \finfo_open($flags, $magic_database);
} else {
$safeResult = \finfo_open($flags);
}
if ($safeResult === false) {
throw FileinfoException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the MIME content type for a file as determined by using
* information from the magic.mime file.
*
* @param resource|string $filename Path to the tested file.
* @return string Returns the content type in MIME format, like
* text/plain or application/octet-stream.
* @throws FileinfoException
*
*/
function mime_content_type($filename): string
{
error_clear_last();
$safeResult = \mime_content_type($filename);
if ($safeResult === false) {
throw FileinfoException::createFromPhpError();
}
return $safeResult;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
<?php
namespace Safe;
use Safe\Exceptions\FilterException;
/**
* This function is useful for retrieving many values without
* repetitively calling filter_input.
*
* @param int $type
* @param array|int $options
* @param bool $add_empty
* @return array|null
* @throws FilterException
*
*/
function filter_input_array(int $type, $options = FILTER_DEFAULT, bool $add_empty = true): ?array
{
error_clear_last();
$safeResult = \filter_input_array($type, $options, $add_empty);
if ($safeResult === false) {
throw FilterException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param array $array
* @param mixed $options
* @param bool $add_empty Add missing keys as NULL to the return value.
* @return array|null An array containing the values of the requested variables on success. An array value will be FALSE if the filter fails, or NULL if
* the variable is not set.
* @throws FilterException
*
*/
function filter_var_array(array $array, $options = FILTER_DEFAULT, bool $add_empty = true): ?array
{
error_clear_last();
$safeResult = \filter_var_array($array, $options, $add_empty);
if ($safeResult === false) {
throw FilterException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Safe;
use Safe\Exceptions\FpmException;
/**
* This function flushes all response data to the client and finishes the
* request. This allows for time consuming tasks to be performed without
* leaving the connection to the client open.
*
* @throws FpmException
*
*/
function fastcgi_finish_request(): void
{
error_clear_last();
$safeResult = \fastcgi_finish_request();
if ($safeResult === false) {
throw FpmException::createFromPhpError();
}
}
/**
* This function returns the full current FPM pool status as an associative array. It always
* returns the full status, including per-process status information. See the
* FPM status page guide for further
* details.
*
* Note that this function will only be defined if FPM is being used to serve the script.
*
* @return array{pool: string, process-manager: 'dynamic'|'ondemand'|'static', start-time: int, start-since: int, accepted-conn: int, listen-queue: int, max-listen-queue: int, listen-queue-len: int, idle-processes: int, active-processes: int, total-processes: int, max-active-processes: int, max-children-reached: 0|1, slow-requests: int, procs: array} Associative array containing the full FPM pool status.
* @throws FpmException
*
*/
function fpm_get_status(): array
{
error_clear_last();
$safeResult = \fpm_get_status();
if ($safeResult === false) {
throw FpmException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,598 @@
<?php
namespace Safe;
use Safe\Exceptions\FtpException;
/**
* Sends an ALLO command to the remote FTP server to
* allocate space for a file to be uploaded.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param int $size The number of bytes to allocate.
* @param null|string $response A textual representation of the servers response will be returned by
* reference in response if a variable is provided.
* @throws FtpException
*
*/
function ftp_alloc(\FTP\Connection $ftp, int $size, ?string &$response = null): void
{
error_clear_last();
$safeResult = \ftp_alloc($ftp, $size, $response);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
*
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $remote_filename
* @param string $local_filename
* @param FTP_ASCII|FTP_BINARY $mode
* @throws FtpException
*
*/
function ftp_append(\FTP\Connection $ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY): void
{
error_clear_last();
$safeResult = \ftp_append($ftp, $remote_filename, $local_filename, $mode);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* Changes to the parent directory.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @throws FtpException
*
*/
function ftp_cdup(\FTP\Connection $ftp): void
{
error_clear_last();
$safeResult = \ftp_cdup($ftp);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* Changes the current directory to the specified one.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $directory The target directory.
* @throws FtpException
*
*/
function ftp_chdir(\FTP\Connection $ftp, string $directory): void
{
error_clear_last();
$safeResult = \ftp_chdir($ftp, $directory);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* Sets the permissions on the specified remote file to
* permissions.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param int $permissions The new permissions, given as an octal value.
* @param string $filename The remote file.
* @return int Returns the new file permissions on success.
* @throws FtpException
*
*/
function ftp_chmod(\FTP\Connection $ftp, int $permissions, string $filename): int
{
error_clear_last();
$safeResult = \ftp_chmod($ftp, $permissions, $filename);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* ftp_close closes the given link identifier
* and releases the resource.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @throws FtpException
*
*/
function ftp_close(\FTP\Connection $ftp): void
{
error_clear_last();
$safeResult = \ftp_close($ftp);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* ftp_connect opens an FTP connection to the
* specified hostname.
*
* @param string $hostname The FTP server address. This parameter shouldn't have any trailing
* slashes and shouldn't be prefixed with ftp://.
* @param int $port This parameter specifies an alternate port to connect to. If it is
* omitted or set to zero, then the default FTP port, 21, will be used.
* @param int $timeout This parameter specifies the timeout in seconds for all subsequent network operations.
* If omitted, the default value is 90 seconds. The timeout can be changed and
* queried at any time with ftp_set_option and
* ftp_get_option.
* @return \FTP\Connection Returns an FTP\Connection instance on success.
* @throws FtpException
*
*/
function ftp_connect(string $hostname, int $port = 21, int $timeout = 90): \FTP\Connection
{
error_clear_last();
$safeResult = \ftp_connect($hostname, $port, $timeout);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* ftp_delete deletes the file specified by
* filename from the FTP server.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $filename The file to delete.
* @throws FtpException
*
*/
function ftp_delete(\FTP\Connection $ftp, string $filename): void
{
error_clear_last();
$safeResult = \ftp_delete($ftp, $filename);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* ftp_fget retrieves remote_filename
* from the FTP server, and writes it to the given file pointer.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param resource $stream An open file pointer in which we store the data.
* @param string $remote_filename The remote file path.
* @param FTP_ASCII|FTP_BINARY $mode The transfer mode. Must be either FTP_ASCII or
* FTP_BINARY.
* @param int $offset The position in the remote file to start downloading from.
* @throws FtpException
*
*/
function ftp_fget(\FTP\Connection $ftp, $stream, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): void
{
error_clear_last();
$safeResult = \ftp_fget($ftp, $stream, $remote_filename, $mode, $offset);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* ftp_fput uploads the data from a file pointer
* to a remote file on the FTP server.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $remote_filename The remote file path.
* @param resource $stream An open file pointer on the local file. Reading stops at end of file.
* @param FTP_ASCII|FTP_BINARY $mode The transfer mode. Must be either FTP_ASCII or
* FTP_BINARY.
* @param int $offset The position in the remote file to start uploading to.
* @throws FtpException
*
*/
function ftp_fput(\FTP\Connection $ftp, string $remote_filename, $stream, int $mode = FTP_BINARY, int $offset = 0): void
{
error_clear_last();
$safeResult = \ftp_fput($ftp, $remote_filename, $stream, $mode, $offset);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* ftp_get retrieves a remote file from the FTP server,
* and saves it into a local file.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $local_filename The local file path (will be overwritten if the file already exists).
* @param string $remote_filename The remote file path.
* @param FTP_ASCII|FTP_BINARY $mode The transfer mode. Must be either FTP_ASCII or
* FTP_BINARY.
* @param int $offset The position in the remote file to start downloading from.
* @throws FtpException
*
*/
function ftp_get(\FTP\Connection $ftp, string $local_filename, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): void
{
error_clear_last();
$safeResult = \ftp_get($ftp, $local_filename, $remote_filename, $mode, $offset);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* Logs in to the given FTP connection.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $username The username (USER).
* @param string $password The password (PASS).
* @throws FtpException
*
*/
function ftp_login(\FTP\Connection $ftp, string $username, string $password): void
{
error_clear_last();
$safeResult = \ftp_login($ftp, $username, $password);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* Creates the specified directory on the FTP server.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $directory The name of the directory that will be created.
* @return string Returns the newly created directory name on success.
* @throws FtpException
*
*/
function ftp_mkdir(\FTP\Connection $ftp, string $directory): string
{
error_clear_last();
$safeResult = \ftp_mkdir($ftp, $directory);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $directory The directory to be listed.
* @return array Returns an array of arrays with file infos from the specified directory on success.
* @throws FtpException
*
*/
function ftp_mlsd(\FTP\Connection $ftp, string $directory): array
{
error_clear_last();
$safeResult = \ftp_mlsd($ftp, $directory);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* ftp_nb_get retrieves a remote file from the FTP server,
* and saves it into a local file.
*
* The difference between this function and ftp_get is that
* this function retrieves the file asynchronously, so your program can perform
* other operations while the file is being downloaded.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $local_filename The local file path (will be overwritten if the file already exists).
* @param string $remote_filename The remote file path.
* @param FTP_ASCII|FTP_BINARY $mode The transfer mode. Must be either FTP_ASCII or
* FTP_BINARY.
* @param int $offset The position in the remote file to start downloading from.
* @return int Returns FTP_FAILED or FTP_FINISHED
* or FTP_MOREDATA to open the local file.
* @throws FtpException
*
*/
function ftp_nb_get(\FTP\Connection $ftp, string $local_filename, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): int
{
error_clear_last();
$safeResult = \ftp_nb_get($ftp, $local_filename, $remote_filename, $mode, $offset);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* ftp_nb_put stores a local file on the FTP server.
*
* The difference between this function and the ftp_put
* is that this function uploads the file asynchronously, so your program can
* perform other operations while the file is being uploaded.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $remote_filename The remote file path.
* @param string $local_filename The local file path.
* @param FTP_ASCII|FTP_BINARY $mode The transfer mode. Must be either FTP_ASCII or
* FTP_BINARY.
* @param int $offset The position in the remote file to start uploading to.
* @return int Returns FTP_FAILED or FTP_FINISHED
* or FTP_MOREDATA to open the local file.
* @throws FtpException
*
*/
function ftp_nb_put(\FTP\Connection $ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY, int $offset = 0): int
{
error_clear_last();
$safeResult = \ftp_nb_put($ftp, $remote_filename, $local_filename, $mode, $offset);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $directory The directory to be listed. This parameter can also include arguments, eg.
* ftp_nlist($ftp, "-la /your/dir");.
* Note that this parameter isn't escaped so there may be some issues with
* filenames containing spaces and other characters.
* @return array Returns an array of filenames from the specified directory on success.
* @throws FtpException
*
*/
function ftp_nlist(\FTP\Connection $ftp, string $directory): array
{
error_clear_last();
$safeResult = \ftp_nlist($ftp, $directory);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* ftp_pasv turns on or off passive mode. In
* passive mode, data connections are initiated by the client,
* rather than by the server.
* It may be needed if the client is behind firewall.
*
* Please note that ftp_pasv can only be called after a
* successful login or otherwise it will fail.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param bool $enable If TRUE, the passive mode is turned on, else it's turned off.
* @throws FtpException
*
*/
function ftp_pasv(\FTP\Connection $ftp, bool $enable): void
{
error_clear_last();
$safeResult = \ftp_pasv($ftp, $enable);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* ftp_put stores a local file on the FTP server.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $remote_filename The remote file path.
* @param string $local_filename The local file path.
* @param FTP_ASCII|FTP_BINARY $mode The transfer mode. Must be either FTP_ASCII or
* FTP_BINARY.
* @param int $offset The position in the remote file to start uploading to.
* @throws FtpException
*
*/
function ftp_put(\FTP\Connection $ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY, int $offset = 0): void
{
error_clear_last();
$safeResult = \ftp_put($ftp, $remote_filename, $local_filename, $mode, $offset);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
*
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @return string Returns the current directory name.
* @throws FtpException
*
*/
function ftp_pwd(\FTP\Connection $ftp): string
{
error_clear_last();
$safeResult = \ftp_pwd($ftp);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* Sends an arbitrary command to the FTP server.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $command The command to execute.
* @return array Returns the server's response as an array of strings.
* No parsing is performed on the response string, nor does
* ftp_raw determine if the command succeeded.
* @throws FtpException
*
*/
function ftp_raw(\FTP\Connection $ftp, string $command): array
{
error_clear_last();
$safeResult = \ftp_raw($ftp, $command);
if ($safeResult === null) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* ftp_rename renames a file or a directory on the FTP
* server.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $from The old file/directory name.
* @param string $to The new name.
* @throws FtpException
*
*/
function ftp_rename(\FTP\Connection $ftp, string $from, string $to): void
{
error_clear_last();
$safeResult = \ftp_rename($ftp, $from, $to);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* Removes the specified directory on the FTP server.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $directory The directory to delete. This must be either an absolute or relative
* path to an empty directory.
* @throws FtpException
*
*/
function ftp_rmdir(\FTP\Connection $ftp, string $directory): void
{
error_clear_last();
$safeResult = \ftp_rmdir($ftp, $directory);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* ftp_site sends the given SITE
* command to the FTP server.
*
* SITE commands are not standardized, and vary from server
* to server. They are useful for handling such things as file permissions and
* group membership.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $command The SITE command. Note that this parameter isn't escaped so there may
* be some issues with filenames containing spaces and other characters.
* @throws FtpException
*
*/
function ftp_site(\FTP\Connection $ftp, string $command): void
{
error_clear_last();
$safeResult = \ftp_site($ftp, $command);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
}
/**
* ftp_size returns the size of the given file in
* bytes.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @param string $filename The remote file.
* @return int Returns the file size on success.
* @throws FtpException
*
*/
function ftp_size(\FTP\Connection $ftp, string $filename): int
{
error_clear_last();
$safeResult = \ftp_size($ftp, $filename);
if ($safeResult === -1) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* ftp_ssl_connect opens an explicit SSL-FTP connection to the
* specified hostname. That implies that
* ftp_ssl_connect will succeed even if the server is not
* configured for SSL-FTP. Only when ftp_login is called, the client will send the
* appropriate AUTH FTP command, so ftp_login will fail.
* The connection established by ftp_ssl_connect will not do
* peer-certificate verification.
*
* @param string $hostname The FTP server address. This parameter shouldn't have any trailing
* slashes and shouldn't be prefixed with ftp://.
* @param int $port This parameter specifies an alternate port to connect to. If it is
* omitted or set to zero, then the default FTP port, 21, will be used.
* @param int $timeout This parameter specifies the timeout for all subsequent network operations.
* If omitted, the default value is 90 seconds. The timeout can be changed and
* queried at any time with ftp_set_option and
* ftp_get_option.
* @return \FTP\Connection Returns an FTP\Connection instance on success.
* @throws FtpException
*
*/
function ftp_ssl_connect(string $hostname, int $port = 21, int $timeout = 90): \FTP\Connection
{
error_clear_last();
$safeResult = \ftp_ssl_connect($hostname, $port, $timeout);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the system type identifier of the remote FTP server.
*
* @param \FTP\Connection $ftp An FTP\Connection instance.
* @return string Returns the remote system type.
* @throws FtpException
*
*/
function ftp_systype(\FTP\Connection $ftp): string
{
error_clear_last();
$safeResult = \ftp_systype($ftp);
if ($safeResult === false) {
throw FtpException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Safe;
use Safe\Exceptions\FunchandException;
/**
*
*
* @param callable(): void $callback The function to register.
* @param mixed $args
* @throws FunchandException
*
*/
function register_tick_function(callable $callback, ...$args): void
{
error_clear_last();
if ($args !== []) {
$safeResult = \register_tick_function($callback, ...$args);
} else {
$safeResult = \register_tick_function($callback);
}
if ($safeResult === false) {
throw FunchandException::createFromPhpError();
}
}

0
vendor/thecodingmachine/safe/generated/8.5/functionsList.php vendored Normal file → Executable file
View File

View File

@@ -0,0 +1,31 @@
<?php
namespace Safe;
use Safe\Exceptions\GettextException;
/**
* The bindtextdomain function sets or gets the path
* for a domain.
*
* @param string $domain The domain.
* @param null|string $directory The directory path.
* An empty string means the current directory.
* If NULL, the currently set directory is returned.
* @return string The full pathname for the domain currently being set.
* @throws GettextException
*
*/
function bindtextdomain(string $domain, ?string $directory = null): string
{
error_clear_last();
if ($directory !== null) {
$safeResult = \bindtextdomain($domain, $directory);
} else {
$safeResult = \bindtextdomain($domain);
}
if ($safeResult === false) {
throw GettextException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Safe;
use Safe\Exceptions\GmpException;
/**
*
*
* @param \GMP|int|string $seed The seed to be set for the gmp_random,
* gmp_random_bits, and
* gmp_random_range functions.
*
*
* A GMP object, an integer,
* or a string that can be interpreted as a number following the same logic
* as if the string was used in gmp_init with automatic
* base detection (i.e. when base is equal to 0).
*
*/
function gmp_random_seed($seed): void
{
error_clear_last();
$safeResult = \gmp_random_seed($seed);
}

View File

@@ -0,0 +1,188 @@
<?php
namespace Safe;
use Safe\Exceptions\GnupgException;
/**
*
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @param string $fingerprint The fingerprint key.
* @param string $passphrase The pass phrase.
* @throws GnupgException
*
*/
function gnupg_adddecryptkey($identifier, string $fingerprint, string $passphrase): void
{
error_clear_last();
$safeResult = \gnupg_adddecryptkey($identifier, $fingerprint, $passphrase);
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}
/**
*
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @param string $fingerprint The fingerprint key.
* @throws GnupgException
*
*/
function gnupg_addencryptkey($identifier, string $fingerprint): void
{
error_clear_last();
$safeResult = \gnupg_addencryptkey($identifier, $fingerprint);
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}
/**
*
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @param string $fingerprint The fingerprint key.
* @param string $passphrase The pass phrase.
* @throws GnupgException
*
*/
function gnupg_addsignkey($identifier, string $fingerprint, ?string $passphrase = null): void
{
error_clear_last();
if ($passphrase !== null) {
$safeResult = \gnupg_addsignkey($identifier, $fingerprint, $passphrase);
} else {
$safeResult = \gnupg_addsignkey($identifier, $fingerprint);
}
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}
/**
*
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @throws GnupgException
*
*/
function gnupg_cleardecryptkeys($identifier): void
{
error_clear_last();
$safeResult = \gnupg_cleardecryptkeys($identifier);
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}
/**
*
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @throws GnupgException
*
*/
function gnupg_clearencryptkeys($identifier): void
{
error_clear_last();
$safeResult = \gnupg_clearencryptkeys($identifier);
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}
/**
*
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @throws GnupgException
*
*/
function gnupg_clearsignkeys($identifier): void
{
error_clear_last();
$safeResult = \gnupg_clearsignkeys($identifier);
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}
/**
*
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @param string $key The key to delete.
* @param bool $allow_secret It specifies whether to delete secret keys as well.
* @throws GnupgException
*
*/
function gnupg_deletekey($identifier, string $key, bool $allow_secret): void
{
error_clear_last();
$safeResult = \gnupg_deletekey($identifier, $key, $allow_secret);
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}
/**
* Toggle the armored output.
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @param int $armor Pass a non-zero integer-value to this function to enable armored-output
* (default).
* Pass 0 to disable armored output.
* @throws GnupgException
*
*/
function gnupg_setarmor($identifier, int $armor): void
{
error_clear_last();
$safeResult = \gnupg_setarmor($identifier, $armor);
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}
/**
* Sets the mode for signing.
*
* @param resource $identifier The gnupg identifier, from a call to
* gnupg_init or gnupg.
* @param int $signmode The mode for signing.
*
* signmode takes a constant indicating what type of
* signature should be produced. The possible values are
* GNUPG_SIG_MODE_NORMAL,
* GNUPG_SIG_MODE_DETACH and
* GNUPG_SIG_MODE_CLEAR.
* By default GNUPG_SIG_MODE_CLEAR is used.
* @throws GnupgException
*
*/
function gnupg_setsignmode($identifier, int $signmode): void
{
error_clear_last();
$safeResult = \gnupg_setsignmode($identifier, $signmode);
if ($safeResult === false) {
throw GnupgException::createFromPhpError();
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Safe;
use Safe\Exceptions\HashException;
/**
*
*
* @param string $algo Name of selected hashing algorithm (e.g. "sha256").
* For a list of supported algorithms see hash_hmac_algos.
*
*
* Non-cryptographic hash functions are not allowed.
*
*
*
* Non-cryptographic hash functions are not allowed.
* @param string $key Input keying material (raw binary). Cannot be empty.
* @param int $length Desired output length in bytes.
* Cannot be greater than 255 times the chosen hash function size.
*
* If length is 0, the output length
* will default to the chosen hash function size.
* @param string $info Application/context-specific info string.
* @param string $salt Salt to use during derivation.
*
* While optional, adding random salt significantly improves the strength of HKDF.
* @return false|non-falsy-string Returns a string containing a raw binary representation of the derived key
* (also known as output keying material - OKM).
*
*/
function hash_hkdf(string $algo, string $key, int $length = 0, string $info = "", string $salt = "")
{
error_clear_last();
$safeResult = \hash_hkdf($algo, $key, $length, $info, $salt);
return $safeResult;
}
/**
*
*
* @param \HashContext $context Hashing context returned by hash_init.
* @param string $filename URL describing location of file to be hashed; Supports fopen wrappers.
* @param \HashContext|null $stream_context Stream context as returned by stream_context_create.
* @throws HashException
*
*/
function hash_update_file(\HashContext $context, string $filename, ?\HashContext $stream_context = null): void
{
error_clear_last();
if ($stream_context !== null) {
$safeResult = \hash_update_file($context, $filename, $stream_context);
} else {
$safeResult = \hash_update_file($context, $filename);
}
if ($safeResult === false) {
throw HashException::createFromPhpError();
}
}

View File

@@ -0,0 +1,661 @@
<?php
namespace Safe;
use Safe\Exceptions\IbaseException;
/**
* This function will discard a BLOB if it has not yet been closed by
* fbird_blob_close.
*
* @param resource $blob_handle A BLOB handle opened with fbird_blob_create.
* @throws IbaseException
*
*/
function fbird_blob_cancel($blob_handle): void
{
error_clear_last();
$safeResult = \fbird_blob_cancel($blob_handle);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
*
*
* @param resource $service_handle The handle on the database server service.
* @param string $user_name The login name of the new database user.
* @param string $password The password of the new user.
* @param string $first_name The first name of the new database user.
* @param string $middle_name The middle name of the new database user.
* @param string $last_name The last name of the new database user.
* @throws IbaseException
*
*/
function ibase_add_user($service_handle, string $user_name, string $password, ?string $first_name = null, ?string $middle_name = null, ?string $last_name = null): void
{
error_clear_last();
if ($last_name !== null) {
$safeResult = \ibase_add_user($service_handle, $user_name, $password, $first_name, $middle_name, $last_name);
} elseif ($middle_name !== null) {
$safeResult = \ibase_add_user($service_handle, $user_name, $password, $first_name, $middle_name);
} elseif ($first_name !== null) {
$safeResult = \ibase_add_user($service_handle, $user_name, $password, $first_name);
} else {
$safeResult = \ibase_add_user($service_handle, $user_name, $password);
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* This function passes the arguments to the (remote) database server. There it starts a new backup process. Therefore you
* won't get any responses.
*
* @param resource $service_handle A previously opened connection to the database server.
* @param string $source_db The absolute file path to the database on the database server. You can also use a database alias.
* @param string $dest_file The path to the backup file on the database server.
* @param int $options Additional options to pass to the database server for backup.
* The options parameter can be a combination
* of the following constants:
* IBASE_BKP_IGNORE_CHECKSUMS,
* IBASE_BKP_IGNORE_LIMBO,
* IBASE_BKP_METADATA_ONLY,
* IBASE_BKP_NO_GARBAGE_COLLECT,
* IBASE_BKP_OLD_DESCRIPTIONS,
* IBASE_BKP_NON_TRANSPORTABLE or
* IBASE_BKP_CONVERT.
* Read the section about for further information.
* @param bool $verbose Since the backup process is done on the database server, you don't have any chance
* to get its output. This argument is useless.
* @return mixed Returns TRUE on success.
*
* Since the backup process is done on the (remote) server, this function just passes the arguments to it.
* While the arguments are legal, you won't get FALSE.
* @throws IbaseException
*
*/
function ibase_backup($service_handle, string $source_db, string $dest_file, int $options = 0, bool $verbose = false)
{
error_clear_last();
$safeResult = \ibase_backup($service_handle, $source_db, $dest_file, $options, $verbose);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
return $safeResult;
}
/**
* This function will discard a BLOB if it has not yet been closed by
* ibase_blob_close.
*
* @param resource $blob_handle A BLOB handle opened with ibase_blob_create.
* @throws IbaseException
*
*/
function ibase_blob_cancel($blob_handle): void
{
error_clear_last();
$safeResult = \ibase_blob_cancel($blob_handle);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* ibase_blob_create creates a new BLOB for filling with
* data.
*
* @param null|resource $link_identifier An InterBase link identifier. If omitted, the last opened link is
* assumed.
* @return resource Returns a BLOB handle for later use with
* ibase_blob_add.
* @throws IbaseException
*
*/
function ibase_blob_create($link_identifier = null)
{
error_clear_last();
if ($link_identifier !== null) {
$safeResult = \ibase_blob_create($link_identifier);
} else {
$safeResult = \ibase_blob_create();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
return $safeResult;
}
/**
* This function returns at most len bytes from a BLOB
* that has been opened for reading by ibase_blob_open.
*
* @param resource $blob_handle A BLOB handle opened with ibase_blob_open.
* @param int $len Size of returned data.
* @return string Returns at most len bytes from the BLOB.
* @throws IbaseException
*
*/
function ibase_blob_get($blob_handle, int $len): string
{
error_clear_last();
$safeResult = \ibase_blob_get($blob_handle, $len);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
return $safeResult;
}
/**
* Closes the link to an InterBase database that's associated with
* a connection id returned from ibase_connect.
* Default transaction on link is committed, other transactions are
* rolled back.
*
* @param null|resource $connection_id An InterBase link identifier returned from
* ibase_connect. If omitted, the last opened link
* is assumed.
* @throws IbaseException
*
*/
function ibase_close($connection_id = null): void
{
error_clear_last();
if ($connection_id !== null) {
$safeResult = \ibase_close($connection_id);
} else {
$safeResult = \ibase_close();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* Commits a transaction without closing it.
*
* @param null|resource $link_or_trans_identifier If called without an argument, this function commits the default
* transaction of the default link. If the argument is a connection
* identifier, the default transaction of the corresponding connection
* will be committed. If the argument is a transaction identifier, the
* corresponding transaction will be committed. The transaction context
* will be retained, so statements executed from within this transaction
* will not be invalidated.
* @throws IbaseException
*
*/
function ibase_commit_ret($link_or_trans_identifier = null): void
{
error_clear_last();
if ($link_or_trans_identifier !== null) {
$safeResult = \ibase_commit_ret($link_or_trans_identifier);
} else {
$safeResult = \ibase_commit_ret();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* Commits a transaction.
*
* @param null|resource $link_or_trans_identifier If called without an argument, this function commits the default
* transaction of the default link. If the argument is a connection
* identifier, the default transaction of the corresponding connection
* will be committed. If the argument is a transaction identifier, the
* corresponding transaction will be committed.
* @throws IbaseException
*
*/
function ibase_commit($link_or_trans_identifier = null): void
{
error_clear_last();
if ($link_or_trans_identifier !== null) {
$safeResult = \ibase_commit($link_or_trans_identifier);
} else {
$safeResult = \ibase_commit();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* Establishes a connection to an Firebird/InterBase server.
*
* In case a second call is made to ibase_connect with
* the same arguments, no new link will be established, but instead, the link
* identifier of the already opened link will be returned. The link to the
* server will be closed as soon as the execution of the script ends, unless
* it's closed earlier by explicitly calling ibase_close.
*
* @param string $database The database argument has to be a valid path to
* database file on the server it resides on. If the server is not local,
* it must be prefixed with either 'hostname:' (TCP/IP), 'hostname/port:'
* (TCP/IP with interbase server on custom TCP port), '//hostname/'
* (NetBEUI), depending on the connection
* protocol used.
* @param string $username The user name. Can be set with the
* ibase.default_user php.ini directive.
* @param string $password The password for username. Can be set with the
* ibase.default_password php.ini directive.
* @param string $charset charset is the default character set for a
* database.
* @param int $buffers buffers is the number of database buffers to
* allocate for the server-side cache. If 0 or omitted, server chooses
* its own default.
* @param int $dialect dialect selects the default SQL dialect for any
* statement executed within a connection, and it defaults to the highest
* one supported by client libraries.
* @param string $role Functional only with InterBase 5 and up.
* @param int $sync
* @return resource Returns an Firebird/InterBase link identifier on success.
* @throws IbaseException
*
*/
function ibase_connect(?string $database = null, ?string $username = null, ?string $password = null, ?string $charset = null, ?int $buffers = null, ?int $dialect = null, ?string $role = null, ?int $sync = null)
{
error_clear_last();
if ($sync !== null) {
$safeResult = \ibase_connect($database, $username, $password, $charset, $buffers, $dialect, $role, $sync);
} elseif ($role !== null) {
$safeResult = \ibase_connect($database, $username, $password, $charset, $buffers, $dialect, $role);
} elseif ($dialect !== null) {
$safeResult = \ibase_connect($database, $username, $password, $charset, $buffers, $dialect);
} elseif ($buffers !== null) {
$safeResult = \ibase_connect($database, $username, $password, $charset, $buffers);
} elseif ($charset !== null) {
$safeResult = \ibase_connect($database, $username, $password, $charset);
} elseif ($password !== null) {
$safeResult = \ibase_connect($database, $username, $password);
} elseif ($username !== null) {
$safeResult = \ibase_connect($database, $username);
} elseif ($database !== null) {
$safeResult = \ibase_connect($database);
} else {
$safeResult = \ibase_connect();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param resource $service_handle The handle on the database server service.
* @param string $user_name The login name of the user you want to delete from the database.
* @throws IbaseException
*
*/
function ibase_delete_user($service_handle, string $user_name): void
{
error_clear_last();
$safeResult = \ibase_delete_user($service_handle, $user_name);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* This functions drops a database that was opened by either ibase_connect
* or ibase_pconnect. The database is closed and deleted from the server.
*
* @param null|resource $connection An InterBase link identifier. If omitted, the last opened link is
* assumed.
* @throws IbaseException
*
*/
function ibase_drop_db($connection = null): void
{
error_clear_last();
if ($connection !== null) {
$safeResult = \ibase_drop_db($connection);
} else {
$safeResult = \ibase_drop_db();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* This function causes the registered event handler specified by
* event to be cancelled. The callback function will
* no longer be called for the events it was registered to handle.
*
* @param resource $event An event resource, created by
* ibase_set_event_handler.
* @throws IbaseException
*
*/
function ibase_free_event_handler($event): void
{
error_clear_last();
$safeResult = \ibase_free_event_handler($event);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* Frees a prepared query.
*
* @param resource $query A query prepared with ibase_prepare.
* @throws IbaseException
*
*/
function ibase_free_query($query): void
{
error_clear_last();
$safeResult = \ibase_free_query($query);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* Frees a result set.
*
* @param resource $result_identifier A result set created by ibase_query or
* ibase_execute.
* @throws IbaseException
*
*/
function ibase_free_result($result_identifier): void
{
error_clear_last();
$safeResult = \ibase_free_result($result_identifier);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
*
*
* @param resource $service_handle
* @param string $db
* @param int $action
* @param int $argument
* @throws IbaseException
*
*/
function ibase_maintain_db($service_handle, string $db, int $action, int $argument = 0): void
{
error_clear_last();
$safeResult = \ibase_maintain_db($service_handle, $db, $action, $argument);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
*
*
* @param resource $service_handle The handle on the database server service.
* @param string $user_name The login name of the database user to modify.
* @param string $password The user's new password.
* @param string $first_name The user's new first name.
* @param string $middle_name The user's new middle name.
* @param string $last_name The user's new last name.
* @throws IbaseException
*
*/
function ibase_modify_user($service_handle, string $user_name, string $password, ?string $first_name = null, ?string $middle_name = null, ?string $last_name = null): void
{
error_clear_last();
if ($last_name !== null) {
$safeResult = \ibase_modify_user($service_handle, $user_name, $password, $first_name, $middle_name, $last_name);
} elseif ($middle_name !== null) {
$safeResult = \ibase_modify_user($service_handle, $user_name, $password, $first_name, $middle_name);
} elseif ($first_name !== null) {
$safeResult = \ibase_modify_user($service_handle, $user_name, $password, $first_name);
} else {
$safeResult = \ibase_modify_user($service_handle, $user_name, $password);
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* This function assigns a name to a result set. This name can be used later in
* UPDATE|DELETE ... WHERE CURRENT OF name statements.
*
* @param resource $result An InterBase result set.
* @param string $name The name to be assigned.
* @throws IbaseException
*
*/
function ibase_name_result($result, string $name): void
{
error_clear_last();
$safeResult = \ibase_name_result($result, $name);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* Opens a persistent connection to an InterBase database.
*
* ibase_pconnect acts very much like
* ibase_connect with two major differences.
*
* First, when connecting, the function will first try to find a (persistent)
* link that's already opened with the same parameters. If one is found, an
* identifier for it will be returned instead of opening a new connection.
*
* Second, the connection to the InterBase server will not be closed when the
* execution of the script ends. Instead, the link will remain open for
* future use (ibase_close will not close links
* established by ibase_pconnect). This type of link is
* therefore called 'persistent'.
*
* @param string $database The database argument has to be a valid path to
* database file on the server it resides on. If the server is not local,
* it must be prefixed with either 'hostname:' (TCP/IP), '//hostname/'
* (NetBEUI) or 'hostname@' (IPX/SPX), depending on the connection
* protocol used.
* @param string $username The user name. Can be set with the
* ibase.default_user php.ini directive.
* @param string $password The password for username. Can be set with the
* ibase.default_password php.ini directive.
* @param string $charset charset is the default character set for a
* database.
* @param int $buffers buffers is the number of database buffers to
* allocate for the server-side cache. If 0 or omitted, server chooses
* its own default.
* @param int $dialect dialect selects the default SQL dialect for any
* statement executed within a connection, and it defaults to the highest
* one supported by client libraries. Functional only with InterBase 6
* and up.
* @param string $role Functional only with InterBase 5 and up.
* @param int $sync
* @return resource Returns an InterBase link identifier on success.
* @throws IbaseException
*
*/
function ibase_pconnect(?string $database = null, ?string $username = null, ?string $password = null, ?string $charset = null, ?int $buffers = null, ?int $dialect = null, ?string $role = null, ?int $sync = null)
{
error_clear_last();
if ($sync !== null) {
$safeResult = \ibase_pconnect($database, $username, $password, $charset, $buffers, $dialect, $role, $sync);
} elseif ($role !== null) {
$safeResult = \ibase_pconnect($database, $username, $password, $charset, $buffers, $dialect, $role);
} elseif ($dialect !== null) {
$safeResult = \ibase_pconnect($database, $username, $password, $charset, $buffers, $dialect);
} elseif ($buffers !== null) {
$safeResult = \ibase_pconnect($database, $username, $password, $charset, $buffers);
} elseif ($charset !== null) {
$safeResult = \ibase_pconnect($database, $username, $password, $charset);
} elseif ($password !== null) {
$safeResult = \ibase_pconnect($database, $username, $password);
} elseif ($username !== null) {
$safeResult = \ibase_pconnect($database, $username);
} elseif ($database !== null) {
$safeResult = \ibase_pconnect($database);
} else {
$safeResult = \ibase_pconnect();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
return $safeResult;
}
/**
* This function passes the arguments to the (remote) database server. There it starts a new restore process. Therefore you
* won't get any responses.
*
* @param resource $service_handle A previously opened connection to the database server.
* @param string $source_file The absolute path on the server where the backup file is located.
* @param string $dest_db The path to create the new database on the server. You can also use database alias.
* @param int $options Additional options to pass to the database server for restore.
* The options parameter can be a combination
* of the following constants:
* IBASE_RES_DEACTIVATE_IDX,
* IBASE_RES_NO_SHADOW,
* IBASE_RES_NO_VALIDITY,
* IBASE_RES_ONE_AT_A_TIME,
* IBASE_RES_REPLACE,
* IBASE_RES_CREATE,
* IBASE_RES_USE_ALL_SPACE,
* IBASE_PRP_PAGE_BUFFERS,
* IBASE_PRP_SWEEP_INTERVAL,
* IBASE_RES_CREATE.
* Read the section about for further information.
* @param bool $verbose Since the restore process is done on the database server, you don't have any chance
* to get its output. This argument is useless.
* @return mixed Returns TRUE on success.
*
* Since the restore process is done on the (remote) server, this function just passes the arguments to it.
* While the arguments are legal, you won't get FALSE.
* @throws IbaseException
*
*/
function ibase_restore($service_handle, string $source_file, string $dest_db, int $options = 0, bool $verbose = false)
{
error_clear_last();
$safeResult = \ibase_restore($service_handle, $source_file, $dest_db, $options, $verbose);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
return $safeResult;
}
/**
* Rolls back a transaction without closing it.
*
* @param null|resource $link_or_trans_identifier If called without an argument, this function rolls back the default
* transaction of the default link. If the argument is a connection
* identifier, the default transaction of the corresponding connection
* will be rolled back. If the argument is a transaction identifier, the
* corresponding transaction will be rolled back. The transaction context
* will be retained, so statements executed from within this transaction
* will not be invalidated.
* @throws IbaseException
*
*/
function ibase_rollback_ret($link_or_trans_identifier = null): void
{
error_clear_last();
if ($link_or_trans_identifier !== null) {
$safeResult = \ibase_rollback_ret($link_or_trans_identifier);
} else {
$safeResult = \ibase_rollback_ret();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
* Rolls back a transaction.
*
* @param null|resource $link_or_trans_identifier If called without an argument, this function rolls back the default
* transaction of the default link. If the argument is a connection
* identifier, the default transaction of the corresponding connection
* will be rolled back. If the argument is a transaction identifier, the
* corresponding transaction will be rolled back.
* @throws IbaseException
*
*/
function ibase_rollback($link_or_trans_identifier = null): void
{
error_clear_last();
if ($link_or_trans_identifier !== null) {
$safeResult = \ibase_rollback($link_or_trans_identifier);
} else {
$safeResult = \ibase_rollback();
}
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}
/**
*
*
* @param string $host The name or ip address of the database host. You can define the port by adding
* '/' and port number. If no port is specified, port 3050 will be used.
* @param string $dba_username The name of any valid user.
* @param string $dba_password The user's password.
* @return resource Returns a Interbase / Firebird link identifier on success.
* @throws IbaseException
*
*/
function ibase_service_attach(string $host, string $dba_username, string $dba_password)
{
error_clear_last();
$safeResult = \ibase_service_attach($host, $dba_username, $dba_password);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param resource $service_handle A previously created connection to the database server.
* @throws IbaseException
*
*/
function ibase_service_detach($service_handle): void
{
error_clear_last();
$safeResult = \ibase_service_detach($service_handle);
if ($safeResult === false) {
throw IbaseException::createFromPhpError();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,309 @@
<?php
namespace Safe;
use Safe\Exceptions\IconvException;
/**
* Retrieve internal configuration variables of iconv extension.
*
* @param string $type The value of the optional type can be:
*
* all
* input_encoding
* output_encoding
* internal_encoding
*
* @return mixed Returns the current value of the internal configuration variable if
* successful.
*
* If type is omitted or set to "all",
* iconv_get_encoding returns an array that
* stores all these variables.
* @throws IconvException
*
*/
function iconv_get_encoding(string $type = "all")
{
error_clear_last();
$safeResult = \iconv_get_encoding($type);
if ($safeResult === false) {
throw IconvException::createFromPhpError();
}
return $safeResult;
}
/**
* Decodes a MIME header field.
*
* @param string $string The encoded header, as a string.
* @param int $mode mode determines the behaviour in the event
* iconv_mime_decode encounters a malformed
* MIME header field. You can specify any combination
* of the following bitmasks.
*
* Bitmasks acceptable to iconv_mime_decode
*
*
*
* Value
* Constant
* Description
*
*
*
*
* 1
* ICONV_MIME_DECODE_STRICT
*
* If set, the given header is decoded in full conformance with the
* standards defined in RFC2047.
* This option is disabled by default because there are a lot of
* broken mail user agents that don't follow the specification and don't
* produce correct MIME headers.
*
*
*
* 2
* ICONV_MIME_DECODE_CONTINUE_ON_ERROR
*
* If set, iconv_mime_decode_headers
* attempts to ignore any grammatical errors and continue to process
* a given header.
*
*
*
*
*
* @param null|string $encoding The optional encoding parameter specifies the
* character set to represent the result by. If omitted or NULL,
* iconv.internal_encoding
* will be used.
* @return string Returns a decoded MIME field on success,
* or FALSE if an error occurs during the decoding.
* @throws IconvException
*
*/
function iconv_mime_decode(string $string, int $mode = 0, ?string $encoding = null): string
{
error_clear_last();
if ($encoding !== null) {
$safeResult = \iconv_mime_decode($string, $mode, $encoding);
} else {
$safeResult = \iconv_mime_decode($string, $mode);
}
if ($safeResult === false) {
throw IconvException::createFromPhpError();
}
return $safeResult;
}
/**
* Composes and returns a string that represents a valid MIME
* header field, which looks like the following:
*
*
*
* In the above example, "Subject" is the field name and the portion that
* begins with "=?ISO-8859-1?..." is the field value.
*
* @param string $field_name The field name.
* @param string $field_value The field value.
* @param array $options You can control the behaviour of iconv_mime_encode
* by specifying an associative array that contains configuration items
* to the optional third parameter options.
* The items supported by iconv_mime_encode are
* listed below. Note that item names are treated case-sensitive.
*
* Configuration items supported by iconv_mime_encode
*
*
*
* Item
* Type
* Description
* Default value
* Example
*
*
*
*
* scheme
* string
*
* Specifies the method to encode a field value by. The value of
* this item may be either "B" or "Q", where "B" stands for
* base64 encoding scheme and "Q" stands for
* quoted-printable encoding scheme.
*
* B
* B
*
*
* input-charset
* string
*
* Specifies the character set in which the first parameter
* field_name and the second parameter
* field_value are presented. If not given,
* iconv_mime_encode assumes those parameters
* are presented to it in the
* iconv.internal_encoding
* ini setting.
*
*
* iconv.internal_encoding
*
* ISO-8859-1
*
*
* output-charset
* string
*
* Specifies the character set to use to compose the
* MIME header.
*
*
* iconv.internal_encoding
*
* UTF-8
*
*
* line-length
* int
*
* Specifies the maximum length of the header lines. The resulting
* header is "folded" to a set of multiple lines in case
* the resulting header field would be longer than the value of this
* parameter, according to
* RFC2822 - Internet Message Format.
* If not given, the length will be limited to 76 characters.
*
* 76
* 996
*
*
* line-break-chars
* string
*
* Specifies the sequence of characters to append to each line
* as an end-of-line sign when "folding" is performed on a long header
* field. If not given, this defaults to "\r\n"
* (CR LF). Note that
* this parameter is always treated as an ASCII string regardless
* of the value of input-charset.
*
* \r\n
* \n
*
*
*
*
* @return string Returns an encoded MIME field on success,
* or FALSE if an error occurs during the encoding.
* @throws IconvException
*
*/
function iconv_mime_encode(string $field_name, string $field_value, array $options = []): string
{
error_clear_last();
$safeResult = \iconv_mime_encode($field_name, $field_value, $options);
if ($safeResult === false) {
throw IconvException::createFromPhpError();
}
return $safeResult;
}
/**
* Changes the value of the internal configuration variable specified by
* type to encoding.
*
* @param string $type The value of type can be any one of these:
*
* input_encoding
* output_encoding
* internal_encoding
*
* @param string $encoding The character set.
* @throws IconvException
*
*/
function iconv_set_encoding(string $type, string $encoding): void
{
error_clear_last();
$safeResult = \iconv_set_encoding($type, $encoding);
if ($safeResult === false) {
throw IconvException::createFromPhpError();
}
}
/**
* In contrast to strlen,
* iconv_strlen counts the occurrences of characters
* in the given byte sequence string on the basis of
* the specified character set, the result of which is not necessarily
* identical to the length of the string in bytes.
*
* @param string $string The string.
* @param null|string $encoding If encoding parameter is omitted or NULL,
* string is assumed to be encoded in
* iconv.internal_encoding.
* @return 0|positive-int Returns the character count of string, as an integer,
* or FALSE if an error occurs during the encoding.
* @throws IconvException
*
*/
function iconv_strlen(string $string, ?string $encoding = null): int
{
error_clear_last();
if ($encoding !== null) {
$safeResult = \iconv_strlen($string, $encoding);
} else {
$safeResult = \iconv_strlen($string);
}
if ($safeResult === false) {
throw IconvException::createFromPhpError();
}
return $safeResult;
}
/**
* Converts string from from_encoding
* to to_encoding.
*
* @param string $from_encoding The current encoding used to interpret string.
* @param string $to_encoding The desired encoding of the result.
*
* If the string //TRANSLIT is appended to
* to_encoding, then transliteration is activated. This
* means that when a character can't be represented in the target charset,
* it may be approximated through one or several similarly looking
* characters. If the string //IGNORE is appended,
* characters that cannot be represented in the target charset are silently
* discarded. Otherwise, E_NOTICE is generated and the function
* will return FALSE.
*
* If and how //TRANSLIT works exactly depends on the
* system's iconv() implementation (cf. ICONV_IMPL).
* Some implementations are known to ignore //TRANSLIT,
* so the conversion is likely to fail for characters which are illegal for
* the to_encoding.
* @param string $string The string to be converted.
* @return string Returns the converted string.
* @throws IconvException
*
*/
function iconv(string $from_encoding, string $to_encoding, string $string): string
{
error_clear_last();
$safeResult = \iconv($from_encoding, $to_encoding, $string);
if ($safeResult === false) {
throw IconvException::createFromPhpError();
}
return $safeResult;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,718 @@
<?php
namespace Safe;
use Safe\Exceptions\InfoException;
/**
* Set the various assert control options or just query
* their current settings.
*
* @param int $option
* Assert Options
*
*
*
* Option
* INI Setting
* Default value
* Description
*
*
*
*
* ASSERT_ACTIVE
* assert.active
* 1
* enable assert evaluation
*
*
* ASSERT_EXCEPTION
* assert.exception
* 1
* throws an AssertionError for each failed assertions
*
*
* ASSERT_WARNING
* assert.warning
* 1
* issue a PHP warning for each failed assertion
*
*
* ASSERT_BAIL
* assert.bail
* 0
* terminate execution on failed assertions
*
*
* ASSERT_QUIET_EVAL
* assert.quiet_eval
* 0
*
* disable error_reporting during assertion expression
* evaluation. Removed as of PHP 8.0.0.
*
*
*
* ASSERT_CALLBACK
* assert.callback
* (NULL)
* Callback to call on failed assertions
*
*
*
*
* @param mixed $value An optional new value for the option.
*
* The callback function set via ASSERT_CALLBACK or
* assert.callback
* should have the following signature:
*
* voidassert_callback
* stringfile
* intline
* stringnullassertion
* stringdescription
*
*
*
* file
*
*
* The file where assert has been called.
*
*
*
*
* line
*
*
* The line where assert has been called.
*
*
*
*
* assertion
*
*
* Prior to PHP 8.0.0, the assertion which has been passed to assert,
* but only when the assertion is given as a string.
* (If the assertion is a boolean condition, this parameter will be an empty string.)
* As of PHP 8.0.0, this parameter is always NULL.
*
*
*
*
* description
*
*
* The description that has been passed to assert.
*
*
*
*
* @return mixed Returns the original setting of any option.
*
*/
function assert_options(int $option, $value = null)
{
error_clear_last();
if ($value !== null) {
$safeResult = \assert_options($option, $value);
} else {
$safeResult = \assert_options($option);
}
return $safeResult;
}
/**
* Sets the process title visible in tools such as top and
* ps. This function is available only in
* CLI mode.
*
* @param string $title The new title.
* @throws InfoException
*
*/
function cli_set_process_title(string $title): void
{
error_clear_last();
$safeResult = \cli_set_process_title($title);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
}
/**
* Loads the PHP extension given by the parameter
* extension_filename.
*
* Use extension_loaded to test whether a given
* extension is already available or not. This works on both built-in
* extensions and dynamically loaded ones (either through php.ini or
* dl).
*
* @param string $extension_filename This parameter is only the filename of the
* extension to load which also depends on your platform. For example,
* the sockets extension (if compiled
* as a shared module, not the default!) would be called
* sockets.so on Unix platforms whereas it is called
* php_sockets.dll on the Windows platform.
*
* The directory where the extension is loaded from depends on your
* platform:
*
* Windows - If not explicitly set in the php.ini, the extension is
* loaded from C:\php5\ by default.
*
* Unix - If not explicitly set in the php.ini, the default extension
* directory depends on
*
*
*
* whether PHP has been built with --enable-debug
* or not
*
*
*
*
* whether PHP has been built with ZTS (Zend Thread Safety)
* support or not
*
*
*
*
* the current internal ZEND_MODULE_API_NO (Zend
* internal module API number, which is basically the date on which a
* major module API change happened, e.g. 20010901)
*
*
*
* Taking into account the above, the directory then defaults to
* &lt;install-dir&gt;/lib/php/extensions/ &lt;debug-or-not&gt;-&lt;zts-or-not&gt;-ZEND_MODULE_API_NO,
* e.g.
* /usr/local/php/lib/php/extensions/debug-non-zts-20010901
* or
* /usr/local/php/lib/php/extensions/no-debug-zts-20010901.
* @throws InfoException
*
*/
function dl(string $extension_filename): void
{
error_clear_last();
$safeResult = \dl($extension_filename);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
}
/**
* Gets the value of a PHP configuration option.
*
* This function will not return configuration information set when the PHP
* was compiled, or read from an Apache configuration file.
*
* To check whether the system is using a configuration file, try retrieving the
* value of the cfg_file_path configuration setting. If this is available, a
* configuration file is being used.
*
* @param string $option The configuration option name.
* @return mixed Returns the current value of the PHP configuration variable specified by
* option, or FALSE if an error occurs.
* @throws InfoException
*
*/
function get_cfg_var(string $option)
{
error_clear_last();
$safeResult = \get_cfg_var($option);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @return string Returns the path, as a string.
* @throws InfoException
*
*/
function get_include_path(): string
{
error_clear_last();
$safeResult = \get_include_path();
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets the time of the last modification of the main script of execution.
*
* If you're interested in getting the last modification time
* of a different file, consider using filemtime.
*
* @return int Returns the time of the last modification of the current
* page. The value returned is a Unix timestamp, suitable for
* feeding to date.
* @throws InfoException
*
*/
function getlastmod(): int
{
error_clear_last();
$safeResult = \getlastmod();
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @return int Returns the group ID of the current script.
* @throws InfoException
*
*/
function getmygid(): int
{
error_clear_last();
$safeResult = \getmygid();
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets the inode of the current script.
*
* @return int Returns the current script's inode as an integer.
* @throws InfoException
*
*/
function getmyinode(): int
{
error_clear_last();
$safeResult = \getmyinode();
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets the current PHP process ID.
*
* @return int Returns the current PHP process ID.
* @throws InfoException
*
*/
function getmypid(): int
{
error_clear_last();
$safeResult = \getmypid();
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @return int Returns the user ID of the current script.
* @throws InfoException
*
*/
function getmyuid(): int
{
error_clear_last();
$safeResult = \getmyuid();
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* Parses options passed to the script.
*
* @param string $short_options
* @param array $long_options
* @param int|null $rest_index
* @return array|array|array This function will return an array of option / argument pairs.
* @throws InfoException
*
*/
function getopt(string $short_options, array $long_options = [], ?int &$rest_index = null): array
{
error_clear_last();
$safeResult = \getopt($short_options, $long_options, $rest_index);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* This is an interface to getrusage(2). It gets data returned
* from the system call.
*
* @param int $mode If mode is 1, getrusage will be called with
* RUSAGE_CHILDREN.
* @return array Returns an associative array containing the data returned from the system
* call. All entries are accessible by using their documented field names.
* Returns FALSE on failure.
* @throws InfoException
*
*/
function getrusage(int $mode = 0): array
{
error_clear_last();
$safeResult = \getrusage($mode);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the value of the configuration option on success.
*
* @param string $option The configuration option name.
* @return string Returns the value of the configuration option as a string on success, or an
* empty string for null values. Returns FALSE if the
* configuration option doesn't exist.
* @throws InfoException
*
*/
function ini_get(string $option): string
{
error_clear_last();
$safeResult = \ini_get($option);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* Sets the value of the given configuration option. The configuration option
* will keep this new value during the script's execution, and will be restored
* at the script's ending.
*
* @param string $option Not all the available options can be changed using
* ini_set. There is a list of all available options
* in the appendix.
* @param bool|float|int|null|string $value The new value for the option.
* @return string Returns the old value on success.
* @throws InfoException
*
*/
function ini_set(string $option, $value): string
{
error_clear_last();
$safeResult = \ini_set($option, $value);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @return non-empty-string Returns the interface type, as a lowercase string.
*
* Although not exhaustive, the possible return values include
* apache,
* apache2handler,
* cgi (until PHP 5.3),
* cgi-fcgi, cli, cli-server,
* embed, fpm-fcgi,
* litespeed,
* phpdbg.
* @throws InfoException
*
*/
function php_sapi_name(): string
{
error_clear_last();
$safeResult = \php_sapi_name();
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* This function prints out the credits listing the PHP developers,
* modules, etc. It generates the appropriate HTML codes to insert
* the information in a page.
*
* @param int $flags To generate a custom credits page, you may want to use the
* flags parameter.
*
*
* Pre-defined phpcredits flags
*
*
*
* name
* description
*
*
*
*
* CREDITS_ALL
*
* All the credits, equivalent to using: CREDITS_DOCS +
* CREDITS_GENERAL + CREDITS_GROUP +
* CREDITS_MODULES + CREDITS_FULLPAGE.
* It generates a complete stand-alone HTML page with the appropriate tags.
*
*
*
* CREDITS_DOCS
* The credits for the documentation team
*
*
* CREDITS_FULLPAGE
*
* Usually used in combination with the other flags. Indicates
* that a complete stand-alone HTML page needs to be
* printed including the information indicated by the other
* flags.
*
*
*
* CREDITS_GENERAL
*
* General credits: Language design and concept, PHP authors
* and SAPI module.
*
*
*
* CREDITS_GROUP
* A list of the core developers
*
*
* CREDITS_MODULES
*
* A list of the extension modules for PHP, and their authors
*
*
*
* CREDITS_SAPI
*
* A list of the server API modules for PHP, and their authors
*
*
*
*
*
* @return bool Always returns TRUE.
*
*/
function phpcredits(int $flags = CREDITS_ALL): bool
{
error_clear_last();
$safeResult = \phpcredits($flags);
return $safeResult;
}
/**
* Outputs a large amount of information about the current state of PHP.
* This includes information about PHP compilation options and extensions,
* the PHP version, server information and environment (if compiled as a
* module), the PHP environment, OS version information, paths, master and
* local values of configuration options, HTTP headers, and the PHP License.
*
* Because every system is setup differently, phpinfo is
* commonly used to check configuration settings and for available
* predefined variables
* on a given system.
*
* phpinfo is also a valuable debugging tool as it
* contains all EGPCS (Environment, GET, POST, Cookie, Server) data.
*
* @param int $flags The output may be customized by passing one or more of the
* following constants bitwise values summed
* together in the optional flags parameter.
* One can also combine the respective constants or bitwise values
* together with the bitwise or operator.
*
*
* phpinfo options
*
*
*
* Name (constant)
* Value
* Description
*
*
*
*
* INFO_GENERAL
* 1
*
* The configuration line, php.ini location, build date, Web
* Server, System and more.
*
*
*
* INFO_CREDITS
* 2
*
* PHP Credits. See also phpcredits.
*
*
*
* INFO_CONFIGURATION
* 4
*
* Current Local and Master values for PHP directives. See
* also ini_get.
*
*
*
* INFO_MODULES
* 8
*
* Loaded modules and their respective settings. See also
* get_loaded_extensions.
*
*
*
* INFO_ENVIRONMENT
* 16
*
* Environment Variable information that's also available in
* $_ENV.
*
*
*
* INFO_VARIABLES
* 32
*
* Shows all
* predefined variables from EGPCS (Environment, GET,
* POST, Cookie, Server).
*
*
*
* INFO_LICENSE
* 64
*
* PHP License information. See also the license FAQ.
*
*
*
* INFO_ALL
* -1
*
* Shows all of the above.
*
*
*
*
*
* @return bool Always returns TRUE.
*
*/
function phpinfo(int $flags = INFO_ALL): bool
{
error_clear_last();
$safeResult = \phpinfo($flags);
return $safeResult;
}
/**
* Adds assignment to the server environment. The
* environment variable will only exist for the duration of the current
* request. At the end of the request the environment is restored to its
* original state.
*
* @param string $assignment The setting, like "FOO=BAR"
* @throws InfoException
*
*/
function putenv(string $assignment): void
{
error_clear_last();
$safeResult = \putenv($assignment);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
}
/**
* Sets the include_path
* configuration option for the duration of the script.
*
* @param string $include_path The new value for the include_path
* @return string Returns the old include_path on
* success.
* @throws InfoException
*
*/
function set_include_path(string $include_path): string
{
error_clear_last();
$safeResult = \set_include_path($include_path);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
return $safeResult;
}
/**
* Set the number of seconds a script is allowed to run. If this is reached,
* the script returns a fatal error. The default limit is 30 seconds or, if
* it exists, the max_execution_time value defined in the
* php.ini.
*
* When called, set_time_limit restarts the timeout
* counter from zero. In other words, if the timeout is the default 30
* seconds, and 25 seconds into script execution a call such as
* set_time_limit(20) is made, the script will run for a
* total of 45 seconds before timing out.
*
* @param int $seconds The maximum execution time, in seconds. If set to zero, no time limit
* is imposed.
* @throws InfoException
*
*/
function set_time_limit(int $seconds): void
{
error_clear_last();
$safeResult = \set_time_limit($seconds);
if ($safeResult === false) {
throw InfoException::createFromPhpError();
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace Safe;
use Safe\Exceptions\InotifyException;
/**
* inotify_add_watch adds a new watch or modify an
* existing watch for the file or directory specified in
* pathname.
*
* Using inotify_add_watch on a watched object replaces
* the existing watch. Using the IN_MASK_ADD constant
* adds (OR) events to the existing watch.
*
* @param resource $inotify_instance Resource returned by
* inotify_init
* @param string $pathname File or directory to watch
* @param int $mask Events to watch for. See Predefined Constants.
* @return int The return value is a unique (inotify instance wide) watch descriptor.
* @throws InotifyException
*
*/
function inotify_add_watch($inotify_instance, string $pathname, int $mask): int
{
error_clear_last();
$safeResult = \inotify_add_watch($inotify_instance, $pathname, $mask);
if ($safeResult === false) {
throw InotifyException::createFromPhpError();
}
return $safeResult;
}
/**
* Initialize an inotify instance for use with
* inotify_add_watch
*
* @return resource A stream resource.
* @throws InotifyException
*
*/
function inotify_init()
{
error_clear_last();
$safeResult = \inotify_init();
if ($safeResult === false) {
throw InotifyException::createFromPhpError();
}
return $safeResult;
}
/**
* inotify_rm_watch removes the watch
* watch_descriptor from the inotify instance
* inotify_instance.
*
* @param resource $inotify_instance Resource returned by
* inotify_init
* @param int $watch_descriptor Watch to remove from the instance
* @throws InotifyException
*
*/
function inotify_rm_watch($inotify_instance, int $watch_descriptor): void
{
error_clear_last();
$safeResult = \inotify_rm_watch($inotify_instance, $watch_descriptor);
if ($safeResult === false) {
throw InotifyException::createFromPhpError();
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Safe;
use Safe\Exceptions\JsonException;
/**
* Returns a string containing the JSON representation of the supplied
* value. If the parameter is an array or object,
* it will be serialized recursively.
*
* If a value to be serialized is an object, then by default only publicly visible
* properties will be included. Alternatively, a class may implement JsonSerializable
* to control how its values are serialized to JSON.
*
* The encoding is affected by the supplied flags
* and additionally the encoding of float values depends on the value of
* serialize_precision.
*
* @param mixed $value The value being encoded. Can be any type except
* a resource.
*
* All string data must be UTF-8 encoded.
*
* PHP implements a superset of JSON as specified in the original
* RFC 7159.
* @param int $flags Bitmask consisting of
* JSON_FORCE_OBJECT,
* JSON_HEX_QUOT,
* JSON_HEX_TAG,
* JSON_HEX_AMP,
* JSON_HEX_APOS,
* JSON_INVALID_UTF8_IGNORE,
* JSON_INVALID_UTF8_SUBSTITUTE,
* JSON_NUMERIC_CHECK,
* JSON_PARTIAL_OUTPUT_ON_ERROR,
* JSON_PRESERVE_ZERO_FRACTION,
* JSON_PRETTY_PRINT,
* JSON_UNESCAPED_LINE_TERMINATORS,
* JSON_UNESCAPED_SLASHES,
* JSON_UNESCAPED_UNICODE,
* JSON_THROW_ON_ERROR.
* The behaviour of these constants is described on the
* JSON constants page.
* @param positive-int $depth Set the maximum depth. Must be greater than zero.
* @return non-empty-string Returns a JSON encoded string on success.
* @throws JsonException
*
*/
function json_encode($value, int $flags = 0, int $depth = 512): string
{
error_clear_last();
$safeResult = \json_encode($value, $flags, $depth);
if ($safeResult === false) {
throw JsonException::createFromPhpError();
}
return $safeResult;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
<?php
namespace Safe;
use Safe\Exceptions\LibxmlException;
/**
* Changes the default external entity loader.
* This can be used to suppress the expansion of arbitrary external entities to avoid XXE attacks,
* even when LIBXML_NOENT has been set for the respective operation,
* and is usually preferable over calling libxml_disable_entity_loader.
*
* @param callable $resolver_function A callable with the following signature:
*
* resourcestringnullresolver
* stringnullpublic_id
* stringsystem_id
* arraycontext
*
*
*
* public_id
*
*
* The public ID.
*
*
*
*
* system_id
*
*
* The system ID.
*
*
*
*
* context
*
*
* An array with the four elements "directory", "intSubName",
* "extSubURI" and "extSubSystem".
*
*
*
*
* This callable should return a resource, a string from which a resource can be
* opened. If NULL is returned, the entity reference resolution will fail.
* @throws LibxmlException
*
*/
function libxml_set_external_entity_loader(callable $resolver_function): void
{
error_clear_last();
$safeResult = \libxml_set_external_entity_loader($resolver_function);
if ($safeResult === false) {
throw LibxmlException::createFromPhpError();
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Safe;
use Safe\Exceptions\LzfException;
/**
* lzf_compress compresses the given
* data string using LZF encoding.
*
* @param string $data The string to compress.
* @return string Returns the compressed data.
* @throws LzfException
*
*/
function lzf_compress(string $data): string
{
error_clear_last();
$safeResult = \lzf_compress($data);
if ($safeResult === false) {
throw LzfException::createFromPhpError();
}
return $safeResult;
}
/**
* lzf_compress decompresses the given
* data string containing lzf encoded data.
*
* @param string $data The compressed string.
* @return string Returns the decompressed data.
* @throws LzfException
*
*/
function lzf_decompress(string $data): string
{
error_clear_last();
$safeResult = \lzf_decompress($data);
if ($safeResult === false) {
throw LzfException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,127 @@
<?php
namespace Safe;
use Safe\Exceptions\MailparseException;
/**
* Extracts/decodes a message section from the supplied filename.
*
* The contents of the section will be decoded according to their transfer
* encoding - base64, quoted-printable and uuencoded text are supported.
*
* @param resource $mimemail A valid MIME resource, created with
* mailparse_msg_create.
* @param mixed $filename Can be a file name or a valid stream resource.
* @param callable $callbackfunc If set, this must be either a valid callback that will be passed the
* extracted section, or NULL to make this function return the
* extracted section.
*
* If not specified, the contents will be sent to "stdout".
* @return string If callbackfunc is not NULL returns TRUE on
* success.
*
* If callbackfunc is set to NULL, returns the
* extracted section as a string.
* @throws MailparseException
*
*/
function mailparse_msg_extract_part_file($mimemail, $filename, ?callable $callbackfunc = null): string
{
error_clear_last();
if ($callbackfunc !== null) {
$safeResult = \mailparse_msg_extract_part_file($mimemail, $filename, $callbackfunc);
} else {
$safeResult = \mailparse_msg_extract_part_file($mimemail, $filename);
}
if ($safeResult === false) {
throw MailparseException::createFromPhpError();
}
return $safeResult;
}
/**
* Frees a MIME resource.
*
* @param resource $mimemail A valid MIME resource allocated by
* mailparse_msg_create or
* mailparse_msg_parse_file.
* @throws MailparseException
*
*/
function mailparse_msg_free($mimemail): void
{
error_clear_last();
$safeResult = \mailparse_msg_free($mimemail);
if ($safeResult === false) {
throw MailparseException::createFromPhpError();
}
}
/**
* Parses a file.
* This is the optimal way of parsing a mail file that you have on disk.
*
* @param string $filename Path to the file holding the message.
* The file is opened and streamed through the parser.
*
* The message contained in filename is supposed to end with a newline
* (CRLF); otherwise the last line of the message will not be parsed.
* @return resource Returns a MIME resource representing the structure.
* @throws MailparseException
*
*/
function mailparse_msg_parse_file(string $filename)
{
error_clear_last();
$safeResult = \mailparse_msg_parse_file($filename);
if ($safeResult === false) {
throw MailparseException::createFromPhpError();
}
return $safeResult;
}
/**
* Incrementally parse data into the supplied mime mail resource.
*
* This function allow you to stream portions of a file at a time, rather
* than read and parse the whole thing.
*
* @param resource $mimemail A valid MIME resource.
* @param string $data The final chunk of data is supposed to end with a newline
* (CRLF); otherwise the last line of the message will not be parsed.
* @throws MailparseException
*
*/
function mailparse_msg_parse($mimemail, string $data): void
{
error_clear_last();
$safeResult = \mailparse_msg_parse($mimemail, $data);
if ($safeResult === false) {
throw MailparseException::createFromPhpError();
}
}
/**
* Streams data from the source file pointer, apply
* encoding and write to the destination file pointer.
*
* @param resource $sourcefp A valid file handle. The file is streamed through the parser.
* @param resource $destfp The destination file handle in which the encoded data will be written.
* @param string $encoding One of the character encodings supported by the
* mbstring module.
* @throws MailparseException
*
*/
function mailparse_stream_encode($sourcefp, $destfp, string $encoding): void
{
error_clear_last();
$safeResult = \mailparse_stream_encode($sourcefp, $destfp, $encoding);
if ($safeResult === false) {
throw MailparseException::createFromPhpError();
}
}

View File

@@ -0,0 +1,636 @@
<?php
namespace Safe;
use Safe\Exceptions\MbstringException;
/**
* Returns a string containing the character specified by the Unicode code point value,
* encoded in the specified encoding.
*
* This function complements mb_ord.
*
* @param int $codepoint A Unicode codepoint value, e.g. 128024 for U+1F418 ELEPHANT
* @param null|string $encoding The encoding
* parameter is the character encoding. If it is omitted or NULL, the internal character
* encoding value will be used.
* @return string A string containing the requested character, if it can be represented in the specified
* encoding.
* @throws MbstringException
*
*/
function mb_chr(int $codepoint, ?string $encoding = null): string
{
error_clear_last();
if ($encoding !== null) {
$safeResult = \mb_chr($codepoint, $encoding);
} else {
$safeResult = \mb_chr($codepoint);
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Converts string from from_encoding,
* or the current internal encoding, to to_encoding.
* If string is an array, all its string values will be
* converted recursively.
*
* @param array|string $string The string or array to be converted.
* @param string $to_encoding The desired encoding of the result.
* @param mixed $from_encoding The current encoding used to interpret string.
* Multiple encodings may be specified as an array or comma separated
* list, in which case the correct encoding will be guessed using the
* same algorithm as mb_detect_encoding.
*
* If from_encoding is omitted or NULL, the
* mbstring.internal_encoding setting
* will be used if set, otherwise the default_charset setting.
*
* See supported encodings
* for valid values of to_encoding
* and from_encoding.
* @return array|string The encoded string or array on success.
* @throws MbstringException
*
*/
function mb_convert_encoding($string, string $to_encoding, $from_encoding = null)
{
error_clear_last();
if ($from_encoding !== null) {
$safeResult = \mb_convert_encoding($string, $to_encoding, $from_encoding);
} else {
$safeResult = \mb_convert_encoding($string, $to_encoding);
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Converts
* character encoding of variables var and vars in
* encoding from_encoding to encoding
* to_encoding.
*
* mb_convert_variables join strings in Array
* or Object to detect encoding, since encoding detection tends to
* fail for short strings. Therefore, it is impossible to mix
* encoding in single array or object.
*
* @param string $to_encoding The encoding that the string is being converted to.
* @param array|string $from_encoding from_encoding is specified as an array
* or comma separated string, it tries to detect encoding from
* from-coding. When from_encoding
* is omitted, detect_order is used.
* @param array|object|string $var var is the reference to the
* variable being converted. String, Array and Object are accepted.
* mb_convert_variables assumes all parameters
* have the same encoding.
* @param array|object|string $vars Additional vars.
* @return string The character encoding before conversion for success.
* @throws MbstringException
*
*/
function mb_convert_variables(string $to_encoding, $from_encoding, &$var, ...$vars): string
{
error_clear_last();
$safeResult = \mb_convert_variables($to_encoding, $from_encoding, $var, ...$vars);
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Sets the automatic character
* encoding detection order to encoding.
*
* @param non-empty-list|non-falsy-string|null $encoding encoding is an array or
* comma separated list of character encoding. See supported encodings.
*
* If encoding is omitted or NULL, it returns
* the current character encoding detection order as array.
*
* This setting affects mb_detect_encoding and
* mb_send_mail.
*
* mbstring currently implements the following
* encoding detection filters. If there is an invalid byte sequence
* for the following encodings, encoding detection will fail.
*
* For ISO-8859-*, mbstring
* always detects as ISO-8859-*.
*
* For UTF-16, UTF-32,
* UCS2 and UCS4, encoding
* detection will fail always.
* @return bool|list When setting the encoding detection order, TRUE is returned on success.
*
* When getting the encoding detection order, an ordered array of the encodings is returned.
* @throws MbstringException
*
*/
function mb_detect_order($encoding = null)
{
error_clear_last();
if ($encoding !== null) {
$safeResult = \mb_detect_order($encoding);
} else {
$safeResult = \mb_detect_order();
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns an array of aliases for a known encoding type.
*
* @param string $encoding The encoding type being checked, for aliases.
* @return false|list Returns a numerically indexed array of encoding aliases.
*
*/
function mb_encoding_aliases(string $encoding)
{
error_clear_last();
$safeResult = \mb_encoding_aliases($encoding);
return $safeResult;
}
/**
* Scans string for matches to
* pattern, then replaces the matched text
* with the output of callback function.
*
* The behavior of this function is almost identical to mb_ereg_replace,
* except for the fact that instead of
* replacement parameter, one should specify a
* callback.
*
* @param string $pattern The regular expression pattern.
*
* Multibyte characters may be used in pattern.
* @param callable(array):string $callback A callback that will be called and passed an array of matched elements
* in the string string. The callback should
* return the replacement string.
*
* You'll often need the callback function
* for a mb_ereg_replace_callback in just one place.
* In this case you can use an
* anonymous function to
* declare the callback within the call to
* mb_ereg_replace_callback. By doing it this way
* you have all information for the call in one place and do not
* clutter the function namespace with a callback function's name
* not used anywhere else.
* @param string $string The string being checked.
* @param null|string $options The search option. See mb_regex_set_options for explanation.
* @return null|string The resultant string on success.
* If string is not valid for the current encoding, NULL
* is returned.
* @throws MbstringException
*
*/
function mb_ereg_replace_callback(string $pattern, callable $callback, string $string, ?string $options = null): ?string
{
error_clear_last();
if ($options !== null) {
$safeResult = \mb_ereg_replace_callback($pattern, $callback, $string, $options);
} else {
$safeResult = \mb_ereg_replace_callback($pattern, $callback, $string);
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param string $pattern The regular expression pattern.
*
* Multibyte characters may be used in pattern.
* @param string $replacement The replacement text.
* @param string $string The string being checked.
* @param null|string $options
* @return null|string The resultant string on success.
* If string is not valid for the current encoding, NULL
* is returned.
* @throws MbstringException
*
*/
function mb_ereg_replace(string $pattern, string $replacement, string $string, ?string $options = null): ?string
{
error_clear_last();
if ($options !== null) {
$safeResult = \mb_ereg_replace($pattern, $replacement, $string, $options);
} else {
$safeResult = \mb_ereg_replace($pattern, $replacement, $string);
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @return array
* @throws MbstringException
*
*/
function mb_ereg_search_getregs(): array
{
error_clear_last();
$safeResult = \mb_ereg_search_getregs();
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* mb_ereg_search_init sets
* string and pattern
* for a multibyte regular expression. These values are used for
* mb_ereg_search,
* mb_ereg_search_pos, and
* mb_ereg_search_regs.
*
* @param string $string The search string.
* @param null|string $pattern The search pattern.
* @param null|string $options The search option. See mb_regex_set_options for explanation.
* @throws MbstringException
*
*/
function mb_ereg_search_init(string $string, ?string $pattern = null, ?string $options = null): void
{
error_clear_last();
if ($options !== null) {
$safeResult = \mb_ereg_search_init($string, $pattern, $options);
} elseif ($pattern !== null) {
$safeResult = \mb_ereg_search_init($string, $pattern);
} else {
$safeResult = \mb_ereg_search_init($string);
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
}
/**
* Returns the matched part of a multibyte regular expression.
*
* @param null|string $pattern The search pattern.
* @param null|string $options The search option. See mb_regex_set_options for explanation.
* @return array
* @throws MbstringException
*
*/
function mb_ereg_search_regs(?string $pattern = null, ?string $options = null): array
{
error_clear_last();
if ($options !== null) {
$safeResult = \mb_ereg_search_regs($pattern, $options);
} elseif ($pattern !== null) {
$safeResult = \mb_ereg_search_regs($pattern);
} else {
$safeResult = \mb_ereg_search_regs();
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param int $offset The position to set. If it is negative, it counts from the end of the string.
* @throws MbstringException
*
*/
function mb_ereg_search_setpos(int $offset): void
{
error_clear_last();
$safeResult = \mb_ereg_search_setpos($offset);
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
}
/**
*
*
* @param string $pattern The regular expression pattern. Multibyte characters may be used. The case will be ignored.
* @param string $replacement The replacement text.
* @param string $string The searched string.
* @param null|string $options
* @return string The resultant string.
* If string is not valid for the current encoding, NULL
* is returned.
* @throws MbstringException
*
*/
function mb_eregi_replace(string $pattern, string $replacement, string $string, ?string $options = null): string
{
error_clear_last();
if ($options !== null) {
$safeResult = \mb_eregi_replace($pattern, $replacement, $string, $options);
} else {
$safeResult = \mb_eregi_replace($pattern, $replacement, $string);
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param string $type If type is not specified or is specified as "all",
* "internal_encoding", "http_input",
* "http_output", "http_output_conv_mimetypes",
* "mail_charset", "mail_header_encoding",
* "mail_body_encoding", "illegal_chars",
* "encoding_translation", "language",
* "detect_order", "substitute_character"
* and "strict_detection"
* will be returned.
*
* If type is specified as
* "internal_encoding", "http_input",
* "http_output", "http_output_conv_mimetypes",
* "mail_charset", "mail_header_encoding",
* "mail_body_encoding", "illegal_chars",
* "encoding_translation", "language",
* "detect_order", "substitute_character"
* or "strict_detection"
* the specified setting parameter will be returned.
* @return mixed An array of type information if type
* is not specified, otherwise a specific type.
* @throws MbstringException
*
*/
function mb_get_info(string $type = "all")
{
error_clear_last();
$safeResult = \mb_get_info($type);
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Set/Get the HTTP output character encoding.
* Output after this function is called will be converted from the set internal encoding to encoding.
*
* @param null|string $encoding If encoding is set,
* mb_http_output sets the HTTP output character
* encoding to encoding.
*
* If encoding is omitted,
* mb_http_output returns the current HTTP output
* character encoding.
* @return bool|string If encoding is omitted,
* mb_http_output returns the current HTTP output
* character encoding. Otherwise,
* Returns TRUE on success.
* @throws MbstringException
*
*/
function mb_http_output(?string $encoding = null)
{
error_clear_last();
if ($encoding !== null) {
$safeResult = \mb_http_output($encoding);
} else {
$safeResult = \mb_http_output();
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Set/Get the internal character encoding
*
* @param null|string $encoding encoding is the character encoding name
* used for the HTTP input character encoding conversion, HTTP output
* character encoding conversion, and the default character encoding
* for string functions defined by the mbstring module.
* You should notice that the internal encoding is totally different from the one for multibyte regex.
* @return bool|string If encoding is set, then
* Returns TRUE on success.
* In this case, the character encoding for multibyte regex is NOT changed.
* If encoding is omitted, then
* the current character encoding name is returned.
* @throws MbstringException
*
*/
function mb_internal_encoding(?string $encoding = null)
{
error_clear_last();
if ($encoding !== null) {
$safeResult = \mb_internal_encoding($encoding);
} else {
$safeResult = \mb_internal_encoding();
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the Unicode code point value of the given character.
*
* This function complements mb_chr.
*
* @param string $string A string
* @param null|string $encoding The encoding
* parameter is the character encoding. If it is omitted or NULL, the internal character
* encoding value will be used.
* @return int The Unicode code point for the first character of string.
* @throws MbstringException
*
*/
function mb_ord(string $string, ?string $encoding = null): int
{
error_clear_last();
if ($encoding !== null) {
$safeResult = \mb_ord($string, $encoding);
} else {
$safeResult = \mb_ord($string);
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Parses GET/POST/COOKIE data and
* sets global variables. Since PHP does not provide raw POST/COOKIE
* data, it can only be used for GET data for now. It parses URL
* encoded data, detects encoding, converts coding to internal
* encoding and set values to the result array or
* global variables.
*
* @param string $string The URL encoded data.
* @param array|null $result An array containing decoded and character encoded converted values.
* @throws MbstringException
*
*/
function mb_parse_str(string $string, ?array &$result): void
{
error_clear_last();
$safeResult = \mb_parse_str($string, $result);
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
}
/**
* Set/Get character encoding for a multibyte regex.
*
* @param null|string $encoding The encoding
* parameter is the character encoding. If it is omitted or NULL, the internal character
* encoding value will be used.
* @return bool|string
* @throws MbstringException
*
*/
function mb_regex_encoding(?string $encoding = null)
{
error_clear_last();
if ($encoding !== null) {
$safeResult = \mb_regex_encoding($encoding);
} else {
$safeResult = \mb_regex_encoding();
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}
/**
* Sends email. Headers and messages are converted and encoded according
* to the mb_language setting. It's a wrapper function
* for mail, so see also mail for details.
*
* @param string $to The mail addresses being sent to. Multiple
* recipients may be specified by putting a comma between each
* address in to.
* This parameter is not automatically encoded.
* @param string $subject The subject of the mail.
* @param string $message The message of the mail.
* @param array|null|string $additional_headers String or array to be inserted at the end of the email header.
*
* This is typically used to add extra headers (From, Cc, and Bcc).
* Multiple extra headers should be separated with a CRLF (\r\n).
* Validate parameter not to be injected unwanted headers by attackers.
*
* If an array is passed, its keys are the header names and its
* values are the respective header values.
*
* When sending mail, the mail must contain
* a From header. This can be set with the
* additional_headers parameter, or a default
* can be set in php.ini.
*
* Failing to do this will result in an error
* message similar to Warning: mail(): "sendmail_from" not
* set in php.ini or custom "From:" header missing.
* The From header sets also
* Return-Path under Windows.
*
* If messages are not received, try using a LF (\n) only.
* Some Unix mail transfer agents (most notably
* qmail) replace LF by CRLF
* automatically (which leads to doubling CR if CRLF is used).
* This should be a last resort, as it does not comply with
* RFC 2822.
* @param null|string $additional_params additional_params is a MTA command line
* parameter. It is useful when setting the correct Return-Path
* header when using sendmail.
*
* This parameter is escaped by escapeshellcmd internally
* to prevent command execution. escapeshellcmd prevents
* command execution, but allows to add additional parameters. For security reason,
* this parameter should be validated.
*
* Since escapeshellcmd is applied automatically, some characters
* that are allowed as email addresses by internet RFCs cannot be used. Programs
* that are required to use these characters mail cannot be used.
*
* The user that the webserver runs as should be added as a trusted user to the
* sendmail configuration to prevent a 'X-Warning' header from being added
* to the message when the envelope sender (-f) is set using this method.
* For sendmail users, this file is /etc/mail/trusted-users.
* @throws MbstringException
*
*/
function mb_send_mail(string $to, string $subject, string $message, $additional_headers = [], ?string $additional_params = null): void
{
error_clear_last();
if ($additional_params !== null) {
$safeResult = \mb_send_mail($to, $subject, $message, $additional_headers, $additional_params);
} else {
$safeResult = \mb_send_mail($to, $subject, $message, $additional_headers);
}
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
}
/**
*
*
* @param string $pattern The regular expression pattern.
* @param string $string The string being split.
* @param int $limit
* @return list The result as an array.
* @throws MbstringException
*
*/
function mb_split(string $pattern, string $string, int $limit = -1): array
{
error_clear_last();
$safeResult = \mb_split($pattern, $string, $limit);
if ($safeResult === false) {
throw MbstringException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,548 @@
<?php
namespace Safe;
use Safe\Exceptions\MiscException;
/**
* Defines a named constant at runtime.
*
* @param string $constant_name The name of the constant.
*
* It is possible to define constants with reserved or
* even invalid names, whose value can (only) be retrieved with
* constant. However, doing so is not recommended.
* @param mixed $value The value of the constant.
*
* While it is possible to define resource constants, it is
* not recommended and may cause unpredictable behavior.
* @param bool $case_insensitive If set to TRUE, the constant will be defined case-insensitive.
* The default behavior is case-sensitive; i.e.
* CONSTANT and Constant represent
* different values.
*
* Case-insensitive constants are stored as lower-case.
* @throws MiscException
*
*/
function define(string $constant_name, $value, bool $case_insensitive = false): void
{
error_clear_last();
$safeResult = \define($constant_name, $value, $case_insensitive);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
}
/**
* Prints out or returns a syntax highlighted version of the code contained
* in filename using the colors defined in the
* built-in syntax highlighter for PHP.
*
* Many servers are configured to automatically highlight files
* with a phps extension. For example,
* example.phps when viewed will show the
* syntax highlighted source of the file. To enable this, add this
* line to the httpd.conf:
*
* @param string $filename Path to the PHP file to be highlighted.
* @param bool $return Set this parameter to TRUE to make this function return the
* highlighted code.
* @return bool|string If return is set to TRUE, returns the highlighted
* code as a string instead of printing it out. Otherwise, it will return
* TRUE on success.
* @throws MiscException
*
*/
function highlight_file(string $filename, bool $return = false)
{
error_clear_last();
$safeResult = \highlight_file($filename, $return);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param string $string The PHP code to be highlighted. This should include the opening tag.
* @param bool $return Set this parameter to TRUE to make this function return the
* highlighted code.
* @return bool|string If return is set to TRUE, returns the highlighted
* code as a string instead of printing it out.
* Otherwise, it will return TRUE.
*
*/
function highlight_string(string $string, bool $return = false)
{
error_clear_last();
$safeResult = \highlight_string($string, $return);
return $safeResult;
}
/**
*
*
* @param bool $as_number Whether the high resolution time should be returned as array
* or number.
* @return array{0:int,1:int}|float|int Returns an array of integers in the form [seconds, nanoseconds], if the
* parameter as_number is false. Otherwise the nanoseconds
* are returned as int (64bit platforms) or float
* (32bit platforms).
* Returns FALSE on failure.
* @throws MiscException
*
*/
function hrtime(bool $as_number = false)
{
error_clear_last();
$safeResult = \hrtime($as_number);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
return $safeResult;
}
/**
* Pack given arguments into a binary string according to
* format.
*
* The idea for this function was taken from Perl and all formatting codes
* work the same as in Perl. However, there are some formatting codes that are
* missing such as Perl's "u" format code.
*
* Note that the distinction between signed and unsigned values only
* affects the function unpack, where as
* function pack gives the same result for
* signed and unsigned format codes.
*
* @param string $format The format string consists of format codes
* followed by an optional repeater argument. The repeater argument can
* be either an integer value or * for repeating to
* the end of the input data. For a, A, h, H the repeat count specifies
* how many characters of one data argument are taken, for @ it is the
* absolute position where to put the next data, for everything else the
* repeat count specifies how many data arguments are consumed and packed
* into the resulting binary string.
*
* Currently implemented formats are:
*
* pack format characters
*
*
*
* Code
* Description
*
*
*
*
* a
* NUL-padded string
*
*
* A
* SPACE-padded string
*
* h
* Hex string, low nibble first
*
* H
* Hex string, high nibble first
* csigned char
*
* C
* unsigned char
*
* s
* signed short (always 16 bit, machine byte order)
*
*
* S
* unsigned short (always 16 bit, machine byte order)
*
*
* n
* unsigned short (always 16 bit, big endian byte order)
*
*
* v
* unsigned short (always 16 bit, little endian byte order)
*
*
* i
* signed integer (machine dependent size and byte order)
*
*
* I
* unsigned integer (machine dependent size and byte order)
*
*
* l
* signed long (always 32 bit, machine byte order)
*
*
* L
* unsigned long (always 32 bit, machine byte order)
*
*
* N
* unsigned long (always 32 bit, big endian byte order)
*
*
* V
* unsigned long (always 32 bit, little endian byte order)
*
*
* q
* signed long long (always 64 bit, machine byte order)
*
*
* Q
* unsigned long long (always 64 bit, machine byte order)
*
*
* J
* unsigned long long (always 64 bit, big endian byte order)
*
*
* P
* unsigned long long (always 64 bit, little endian byte order)
*
*
* f
* float (machine dependent size and representation)
*
*
* g
* float (machine dependent size, little endian byte order)
*
*
* G
* float (machine dependent size, big endian byte order)
*
*
* d
* double (machine dependent size and representation)
*
*
* e
* double (machine dependent size, little endian byte order)
*
*
* E
* double (machine dependent size, big endian byte order)
*
*
* x
* NUL byte
*
*
* X
* Back up one byte
*
*
* Z
* NUL-padded string
*
*
* @
* NUL-fill to absolute position
*
*
*
*
* @param mixed $values
* @return string Returns a binary string containing data.
*
*/
function pack(string $format, ...$values): string
{
error_clear_last();
if ($values !== []) {
$safeResult = \pack($format, ...$values);
} else {
$safeResult = \pack($format);
}
return $safeResult;
}
/**
* Convert string from one codepage to another.
*
* @param int|string $in_codepage The codepage of the subject string.
* Either the codepage name or identifier.
* @param int|string $out_codepage The codepage to convert the subject string to.
* Either the codepage name or identifier.
* @param string $subject The string to convert.
* @return string The subject string converted to
* out_codepage.
* @throws MiscException
*
*/
function sapi_windows_cp_conv($in_codepage, $out_codepage, string $subject): string
{
error_clear_last();
$safeResult = \sapi_windows_cp_conv($in_codepage, $out_codepage, $subject);
if ($safeResult === null) {
throw MiscException::createFromPhpError();
}
return $safeResult;
}
/**
* Set the codepage of the current process.
*
* @param int $codepage A codepage identifier.
* @throws MiscException
*
*/
function sapi_windows_cp_set(int $codepage): void
{
error_clear_last();
$safeResult = \sapi_windows_cp_set($codepage);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
}
/**
* Sends a CTRL event to another process in the same process group.
*
* @param int $event The CTRL event to send;
* either PHP_WINDOWS_EVENT_CTRL_C
* or PHP_WINDOWS_EVENT_CTRL_BREAK.
* @param int $pid The ID of the process to which to send the event to. If 0
* is given, the event is sent to all processes of the process group.
* @throws MiscException
*
*/
function sapi_windows_generate_ctrl_event(int $event, int $pid = 0): void
{
error_clear_last();
$safeResult = \sapi_windows_generate_ctrl_event($event, $pid);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
}
/**
* Sets or removes a CTRL event handler, which allows Windows
* CLI processes to intercept or ignore CTRL+C and
* CTRL+BREAK events. Note that in multithreaded environments,
* this is only possible when called from the main thread.
*
* @param callable|null $handler A callback function to set or remove. If set, this function will be called
* whenever a
*
* CTRL
* C
*
* or
*
* CTRL
* BREAK
*
* event occurs.
* The function is supposed to have the following signature:
*
* voidhandler
* intevent
*
*
*
* event
*
*
* The CTRL event which has been received;
* either PHP_WINDOWS_EVENT_CTRL_C
* or PHP_WINDOWS_EVENT_CTRL_BREAK.
*
*
*
*
* Setting a NULL handler causes the process to ignore
*
* CTRL
* C
*
* events, but not
*
* CTRL
* BREAK
*
* events.
* @param bool $add
* @throws MiscException
*
*/
function sapi_windows_set_ctrl_handler(?callable $handler, bool $add = true): void
{
error_clear_last();
$safeResult = \sapi_windows_set_ctrl_handler($handler, $add);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
}
/**
* If enable is NULL, the function returns TRUE if the stream stream has VT100 control codes enabled.
*
* If enable is a bool, the function will try to enable or disable the VT100 features of the stream stream.
* If the feature has been successfully enabled (or disabled).
*
* At startup, PHP tries to enable the VT100 feature of the STDOUT/STDERR streams. By the way, if those streams are redirected to a file, the VT100 features may not be enabled.
*
* If VT100 support is enabled, it is possible to use control sequences as they are known from the VT100 terminal.
* They allow the modification of the terminal's output. On Windows these sequences are called Console Virtual Terminal Sequences.
*
* @param resource $stream The stream on which the function will operate.
* @param bool|null $enable If bool, the VT100 feature will be enabled (if TRUE) or disabled (if FALSE).
* @throws MiscException
*
*/
function sapi_windows_vt100_support($stream, ?bool $enable = null): void
{
error_clear_last();
if ($enable !== null) {
$safeResult = \sapi_windows_vt100_support($stream, $enable);
} else {
$safeResult = \sapi_windows_vt100_support($stream);
}
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
}
/**
*
*
* @param int $seconds Halt time in seconds (must be greater than or equal to 0).
* @return false|int Returns zero on success.
*
* If the call was interrupted by a signal, sleep returns
* a non-zero value. On Windows, this value will always be
* 192 (the value of the
* WAIT_IO_COMPLETION constant within the Windows API).
* On other platforms, the return value will be the number of seconds left to
* sleep.
*
*/
function sleep(int $seconds)
{
error_clear_last();
$safeResult = \sleep($seconds);
return $safeResult;
}
/**
* Delays program execution for the given number of
* seconds and nanoseconds.
*
* @param int $seconds Must be a non-negative integer.
* @param int $nanoseconds Must be a non-negative integer less than 1 billion.
* @return array{seconds:0|positive-int,nanoseconds:0|positive-int}|bool Returns TRUE on success.
*
* If the delay was interrupted by a signal, an associative array will be
* returned with the components:
*
*
*
* seconds - number of seconds remaining in
* the delay
*
*
*
*
* nanoseconds - number of nanoseconds
* remaining in the delay
*
*
*
* @throws MiscException
*
*/
function time_nanosleep(int $seconds, int $nanoseconds)
{
error_clear_last();
$safeResult = \time_nanosleep($seconds, $nanoseconds);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
return $safeResult;
}
/**
* Makes the script sleep until the specified
* timestamp.
*
* @param float $timestamp The timestamp when the script should wake.
* @throws MiscException
*
*/
function time_sleep_until(float $timestamp): void
{
error_clear_last();
$safeResult = \time_sleep_until($timestamp);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
}
/**
* Unpacks from a binary string into an array according to the given
* format.
*
* The unpacked data is stored in an associative array. To
* accomplish this you have to name the different format codes and
* separate them by a slash /. If a repeater argument is present,
* then each of the array keys will have a sequence number behind
* the given name.
*
* Changes were made to bring this function into line with Perl:
*
*
* The "a" code now retains trailing NULL bytes.
*
*
* The "A" code now strips all trailing ASCII whitespace (spaces, tabs,
* newlines, carriage returns, and NULL bytes).
*
*
* The "Z" code was added for NULL-padded strings, and removes trailing
* NULL bytes.
*
*
*
* @param string $format See pack for an explanation of the format codes.
* @param string $string The packed data.
* @param int $offset The offset to begin unpacking from.
* @return array Returns an associative array containing unpacked elements of binary
* string.
* @throws MiscException
*
*/
function unpack(string $format, string $string, int $offset = 0): array
{
error_clear_last();
$safeResult = \unpack($format, $string, $offset);
if ($safeResult === false) {
throw MiscException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,938 @@
<?php
namespace Safe;
use Safe\Exceptions\MysqlException;
/**
* mysql_close closes the non-persistent connection to
* the MySQL server that's associated with the specified link identifier. If
* link_identifier isn't specified, the last opened
* link is used.
*
*
* Open non-persistent MySQL connections and result sets are automatically destroyed when a
* PHP script finishes its execution. So, while explicitly closing open
* connections and freeing result sets is optional, doing so is recommended.
* This will immediately return resources to PHP and MySQL, which can
* improve performance. For related information, see
* freeing resources
*
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no connection is found or
* established, an E_WARNING level error is
* generated.
* @throws MysqlException
*
*/
function mysql_close($link_identifier = null): void
{
error_clear_last();
$safeResult = \mysql_close($link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
}
/**
* Opens or reuses a connection to a MySQL server.
*
* @param string $server The MySQL server. It can also include a port number. e.g.
* "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for
* the localhost.
*
* If the PHP directive
* mysql.default_host is undefined (default), then the default
* value is 'localhost:3306'. In SQL safe mode, this parameter is ignored
* and value 'localhost:3306' is always used.
* @param string $username The username. Default value is defined by mysql.default_user. In
* SQL safe mode, this parameter is ignored and the name of the user that
* owns the server process is used.
* @param string $password The password. Default value is defined by mysql.default_password. In
* SQL safe mode, this parameter is ignored and empty password is used.
* @param bool $new_link If a second call is made to mysql_connect
* with the same arguments, no new link will be established, but
* instead, the link identifier of the already opened link will be
* returned. The new_link parameter modifies this
* behavior and makes mysql_connect always open
* a new link, even if mysql_connect was called
* before with the same parameters.
* In SQL safe mode, this parameter is ignored.
* @param int $client_flags The client_flags parameter can be a combination
* of the following constants:
* 128 (enable LOAD DATA LOCAL handling),
* MYSQL_CLIENT_SSL,
* MYSQL_CLIENT_COMPRESS,
* MYSQL_CLIENT_IGNORE_SPACE or
* MYSQL_CLIENT_INTERACTIVE.
* Read the section about for further information.
* In SQL safe mode, this parameter is ignored.
* @return resource Returns a MySQL link identifier on success.
* @throws MysqlException
*
*/
function mysql_connect(?string $server = null, ?string $username = null, ?string $password = null, bool $new_link = false, int $client_flags = 0)
{
error_clear_last();
if ($client_flags !== 0) {
$safeResult = \mysql_connect($server, $username, $password, $new_link, $client_flags);
} elseif ($new_link !== false) {
$safeResult = \mysql_connect($server, $username, $password, $new_link);
} elseif ($password !== null) {
$safeResult = \mysql_connect($server, $username, $password);
} elseif ($username !== null) {
$safeResult = \mysql_connect($server, $username);
} elseif ($server !== null) {
$safeResult = \mysql_connect($server);
} else {
$safeResult = \mysql_connect();
}
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* mysql_create_db attempts to create a new
* database on the server associated with the specified link
* identifier.
*
* @param string $database_name The name of the database being created.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @throws MysqlException
*
*/
function mysql_create_db(string $database_name, $link_identifier = null): void
{
error_clear_last();
$safeResult = \mysql_create_db($database_name, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
}
/**
* mysql_data_seek moves the internal row
* pointer of the MySQL result associated with the specified result
* identifier to point to the specified row number. The next call
* to a MySQL fetch function, such as mysql_fetch_assoc,
* would return that row.
*
* row_number starts at 0. The
* row_number should be a value in the range from 0 to
* mysql_num_rows - 1. However if the result set
* is empty (mysql_num_rows == 0), a seek to 0 will
* fail with an E_WARNING and
* mysql_data_seek will return FALSE.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @param int $row_number The desired row number of the new result pointer.
* @throws MysqlException
*
*/
function mysql_data_seek($result, int $row_number): void
{
error_clear_last();
$safeResult = \mysql_data_seek($result, $row_number);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
}
/**
* Retrieve the database name from a call to
* mysql_list_dbs.
*
* @param resource $result The result pointer from a call to mysql_list_dbs.
* @param int $row The index into the result set.
* @param mixed $field The field name.
* @return string Returns the database name on success. If FALSE
* is returned, use mysql_error to determine the nature
* of the error.
* @throws MysqlException
*
*/
function mysql_db_name($result, int $row, $field = null): string
{
error_clear_last();
$safeResult = \mysql_db_name($result, $row, $field);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* mysql_db_query selects a database, and executes a
* query on it.
*
* @param string $database The name of the database that will be selected.
* @param string $query The MySQL query.
*
* Data inside the query should be properly escaped.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return bool|resource Returns a positive MySQL result resource to the query result. The function also returns TRUE/FALSE for
* INSERT/UPDATE/DELETE
* queries to indicate success/failure.
* @throws MysqlException
*
*/
function mysql_db_query(string $database, string $query, $link_identifier = null)
{
error_clear_last();
$safeResult = \mysql_db_query($database, $query, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* mysql_drop_db attempts to drop (remove) an
* entire database from the server associated with the specified
* link identifier. This function is deprecated, it is preferable to use
* mysql_query to issue an sql
* DROP DATABASE statement instead.
*
* @param string $database_name The name of the database that will be deleted.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @throws MysqlException
*
*/
function mysql_drop_db(string $database_name, $link_identifier = null): void
{
error_clear_last();
$safeResult = \mysql_drop_db($database_name, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
}
/**
* Returns an array that corresponds to the lengths of each field
* in the last row fetched by MySQL.
*
* mysql_fetch_lengths stores the lengths of
* each result column in the last row returned by
* mysql_fetch_row,
* mysql_fetch_assoc,
* mysql_fetch_array, and
* mysql_fetch_object in an array, starting at
* offset 0.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @return array An array of lengths on success.
* @throws MysqlException
*
*/
function mysql_fetch_lengths($result): array
{
error_clear_last();
$safeResult = \mysql_fetch_lengths($result);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* mysql_field_flags returns the field flags of
* the specified field. The flags are reported as a single word
* per flag separated by a single space, so that you can split the
* returned value using explode.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @param int $field_offset The numerical field offset. The
* field_offset starts at 0. If
* field_offset does not exist, an error of level
* E_WARNING is also issued.
* @return string Returns a string of flags associated with the result.
*
* The following flags are reported, if your version of MySQL
* is current enough to support them: "not_null",
* "primary_key", "unique_key",
* "multiple_key", "blob",
* "unsigned", "zerofill",
* "binary", "enum",
* "auto_increment" and "timestamp".
* @throws MysqlException
*
*/
function mysql_field_flags($result, int $field_offset): string
{
error_clear_last();
$safeResult = \mysql_field_flags($result, $field_offset);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* mysql_field_len returns the length of the
* specified field.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @param int $field_offset The numerical field offset. The
* field_offset starts at 0. If
* field_offset does not exist, an error of level
* E_WARNING is also issued.
* @return int The length of the specified field index on success.
* @throws MysqlException
*
*/
function mysql_field_len($result, int $field_offset): int
{
error_clear_last();
$safeResult = \mysql_field_len($result, $field_offset);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* mysql_field_name returns the name of the
* specified field index.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @param int $field_offset The numerical field offset. The
* field_offset starts at 0. If
* field_offset does not exist, an error of level
* E_WARNING is also issued.
* @return string The name of the specified field index on success.
* @throws MysqlException
*
*/
function mysql_field_name($result, int $field_offset): string
{
error_clear_last();
$safeResult = \mysql_field_name($result, $field_offset);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Seeks to the specified field offset. If the next call to
* mysql_fetch_field doesn't include a field
* offset, the field offset specified in
* mysql_field_seek will be returned.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @param int $field_offset The numerical field offset. The
* field_offset starts at 0. If
* field_offset does not exist, an error of level
* E_WARNING is also issued.
* @throws MysqlException
*
*/
function mysql_field_seek($result, int $field_offset): void
{
error_clear_last();
$safeResult = \mysql_field_seek($result, $field_offset);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
}
/**
* mysql_free_result will free all memory
* associated with the result identifier result.
*
* mysql_free_result only needs to be called if
* you are concerned about how much memory is being used for queries
* that return large result sets. All associated result memory is
* automatically freed at the end of the script's execution.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @throws MysqlException
*
*/
function mysql_free_result($result): void
{
error_clear_last();
$safeResult = \mysql_free_result($result);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
}
/**
* Describes the type of connection in use for the connection, including the
* server host name.
*
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return string Returns a string describing the type of MySQL connection in use for the
* connection.
* @throws MysqlException
*
*/
function mysql_get_host_info($link_identifier = null): string
{
error_clear_last();
$safeResult = \mysql_get_host_info($link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the MySQL protocol.
*
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return int Returns the MySQL protocol on success.
* @throws MysqlException
*
*/
function mysql_get_proto_info($link_identifier = null): int
{
error_clear_last();
$safeResult = \mysql_get_proto_info($link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the MySQL server version.
*
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return string Returns the MySQL server version on success.
* @throws MysqlException
*
*/
function mysql_get_server_info($link_identifier = null): string
{
error_clear_last();
$safeResult = \mysql_get_server_info($link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns detailed information about the last query.
*
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return string Returns information about the statement on success. See the example below for which statements provide information,
* and what the returned value may look like. Statements that are not listed
* will return FALSE.
* @throws MysqlException
*
*/
function mysql_info($link_identifier = null): string
{
error_clear_last();
$safeResult = \mysql_info($link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns a result pointer containing the databases available from the
* current mysql daemon.
*
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return resource Returns a result pointer resource on success. Use the mysql_tablename function to traverse
* this result pointer, or any function for result tables, such as
* mysql_fetch_array.
* @throws MysqlException
*
*/
function mysql_list_dbs($link_identifier = null)
{
error_clear_last();
$safeResult = \mysql_list_dbs($link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves information about the given table name.
*
* This function is deprecated. It is preferable to use
* mysql_query to issue an SQL SHOW COLUMNS FROM
* table [LIKE 'name'] statement instead.
*
* @param string $database_name The name of the database that's being queried.
* @param string $table_name The name of the table that's being queried.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return resource A result pointer resource on success.
*
* The returned result can be used with mysql_field_flags,
* mysql_field_len,
* mysql_field_name and
* mysql_field_type.
* @throws MysqlException
*
*/
function mysql_list_fields(string $database_name, string $table_name, $link_identifier = null)
{
error_clear_last();
$safeResult = \mysql_list_fields($database_name, $table_name, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the current MySQL server threads.
*
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return resource A result pointer resource on success.
* @throws MysqlException
*
*/
function mysql_list_processes($link_identifier = null)
{
error_clear_last();
$safeResult = \mysql_list_processes($link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves a list of table names from a MySQL database.
*
* This function is deprecated. It is preferable to use
* mysql_query to issue an SQL SHOW TABLES
* [FROM db_name] [LIKE 'pattern'] statement instead.
*
* @param string $database The name of the database
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return resource A result pointer resource on success.
*
* Use the mysql_tablename function to
* traverse this result pointer, or any function for result tables,
* such as mysql_fetch_array.
* @throws MysqlException
*
*/
function mysql_list_tables(string $database, $link_identifier = null)
{
error_clear_last();
$safeResult = \mysql_list_tables($database, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the number of fields from a query.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @return int Returns the number of fields in the result set resource on
* success.
* @throws MysqlException
*
*/
function mysql_num_fields($result): int
{
error_clear_last();
$safeResult = \mysql_num_fields($result);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the number of rows from a result set. This command is only valid
* for statements like SELECT or SHOW that return an actual result set.
* To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or
* DELETE query, use mysql_affected_rows.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @return int The number of rows in a result set on success.
* @throws MysqlException
*
*/
function mysql_num_rows($result): int
{
error_clear_last();
$safeResult = \mysql_num_rows($result);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* mysql_query sends a unique query (multiple queries
* are not supported) to the currently
* active database on the server that's associated with the
* specified link_identifier.
*
* @param string $query An SQL query
*
* The query string should not end with a semicolon.
* Data inside the query should be properly escaped.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return bool|resource For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset,
* mysql_query
* returns a resource on success.
*
* For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
* mysql_query returns TRUE on success.
*
* The returned result resource should be passed to
* mysql_fetch_array, and other
* functions for dealing with result tables, to access the returned data.
*
* Use mysql_num_rows to find out how many rows
* were returned for a SELECT statement or
* mysql_affected_rows to find out how many
* rows were affected by a DELETE, INSERT, REPLACE, or UPDATE
* statement.
*
* mysql_query will also fail and return FALSE
* if the user does not have permission to access the table(s) referenced by
* the query.
* @throws MysqlException
*
*/
function mysql_query(string $query, $link_identifier = null)
{
error_clear_last();
$safeResult = \mysql_query($query, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Escapes special characters in the unescaped_string,
* taking into account the current character set of the connection so that it
* is safe to place it in a mysql_query. If binary data
* is to be inserted, this function must be used.
*
* mysql_real_escape_string calls MySQL's library function
* mysql_real_escape_string, which prepends backslashes to the following characters:
* \x00, \n,
* \r, \, ',
* " and \x1a.
*
* This function must always (with few exceptions) be used to make data
* safe before sending a query to MySQL.
*
* @param string $unescaped_string The string that is to be escaped.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return string Returns the escaped string.
* @throws MysqlException
*
*/
function mysql_real_escape_string(string $unescaped_string, $link_identifier = null): string
{
error_clear_last();
$safeResult = \mysql_real_escape_string($unescaped_string, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the contents of one cell from a MySQL result set.
*
* When working on large result sets, you should consider using one
* of the functions that fetch an entire row (specified below). As
* these functions return the contents of multiple cells in one
* function call, they're MUCH quicker than
* mysql_result. Also, note that specifying a
* numeric offset for the field argument is much quicker than
* specifying a fieldname or tablename.fieldname argument.
*
* @param resource $result The result resource that
* is being evaluated. This result comes from a call to
* mysql_query.
* @param int $row The row number from the result that's being retrieved. Row numbers
* start at 0.
* @param mixed $field The name or offset of the field being retrieved.
*
* It can be the field's offset, the field's name, or the field's table
* dot field name (tablename.fieldname). If the column name has been
* aliased ('select foo as bar from...'), use the alias instead of the
* column name. If undefined, the first field is retrieved.
* @return string The contents of one cell from a MySQL result set on success.
* @throws MysqlException
*
*/
function mysql_result($result, int $row, $field = 0): string
{
error_clear_last();
$safeResult = \mysql_result($result, $row, $field);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Sets the current active database on the server that's associated with the
* specified link identifier. Every subsequent call to
* mysql_query will be made on the active database.
*
* @param string $database_name The name of the database that is to be selected.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @throws MysqlException
*
*/
function mysql_select_db(string $database_name, $link_identifier = null): void
{
error_clear_last();
$safeResult = \mysql_select_db($database_name, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
}
/**
* Sets the default character set for the current connection.
*
* @param string $charset A valid character set name.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @throws MysqlException
*
*/
function mysql_set_charset(string $charset, $link_identifier = null): void
{
error_clear_last();
$safeResult = \mysql_set_charset($charset, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
}
/**
* Retrieves the table name from a result.
*
* This function is deprecated. It is preferable to use
* mysql_query to issue an SQL SHOW TABLES
* [FROM db_name] [LIKE 'pattern'] statement instead.
*
* @param resource $result A result pointer resource that's returned from
* mysql_list_tables.
* @param int $i The integer index (row/table number)
* @return string The name of the table on success.
*
* Use the mysql_tablename function to
* traverse this result pointer, or any function for result tables,
* such as mysql_fetch_array.
* @throws MysqlException
*
*/
function mysql_tablename($result, int $i): string
{
error_clear_last();
$safeResult = \mysql_tablename($result, $i);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the current thread ID. If the connection is lost, and a reconnect
* with mysql_ping is executed, the thread ID will
* change. This means only retrieve the thread ID when needed.
*
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return int The thread ID on success.
* @throws MysqlException
*
*/
function mysql_thread_id($link_identifier = null): int
{
error_clear_last();
$safeResult = \mysql_thread_id($link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}
/**
* mysql_unbuffered_query sends the SQL query
* query to MySQL without automatically
* fetching and buffering the result rows as
* mysql_query does. This saves a considerable
* amount of memory with SQL queries that produce large result sets,
* and you can start working on the result set immediately after the
* first row has been retrieved as you don't have to wait until the
* complete SQL query has been performed. To use
* mysql_unbuffered_query while multiple database
* connections are open, you must specify the optional parameter
* link_identifier to identify which connection
* you want to use.
*
* @param string $query The SQL query to execute.
*
* Data inside the query should be properly escaped.
* @param null|resource $link_identifier The MySQL connection. If the
* link identifier is not specified, the last link opened by
* mysql_connect is assumed. If no such link is found, it
* will try to create one as if mysql_connect had been called
* with no arguments. If no connection is found or established, an
* E_WARNING level error is generated.
* @return bool|resource For SELECT, SHOW, DESCRIBE or EXPLAIN statements,
* mysql_unbuffered_query
* returns a resource on success.
*
* For other type of SQL statements, UPDATE, DELETE, DROP, etc,
* mysql_unbuffered_query returns TRUE on success.
* @throws MysqlException
*
*/
function mysql_unbuffered_query(string $query, $link_identifier = null)
{
error_clear_last();
$safeResult = \mysql_unbuffered_query($query, $link_identifier);
if ($safeResult === false) {
throw MysqlException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Safe;
use Safe\Exceptions\MysqliException;
/**
* Returns client per-process statistics.
*
* @return array|false Returns an array with client stats.
*
*/
function mysqli_get_client_stats()
{
error_clear_last();
$safeResult = \mysqli_get_client_stats();
return $safeResult;
}

View File

@@ -0,0 +1,693 @@
<?php
namespace Safe;
use Safe\Exceptions\NetworkException;
/**
* closelog closes the descriptor being used to write to
* the system logger. The use of closelog is optional.
*
* @return bool Always returns TRUE.
*
*/
function closelog(): bool
{
error_clear_last();
$safeResult = \closelog();
return $safeResult;
}
/**
* Fetch DNS Resource Records associated with the given
* hostname.
*
* @param string $hostname hostname should be a valid DNS hostname such
* as "www.example.com". Reverse lookups can be generated
* using in-addr.arpa notation, but
* gethostbyaddr is more suitable for
* the majority of reverse lookups.
*
* Per DNS standards, email addresses are given in user.host format (for
* example: hostmaster.example.com as opposed to hostmaster@example.com),
* be sure to check this value and modify if necessary before using it
* with a functions such as mail.
* @param int $type By default, dns_get_record will search for any
* resource records associated with hostname.
* To limit the query, use one of the
* DNS_*
* constants.
* @param array|null $authoritative_name_servers Passed by reference and, if given, will be populated with Resource
* Records for the Authoritative Name Servers.
* @param array|null $additional_records Passed by reference and, if given, will be populated with any
* Additional Records.
* @param bool $raw The type will be interpreted as a raw DNS type ID
* (the DNS_* constants cannot be used).
* The return value will contain a data key, which needs
* to be manually parsed.
* @return list This function returns an array of associative arrays. Each associative array contains
* at minimum the following keys:
*
* Basic DNS attributes
*
*
*
* Attribute
* Meaning
*
*
*
*
* host
*
* The record in the DNS namespace to which the rest of the associated data refers.
*
*
*
* class
*
* dns_get_record only returns Internet class records and as
* such this parameter will always return IN.
*
*
*
* type
*
* String containing the record type. Additional attributes will also be contained
* in the resulting array dependant on the value of type. See table below.
*
*
*
* ttl
*
* "Time To Live" remaining for this record. This will not equal
* the record's original ttl, but will rather equal the original ttl minus whatever
* length of time has passed since the authoritative name server was queried.
*
*
*
*
*
*
*
* Other keys in associative arrays dependent on type
*
*
*
* Type
* Extra Columns
*
*
*
*
* A
*
* ip: An IPv4 addresses in dotted decimal notation.
*
*
*
* MX
*
* pri: Priority of mail exchanger.
* Lower numbers indicate greater priority.
* target: FQDN of the mail exchanger.
* See also dns_get_mx.
*
*
*
* CNAME
*
* target: FQDN of location in DNS namespace to which
* the record is aliased.
*
*
*
* NS
*
* target: FQDN of the name server which is authoritative
* for this hostname.
*
*
*
* PTR
*
* target: Location within the DNS namespace to which
* this record points.
*
*
*
* TXT
*
* txt: Arbitrary string data associated with this record.
*
*
*
* HINFO
*
* cpu: IANA number designating the CPU of the machine
* referenced by this record.
* os: IANA number designating the Operating System on
* the machine referenced by this record.
* See IANA's Operating System
* Names for the meaning of these values.
*
*
*
* CAA
*
* flags: A one-byte bitfield; currently only bit 0 is defined,
* meaning 'critical'; other bits are reserved and should be ignored.
* tag: The CAA tag name (alphanumeric ASCII string).
* value: The CAA tag value (binary string, may use subformats).
* For additional information see: RFC 6844
*
*
*
* SOA
*
* mname: FQDN of the machine from which the resource
* records originated.
* rname: Email address of the administrative contact
* for this domain.
* serial: Serial # of this revision of the requested
* domain.
* refresh: Refresh interval (seconds) secondary name
* servers should use when updating remote copies of this domain.
* retry: Length of time (seconds) to wait after a
* failed refresh before making a second attempt.
* expire: Maximum length of time (seconds) a secondary
* DNS server should retain remote copies of the zone data without a
* successful refresh before discarding.
* minimum-ttl: Minimum length of time (seconds) a
* client can continue to use a DNS resolution before it should request
* a new resolution from the server. Can be overridden by individual
* resource records.
*
*
*
* AAAA
*
* ipv6: IPv6 address
*
*
*
* A6
*
* masklen: Length (in bits) to inherit from the target
* specified by chain.
* ipv6: Address for this specific record to merge with
* chain.
* chain: Parent record to merge with
* ipv6 data.
*
*
*
* SRV
*
* pri: (Priority) lowest priorities should be used first.
* weight: Ranking to weight which of commonly prioritized
* targets should be chosen at random.
* target and port: hostname and port
* where the requested service can be found.
* For additional information see: RFC 2782
*
*
*
* NAPTR
*
* order and pref: Equivalent to
* pri and weight above.
* flags, services, regex,
* and replacement: Parameters as defined by
* RFC 2915.
*
*
*
*
*
* @throws NetworkException
*
*/
function dns_get_record(string $hostname, int $type = DNS_ANY, ?array &$authoritative_name_servers = null, ?array &$additional_records = null, bool $raw = false): array
{
error_clear_last();
$safeResult = \dns_get_record($hostname, $type, $authoritative_name_servers, $additional_records, $raw);
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* Initiates a socket connection to the resource specified by
* hostname.
*
* PHP supports targets in the Internet and Unix domains as described in
* . A list of supported transports can also be
* retrieved using stream_get_transports.
*
* The socket will by default be opened in blocking mode. You can
* switch it to non-blocking mode by using
* stream_set_blocking.
*
* The function stream_socket_client is similar but
* provides a richer set of options, including non-blocking connection and the
* ability to provide a stream context.
*
* @param string $hostname If OpenSSL support is
* installed, you may prefix the hostname
* with either ssl:// or tls:// to
* use an SSL or TLS client connection over TCP/IP to connect to the
* remote host.
* @param int $port The port number. This can be omitted and skipped with
* -1 for transports that do not use ports, such as
* unix://.
* @param int|null $error_code If provided, holds the system level error number that occurred in the
* system-level connect() call.
*
* If the value returned in error_code is
* 0 and the function returned FALSE, it is an
* indication that the error occurred before the
* connect() call. This is most likely due to a
* problem initializing the socket.
* @param null|string $error_message The error message as a string.
* @param float|null $timeout The connection timeout, in seconds. When NULL, the
* default_socket_timeout php.ini setting is used.
*
* If you need to set a timeout for reading/writing data over the
* socket, use stream_set_timeout, as the
* timeout parameter to
* fsockopen only applies while connecting the
* socket.
* @return resource fsockopen returns a file pointer which may be used
* together with the other file functions (such as
* fgets, fgetss,
* fwrite, fclose, and
* feof). If the call fails, it will return FALSE
* @throws NetworkException
*
*/
function fsockopen(string $hostname, int $port = -1, ?int &$error_code = null, ?string &$error_message = null, ?float $timeout = null)
{
error_clear_last();
if ($timeout !== null) {
$safeResult = \fsockopen($hostname, $port, $error_code, $error_message, $timeout);
} else {
$safeResult = \fsockopen($hostname, $port, $error_code, $error_message);
}
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* gethostname gets the standard host name for
* the local machine.
*
* @return string Returns a string with the hostname on success, otherwise FALSE is
* returned.
* @throws NetworkException
*
*/
function gethostname(): string
{
error_clear_last();
$safeResult = \gethostname();
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* getprotobyname returns the protocol number
* associated with the protocol protocol as per
* /etc/protocols.
*
* @param string $protocol The protocol name.
* @return int Returns the protocol number.
* @throws NetworkException
*
*/
function getprotobyname(string $protocol): int
{
error_clear_last();
$safeResult = \getprotobyname($protocol);
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* getprotobynumber returns the protocol name
* associated with protocol protocol as per
* /etc/protocols.
*
* @param int $protocol The protocol number.
* @return string Returns the protocol name as a string.
* @throws NetworkException
*
*/
function getprotobynumber(int $protocol): string
{
error_clear_last();
$safeResult = \getprotobynumber($protocol);
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* getservbyport returns the Internet service
* associated with port for the specified
* protocol as per /etc/services.
*
* @param int $port The port number.
* @param string $protocol protocol is either "tcp"
* or "udp" (in lowercase).
* @return string Returns the Internet service name as a string.
* @throws NetworkException
*
*/
function getservbyport(int $port, string $protocol): string
{
error_clear_last();
$safeResult = \getservbyport($port, $protocol);
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* Registers a function that will be called when PHP starts sending output.
*
* The callback is executed just after PHP prepares all
* headers to be sent, and before any other output is sent, creating a window
* to manipulate the outgoing headers before being sent.
*
* @param callable $callback Function called just before the headers are sent. It gets no parameters
* and the return value is ignored.
* @throws NetworkException
*
*/
function header_register_callback(callable $callback): void
{
error_clear_last();
$safeResult = \header_register_callback($callback);
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
}
/**
*
*
* @param string $ip A 32bit IPv4, or 128bit IPv6 address.
* @return string Returns a string representation of the address.
* @throws NetworkException
*
*/
function inet_ntop(string $ip): string
{
error_clear_last();
$safeResult = \inet_ntop($ip);
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* This function converts a human readable IPv4 or IPv6 address (if PHP
* was built with IPv6 support enabled) into an address family appropriate
* 32bit or 128bit binary structure.
*
* @param string $ip A human readable IPv4 or IPv6 address.
* @return string Returns the in_addr representation of the given
* ip, or FALSE if a syntactically invalid
* ip is given (for example, an IPv4 address
* without dots or an IPv6 address without colons).
* @throws NetworkException
*
*/
function inet_pton(string $ip): string
{
error_clear_last();
$safeResult = \inet_pton($ip);
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* The function long2ip generates an Internet address
* in dotted format (i.e.: aaa.bbb.ccc.ddd) from the long integer
* representation.
*
* @param int $ip A proper address representation in long integer.
* @return false|string Returns the Internet IP address as a string.
*
*/
function long2ip(int $ip)
{
error_clear_last();
$safeResult = \long2ip($ip);
return $safeResult;
}
/**
* Returns an enumeration of network interfaces (adapters) on the local machine.
*
* @return array Returns an associative array where the key is the name of the interface and
* the value an associative array of interface attributes.
*
* Each interface associative array contains:
*
* Interface attributes
*
*
*
* Name
* Description
*
*
*
*
* description
*
* Optional string value for description of the interface.
* Windows only.
*
*
*
* mac
*
* Optional string value for MAC address of the interface.
* Windows only.
*
*
*
* mtu
*
* Integer value for Maximum transmission unit (MTU) of the interface.
* Windows only.
*
*
*
* unicast
*
* Array of associative arrays, see Unicast attributes below.
*
*
*
* up
*
* Boolean status (on/off) for interface.
*
*
*
*
*
*
*
* Unicast attributes
*
*
*
* Name
* Description
*
*
*
*
* flags
*
* Integer value.
*
*
*
* family
*
* Integer value.
*
*
*
* address
*
* String value for address in either IPv4 or IPv6.
*
*
*
* netmask
*
* String value for netmask in either IPv4 or IPv6.
*
*
*
*
*
* @throws NetworkException
*
*/
function net_get_interfaces(): array
{
error_clear_last();
$safeResult = \net_get_interfaces();
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* openlog opens a connection to the system
* logger for a program.
*
* The use of openlog is optional. It
* will automatically be called by syslog if
* necessary, in which case prefix will default
* to the empty string.
*
* @param string $prefix The string prefix is added to each message.
* @param int $flags Bitmask of the following constants:
*
* LOG_CONS
* LOG_NDELAY
* LOG_ODELAY
* LOG_NOWAIT
* LOG_PERROR
* LOG_PID
*
* @param int $facility The facility argument is used to specify
* what type of program is logging the message.
* This lets the configuration file specify that messages from different
* facilities will be handled differently.
* Must be one of the following constants:
*
* LOG_AUTH
* LOG_AUTHPRIV
* LOG_CRON
* LOG_DAEMON
* LOG_KERN
* LOG_LOCAL[0-7]
* LOG_LPR
* LOG_MAIL
* LOG_NEWS
* LOG_SYSLOG
* LOG_USER
* LOG_UUCP
*
* @return bool Always returns TRUE.
*
*/
function openlog(string $prefix, int $flags, int $facility): bool
{
error_clear_last();
$safeResult = \openlog($prefix, $flags, $facility);
return $safeResult;
}
/**
* This function behaves exactly as fsockopen with the
* difference that the connection is not closed after the script finishes.
* It is the persistent version of fsockopen.
*
* @param string $hostname
* @param int $port
* @param int|null $error_code
* @param null|string $error_message
* @param float|null $timeout
* @return resource pfsockopen returns a file pointer which may be used
* together with the other file functions (such as
* fgets, fgetss,
* fwrite, fclose, and
* feof).
* @throws NetworkException
*
*/
function pfsockopen(string $hostname, int $port = -1, ?int &$error_code = null, ?string &$error_message = null, ?float $timeout = null)
{
error_clear_last();
if ($timeout !== null) {
$safeResult = \pfsockopen($hostname, $port, $error_code, $error_message, $timeout);
} else {
$safeResult = \pfsockopen($hostname, $port, $error_code, $error_message);
}
if ($safeResult === false) {
throw NetworkException::createFromPhpError();
}
return $safeResult;
}
/**
* syslog generates a log message that will be
* distributed by the system logger.
*
* For information on setting up a user defined log handler, see the
* syslog.conf
* 5 Unix manual page. More
* information on the syslog facilities and option can be found in the man
* pages for syslog
* 3 on Unix machines.
*
* @param int $priority One of the
*
* LOG_EMERG
* LOG_ALERT
* LOG_CRIT
* LOG_ERR
* LOG_WARNING
* LOG_NOTICE
* LOG_INFO
* LOG_DEBUG
*
* constants.
* @param string $message The message to send.
* @return bool Always returns TRUE.
*
*/
function syslog(int $priority, string $message): bool
{
error_clear_last();
$safeResult = \syslog($priority, $message);
return $safeResult;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
<?php
namespace Safe;
use Safe\Exceptions\OpcacheException;
/**
* This function compiles a PHP script and adds it to the opcode cache without
* executing it. This can be used to prime the cache after a Web server
* restart by pre-caching files that will be included in later requests.
*
* @param string $filename The path to the PHP script to be compiled.
* @throws OpcacheException
*
*/
function opcache_compile_file(string $filename): void
{
error_clear_last();
$safeResult = \opcache_compile_file($filename);
if ($safeResult === false) {
throw OpcacheException::createFromPhpError();
}
}
/**
* This function returns state information about the in-memory cache instance. It will not return any
* information about the file cache.
*
* @param bool $include_scripts Include script specific state information
* @return array Returns an array of information, optionally containing script specific state information.
* @throws OpcacheException
*
*/
function opcache_get_status(bool $include_scripts = true): array
{
error_clear_last();
$safeResult = \opcache_get_status($include_scripts);
if ($safeResult === false) {
throw OpcacheException::createFromPhpError();
}
return $safeResult;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,321 @@
<?php
namespace Safe;
use Safe\Exceptions\OutcontrolException;
/**
* This function calls the output handler
* (with the PHP_OUTPUT_HANDLER_CLEAN flag),
* discards it's return value
* and cleans (erases) the contents of the active output buffer.
*
* This function does not turn off the active output buffer like
* ob_end_clean or ob_get_clean does.
*
* ob_clean will fail
* without an active output buffer started with the
* PHP_OUTPUT_HANDLER_CLEANABLE flag.
*
* @throws OutcontrolException
*
*/
function ob_clean(): void
{
error_clear_last();
$safeResult = \ob_clean();
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
}
/**
* This function calls the output handler
* (with the PHP_OUTPUT_HANDLER_CLEAN and
* PHP_OUTPUT_HANDLER_FINAL flags),
* discards it's return value,
* discards the contents of the active output buffer
* and turns off the active output buffer.
*
* ob_end_clean will fail
* without an active output buffer started with the
* PHP_OUTPUT_HANDLER_REMOVABLE flag.
*
* ob_end_clean
* will discard the contents of the active output buffer
* even if it was started without the
* PHP_OUTPUT_HANDLER_CLEANABLE flag.
*
* @throws OutcontrolException
*
*/
function ob_end_clean(): void
{
error_clear_last();
$safeResult = \ob_end_clean();
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
}
/**
* This function calls the output handler
* (with the PHP_OUTPUT_HANDLER_FINAL flag),
* flushes (sends) it's return value,
* discards the contents of the active output buffer
* and turns off the active output buffer.
*
* ob_end_flush will fail
* without an active output buffer started with the
* PHP_OUTPUT_HANDLER_REMOVABLE flag.
*
* ob_end_flush will flush (send)
* the return value of the output handler
* even if the active output buffer was started without the
* PHP_OUTPUT_HANDLER_FLUSHABLE flag.
*
* @throws OutcontrolException
*
*/
function ob_end_flush(): void
{
error_clear_last();
$safeResult = \ob_end_flush();
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
}
/**
* This function calls the output handler
* (with the PHP_OUTPUT_HANDLER_FLUSH flag),
* flushes (sends) its return value
* and discards the contents of the active output buffer.
*
* This function does not turn off the active output buffer like
* ob_end_flush or ob_get_flush does.
*
* ob_flush will fail
* without an active output buffer started with the
* PHP_OUTPUT_HANDLER_FLUSHABLE flag.
*
* @throws OutcontrolException
*
*/
function ob_flush(): void
{
error_clear_last();
$safeResult = \ob_flush();
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
}
/**
* This function calls the output handler
* (with the PHP_OUTPUT_HANDLER_CLEAN and
* PHP_OUTPUT_HANDLER_FINAL flags),
* discards it's return value,
* returns the contents of the active output buffer
* and turns off the active output buffer.
*
* ob_get_clean will fail
* without an active output buffer started with the
* PHP_OUTPUT_HANDLER_REMOVABLE flag.
*
* ob_get_clean
* will discard the contents of the active output buffer
* even if it was started without the
* PHP_OUTPUT_HANDLER_CLEANABLE flag.
*
* @return string Returns the contents of the active output buffer on success.
* @throws OutcontrolException
*
*/
function ob_get_clean(): string
{
error_clear_last();
$safeResult = \ob_get_clean();
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
return $safeResult;
}
/**
* This function calls the output handler
* (with the PHP_OUTPUT_HANDLER_FINAL flag),
* flushes (sends) it's return value,
* returns the contents of the active output buffer
* and turns off the active output buffer.
*
* ob_get_flush will fail
* without an active output buffer started with the
* PHP_OUTPUT_HANDLER_REMOVABLE flag.
*
* ob_get_flush will flush (send)
* the return value of the output handler
* even if the active output buffer was started without the
* PHP_OUTPUT_HANDLER_FLUSHABLE flag.
*
* @return string Returns the contents of the active output buffer on success.
* @throws OutcontrolException
*
*/
function ob_get_flush(): string
{
error_clear_last();
$safeResult = \ob_get_flush();
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
return $safeResult;
}
/**
* This function will turn output buffering on.
* While output buffering is active no output is sent from the script,
* instead the output is stored in an internal buffer.
* See
* on exactly what output is affected.
*
* Output buffers are stackable, that is,
* ob_start may be called while another buffer is active.
* If multiple output buffers are active,
* output is being filtered sequentially
* through each of them in nesting order.
* See for more details.
*
* See
* for a detailed description of output buffers.
*
* @param array|callable|null|string $callback An optional callback callable may be
* specified. It can also be bypassed by passing NULL.
*
* callback is invoked when the output buffer is
* flushed (sent), cleaned, or when the output buffer is flushed
* at the end of the script.
*
* The signature of the callback is as follows:
*
*
* stringhandler
* stringbuffer
* intphase
*
*
*
* buffer
*
*
* Contents of the output buffer.
*
*
*
*
* phase
*
*
* Bitmask of
*
* PHP_OUTPUT_HANDLER_*
* constants
* .
* See
* for more details.
*
*
*
*
*
* If callback returns FALSE
* the contents of the buffer are returned.
* See
* for more details.
*
* See
* and
* for more details on callbacks (output handlers).
* @param int $chunk_size
* @param int $flags
* @throws OutcontrolException
*
*/
function ob_start($callback = null, int $chunk_size = 0, int $flags = PHP_OUTPUT_HANDLER_STDFLAGS): void
{
error_clear_last();
if ($flags !== PHP_OUTPUT_HANDLER_STDFLAGS) {
$safeResult = \ob_start($callback, $chunk_size, $flags);
} elseif ($chunk_size !== 0) {
$safeResult = \ob_start($callback, $chunk_size);
} elseif ($callback !== null) {
$safeResult = \ob_start($callback);
} else {
$safeResult = \ob_start();
}
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
}
/**
* This function starts the 'URL-Rewriter' output buffer handler
* if it is not active,
* stores the name and value parameters,
* and when the buffer is flushed rewrites the URLs
* and forms based on the applicable ini settings.
* Subsequent calls to this function will store all additional name/value pairs
* until the handler is turned off.
*
* When the output buffer is flushed
* (by calling ob_flush, ob_end_flush,
* ob_get_flush or at the end of the script)
* the 'URL-Rewriter' handler adds the name/value pairs
* as query parameters to URLs in attributes of HTML tags
* and adds hidden fields to forms based on the values of the
* url_rewriter.tags and
* url_rewriter.hosts
* configuration directives.
*
* Each name/value pair added to the 'URL-Rewriter' handler
* is added to the URLs and/or forms
* even if this results in duplicate URL query parameters
* or elements with the same name attributes.
*
* @param string $name The variable name.
* @param string $value The variable value.
* @throws OutcontrolException
*
*/
function output_add_rewrite_var(string $name, string $value): void
{
error_clear_last();
$safeResult = \output_add_rewrite_var($name, $value);
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
}
/**
* This function removes all rewrite variables previously set by
* the output_add_rewrite_var function.
*
* @throws OutcontrolException
*
*/
function output_reset_rewrite_vars(): void
{
error_clear_last();
$safeResult = \output_reset_rewrite_vars();
if ($safeResult === false) {
throw OutcontrolException::createFromPhpError();
}
}

0
vendor/thecodingmachine/safe/generated/8.5/pcntl.php vendored Normal file → Executable file
View File

View File

@@ -0,0 +1,788 @@
<?php
namespace Safe;
use Safe\Exceptions\PcreException;
/**
* Returns the array consisting of the elements of the
* array array that match the given
* pattern.
*
* @param string $pattern The pattern to search for, as a string.
* @param array $array The input array.
* @param int $flags If set to PREG_GREP_INVERT, this function returns
* the elements of the input array that do not match
* the given pattern.
* @return array Returns an array indexed using the keys from the
* array array.
* @throws PcreException
*
*/
function preg_grep(string $pattern, array $array, int $flags = 0): array
{
error_clear_last();
$safeResult = \preg_grep($pattern, $array, $flags);
if ($safeResult === false) {
throw PcreException::createFromPhpError();
}
return $safeResult;
}
/**
* Searches subject for all matches to the regular
* expression given in pattern and puts them in
* matches in the order specified by
* flags.
*
* After the first match is found, the subsequent searches are continued
* on from end of the last match.
*
* @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string.
* @param array|null $matches Array of all matches in multi-dimensional array ordered according to
* flags.
* @param int $flags Can be a combination of the following flags (note that it doesn't make
* sense to use PREG_PATTERN_ORDER together with
* PREG_SET_ORDER):
*
*
* PREG_PATTERN_ORDER
*
*
* Orders results so that $matches[0] is an array of full
* pattern matches, $matches[1] is an array of strings matched by
* the first parenthesized subpattern, and so on.
*
*
*
*
*
* ]]>
*
* The above example will output:
*
* example: , this is a test
* example: , this is a test
* ]]>
*
*
* So, $out[0] contains an array of strings that matched the full pattern,
* and $out[1] contains an array of strings enclosed by tags.
*
*
*
*
* If the pattern contains named subpatterns, $matches
* additionally contains entries for keys with the subpattern name.
*
*
* If the pattern contains duplicate named subpatterns, only the rightmost
* subpattern is stored in $matches[NAME].
*
*
*
* ]]>
*
* The above example will output:
*
*
* [1] => bar
* )
* ]]>
*
*
*
*
*
*
* PREG_SET_ORDER
*
*
* Orders results so that $matches[0] is an array of first set
* of matches, $matches[1] is an array of second set of matches,
* and so on.
*
*
*
* ]]>
*
* The above example will output:
*
* example: , example:
* this is a test, this is a test
* ]]>
*
*
*
*
*
*
* PREG_OFFSET_CAPTURE
*
*
* If this flag is passed, for every occurring match the appendant string
* offset (in bytes) will also be returned. Note that this changes the value of
* matches into an array of arrays where every element is an
* array consisting of the matched string at offset 0
* and its string offset into subject at offset
* 1.
*
*
*
* ]]>
*
* The above example will output:
*
* Array
* (
* [0] => Array
* (
* [0] => foobarbaz
* [1] => 0
* )
*
* )
*
* [1] => Array
* (
* [0] => Array
* (
* [0] => foo
* [1] => 0
* )
*
* )
*
* [2] => Array
* (
* [0] => Array
* (
* [0] => bar
* [1] => 3
* )
*
* )
*
* [3] => Array
* (
* [0] => Array
* (
* [0] => baz
* [1] => 6
* )
*
* )
*
* )
* ]]>
*
*
*
*
*
*
* PREG_UNMATCHED_AS_NULL
*
*
* If this flag is passed, unmatched subpatterns are reported as NULL;
* otherwise they are reported as an empty string.
*
*
*
*
*
* Orders results so that $matches[0] is an array of full
* pattern matches, $matches[1] is an array of strings matched by
* the first parenthesized subpattern, and so on.
*
*
*
*
* ]]>
*
* The above example will output:
*
* example: , this is a test
* example: , this is a test
* ]]>
*
*
* So, $out[0] contains an array of strings that matched the full pattern,
* and $out[1] contains an array of strings enclosed by tags.
*
*
*
* The above example will output:
*
* So, $out[0] contains an array of strings that matched the full pattern,
* and $out[1] contains an array of strings enclosed by tags.
*
* If the pattern contains named subpatterns, $matches
* additionally contains entries for keys with the subpattern name.
*
* If the pattern contains duplicate named subpatterns, only the rightmost
* subpattern is stored in $matches[NAME].
*
*
*
* ]]>
*
* The above example will output:
*
*
* [1] => bar
* )
* ]]>
*
*
*
* The above example will output:
*
* Orders results so that $matches[0] is an array of first set
* of matches, $matches[1] is an array of second set of matches,
* and so on.
*
*
*
* ]]>
*
* The above example will output:
*
* example: , example:
* this is a test, this is a test
* ]]>
*
*
*
* The above example will output:
*
* If this flag is passed, for every occurring match the appendant string
* offset (in bytes) will also be returned. Note that this changes the value of
* matches into an array of arrays where every element is an
* array consisting of the matched string at offset 0
* and its string offset into subject at offset
* 1.
*
*
*
* ]]>
*
* The above example will output:
*
* Array
* (
* [0] => Array
* (
* [0] => foobarbaz
* [1] => 0
* )
*
* )
*
* [1] => Array
* (
* [0] => Array
* (
* [0] => foo
* [1] => 0
* )
*
* )
*
* [2] => Array
* (
* [0] => Array
* (
* [0] => bar
* [1] => 3
* )
*
* )
*
* [3] => Array
* (
* [0] => Array
* (
* [0] => baz
* [1] => 6
* )
*
* )
*
* )
* ]]>
*
*
*
* The above example will output:
*
* If this flag is passed, unmatched subpatterns are reported as NULL;
* otherwise they are reported as an empty string.
*
* If no order flag is given, PREG_PATTERN_ORDER is
* assumed.
* @param int $offset Orders results so that $matches[0] is an array of full
* pattern matches, $matches[1] is an array of strings matched by
* the first parenthesized subpattern, and so on.
*
*
*
*
* ]]>
*
* The above example will output:
*
* example: , this is a test
* example: , this is a test
* ]]>
*
*
* So, $out[0] contains an array of strings that matched the full pattern,
* and $out[1] contains an array of strings enclosed by tags.
*
*
*
* The above example will output:
*
* So, $out[0] contains an array of strings that matched the full pattern,
* and $out[1] contains an array of strings enclosed by tags.
*
* If the pattern contains named subpatterns, $matches
* additionally contains entries for keys with the subpattern name.
*
* If the pattern contains duplicate named subpatterns, only the rightmost
* subpattern is stored in $matches[NAME].
*
*
*
* ]]>
*
* The above example will output:
*
*
* [1] => bar
* )
* ]]>
*
*
*
* The above example will output:
* @return 0|positive-int Returns the number of full pattern matches (which might be zero).
* @throws PcreException
*
*/
function preg_match_all(string $pattern, string $subject, ?array &$matches = null, int $flags = 0, int $offset = 0): int
{
error_clear_last();
$safeResult = \preg_match_all($pattern, $subject, $matches, $flags, $offset);
if ($safeResult === false) {
throw PcreException::createFromPhpError();
}
return $safeResult;
}
/**
* Searches subject for a match to the regular
* expression given in pattern.
*
* @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string.
* @param null|string[] $matches If matches is provided, then it is filled with
* the results of search. $matches[0] will contain the
* text that matched the full pattern, $matches[1]
* will have the text that matched the first captured parenthesized
* subpattern, and so on.
* @param int $flags flags can be a combination of the following flags:
*
*
* PREG_OFFSET_CAPTURE
*
*
* If this flag is passed, for every occurring match the appendant string
* offset (in bytes) will also be returned. Note that this changes the value of
* matches into an array where every element is an
* array consisting of the matched string at offset 0
* and its string offset into subject at offset
* 1.
*
*
*
* ]]>
*
* The above example will output:
*
* Array
* (
* [0] => foobarbaz
* [1] => 0
* )
*
* [1] => Array
* (
* [0] => foo
* [1] => 0
* )
*
* [2] => Array
* (
* [0] => bar
* [1] => 3
* )
*
* [3] => Array
* (
* [0] => baz
* [1] => 6
* )
*
* )
* ]]>
*
*
*
*
*
*
* PREG_UNMATCHED_AS_NULL
*
*
* If this flag is passed, unmatched subpatterns are reported as NULL;
* otherwise they are reported as an empty string.
*
*
*
* ]]>
*
* The above example will output:
*
*
* string(2) "ac"
* [1]=>
* string(1) "a"
* [2]=>
* string(0) ""
* [3]=>
* string(1) "c"
* }
* array(4) {
* [0]=>
* string(2) "ac"
* [1]=>
* string(1) "a"
* [2]=>
* NULL
* [3]=>
* string(1) "c"
* }
* ]]>
*
*
*
*
*
*
*
* If this flag is passed, for every occurring match the appendant string
* offset (in bytes) will also be returned. Note that this changes the value of
* matches into an array where every element is an
* array consisting of the matched string at offset 0
* and its string offset into subject at offset
* 1.
*
*
*
* ]]>
*
* The above example will output:
*
* Array
* (
* [0] => foobarbaz
* [1] => 0
* )
*
* [1] => Array
* (
* [0] => foo
* [1] => 0
* )
*
* [2] => Array
* (
* [0] => bar
* [1] => 3
* )
*
* [3] => Array
* (
* [0] => baz
* [1] => 6
* )
*
* )
* ]]>
*
*
*
* The above example will output:
*
* If this flag is passed, unmatched subpatterns are reported as NULL;
* otherwise they are reported as an empty string.
*
*
*
* ]]>
*
* The above example will output:
*
*
* string(2) "ac"
* [1]=>
* string(1) "a"
* [2]=>
* string(0) ""
* [3]=>
* string(1) "c"
* }
* array(4) {
* [0]=>
* string(2) "ac"
* [1]=>
* string(1) "a"
* [2]=>
* NULL
* [3]=>
* string(1) "c"
* }
* ]]>
*
*
*
* The above example will output:
* @param int $offset If this flag is passed, for every occurring match the appendant string
* offset (in bytes) will also be returned. Note that this changes the value of
* matches into an array where every element is an
* array consisting of the matched string at offset 0
* and its string offset into subject at offset
* 1.
*
*
*
* ]]>
*
* The above example will output:
*
* Array
* (
* [0] => foobarbaz
* [1] => 0
* )
*
* [1] => Array
* (
* [0] => foo
* [1] => 0
* )
*
* [2] => Array
* (
* [0] => bar
* [1] => 3
* )
*
* [3] => Array
* (
* [0] => baz
* [1] => 6
* )
*
* )
* ]]>
*
*
*
* The above example will output:
* @return 0|1 preg_match returns 1 if the pattern
* matches given subject, 0 if it does not.
* @throws PcreException
*
*/
function preg_match(string $pattern, string $subject, ?array &$matches = null, int $flags = 0, int $offset = 0): int
{
error_clear_last();
$safeResult = \preg_match($pattern, $subject, $matches, $flags, $offset);
if ($safeResult === false) {
throw PcreException::createFromPhpError();
}
return $safeResult;
}
/**
* The behavior of this function is similar to
* preg_replace_callback, except that callbacks are
* executed on a per-pattern basis.
*
* @param array $pattern An associative array mapping patterns (keys) to callables (values).
* @param array|string $subject The string or an array with strings to search and replace.
* @param int $limit The maximum possible replacements for each pattern in each
* subject string. Defaults to
* -1 (no limit).
* @param int|null $count If specified, this variable will be filled with the number of
* replacements done.
* @param int $flags flags can be a combination of the
* PREG_OFFSET_CAPTURE and
* PREG_UNMATCHED_AS_NULL flags, which influence the
* format of the matches array.
* See the description in preg_match for more details.
* @return array|string preg_replace_callback_array returns an array if the
* subject parameter is an array, or a string
* otherwise. On errors the return value is NULL
*
* If matches are found, the new subject will be returned, otherwise
* subject will be returned unchanged.
* @throws PcreException
*
*/
function preg_replace_callback_array(array $pattern, $subject, int $limit = -1, ?int &$count = null, int $flags = 0)
{
error_clear_last();
$safeResult = \preg_replace_callback_array($pattern, $subject, $limit, $count, $flags);
if ($safeResult === null) {
throw PcreException::createFromPhpError();
}
return $safeResult;
}
/**
* The behavior of this function is almost identical to
* preg_replace, except for the fact that instead of
* replacement parameter, one should specify a
* callback.
*
* @param array|string $pattern The pattern to search for. It can be either a string or an array with
* strings.
* @param callable(array):string $callback A callback that will be called and passed an array of matched elements
* in the subject string. The callback should
* return the replacement string. This is the callback signature:
*
*
* stringhandler
* arraymatches
*
*
* You'll often need the callback function
* for a preg_replace_callback in just one place.
* In this case you can use an
* anonymous function to
* declare the callback within the call to
* preg_replace_callback. By doing it this way
* you have all information for the call in one place and do not
* clutter the function namespace with a callback function's name
* not used anywhere else.
*
*
* preg_replace_callback and
* anonymous function
*
*
* ]]>
*
*
* @param array|string $subject The string or an array with strings to search and replace.
* @param int $limit The maximum possible replacements for each pattern in each
* subject string. Defaults to
* -1 (no limit).
* @param int|null $count If specified, this variable will be filled with the number of
* replacements done.
* @param int $flags flags can be a combination of the
* PREG_OFFSET_CAPTURE and
* PREG_UNMATCHED_AS_NULL flags, which influence the
* format of the matches array.
* See the description in preg_match for more details.
* @return array|string preg_replace_callback returns an array if the
* subject parameter is an array, or a string
* otherwise. On errors the return value is NULL
*
* If matches are found, the new subject will be returned, otherwise
* subject will be returned unchanged.
* @throws PcreException
*
*/
function preg_replace_callback($pattern, callable $callback, $subject, int $limit = -1, ?int &$count = null, int $flags = 0)
{
error_clear_last();
$safeResult = \preg_replace_callback($pattern, $callback, $subject, $limit, $count, $flags);
if ($safeResult === null) {
throw PcreException::createFromPhpError();
}
return $safeResult;
}
/**
* Split the given string by a regular expression.
*
* @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string.
* @param int|null $limit If specified, then only substrings up to limit
* are returned with the rest of the string being placed in the last
* substring. A limit of -1 or 0 means "no limit".
* @param int $flags flags can be any combination of the following
* flags (combined with the | bitwise operator):
*
*
* PREG_SPLIT_NO_EMPTY
*
*
* If this flag is set, only non-empty pieces will be returned by
* preg_split.
*
*
*
*
* PREG_SPLIT_DELIM_CAPTURE
*
*
* If this flag is set, parenthesized expression in the delimiter pattern
* will be captured and returned as well.
*
*
*
*
* PREG_SPLIT_OFFSET_CAPTURE
*
*
* If this flag is set, for every occurring match the appendant string
* offset will also be returned. Note that this changes the return
* value in an array where every element is an array consisting of the
* matched string at offset 0 and its string offset
* into subject at offset 1.
*
*
*
*
*
* If this flag is set, for every occurring match the appendant string
* offset will also be returned. Note that this changes the return
* value in an array where every element is an array consisting of the
* matched string at offset 0 and its string offset
* into subject at offset 1.
* @return list Returns an array containing substrings of subject
* split along boundaries matched by pattern.
* @throws PcreException
*
*/
function preg_split(string $pattern, string $subject, ?int $limit = -1, int $flags = 0): array
{
error_clear_last();
$safeResult = \preg_split($pattern, $subject, $limit, $flags);
if ($safeResult === false) {
throw PcreException::createFromPhpError();
}
return $safeResult;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,783 @@
<?php
namespace Safe;
use Safe\Exceptions\PosixException;
/**
* posix_access checks the user's permission of a file.
*
* @param string $filename The name of the file to be tested.
* @param int $flags A mask consisting of one or more of POSIX_F_OK,
* POSIX_R_OK, POSIX_W_OK and
* POSIX_X_OK.
*
* POSIX_R_OK, POSIX_W_OK and
* POSIX_X_OK request checking whether the file
* exists and has read, write and execute permissions, respectively.
* POSIX_F_OK just requests checking for the
* existence of the file.
* @throws PosixException
*
*/
function posix_access(string $filename, int $flags = 0): void
{
error_clear_last();
$safeResult = \posix_access($filename, $flags);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* posix_eaccess checks the effective user's permission of a file
*
* @param string $filename The name of a file to be tested.
* @param int $flags A mask consisting of one or more of POSIX_F_OK,
* POSIX_R_OK, POSIX_W_OK and
* POSIX_X_OK.
*
* POSIX_R_OK, POSIX_W_OK and
* POSIX_X_OK request checking whether the file
* exists and has read, write and execute permissions, respectively.
* POSIX_F_OK just requests checking for the
* existence of the file.
* @throws PosixException
*
*/
function posix_eaccess(string $filename, int $flags = 0): void
{
error_clear_last();
$safeResult = \posix_eaccess($filename, $flags);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Gets information about a group provided its id.
*
* @param int $group_id The group id.
* @return array{name: string, passwd: string, gid: int, members: list} The array elements returned are:
*
* The group information array
*
*
*
* Element
* Description
*
*
*
*
* name
*
* The name element contains the name of the group. This is
* a short, usually less than 16 character "handle" of the
* group, not the real, full name.
*
*
*
* passwd
*
* The passwd element contains the group's password in an
* encrypted format. Often, for example on a system employing
* "shadow" passwords, an asterisk is returned instead.
*
*
*
* gid
*
* Group ID, should be the same as the
* group_id parameter used when calling the
* function, and hence redundant.
*
*
*
* members
*
* This consists of an array of
* string's for all the members in the group.
*
*
*
*
*
* The function returns FALSE on failure.
* @throws PosixException
*
*/
function posix_getgrgid(int $group_id): array
{
error_clear_last();
$safeResult = \posix_getgrgid($group_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets information about a group provided its name.
*
* @param string $name The name of the group
* @return array{name: string, passwd: string, gid: int, members: list} Returns an array on success.
* The array elements returned are:
*
* The group information array
*
*
*
* Element
* Description
*
*
*
*
* name
*
* The name element contains the name of the group. This is
* a short, usually less than 16 character "handle" of the
* group, not the real, full name. This should be the same as
* the name parameter used when
* calling the function, and hence redundant.
*
*
*
* passwd
*
* The passwd element contains the group's password in an
* encrypted format. Often, for example on a system employing
* "shadow" passwords, an asterisk is returned instead.
*
*
*
* gid
*
* Group ID of the group in numeric form.
*
*
*
* members
*
* This consists of an array of
* string's for all the members in the group.
*
*
*
*
*
* @throws PosixException
*
*/
function posix_getgrnam(string $name): array
{
error_clear_last();
$safeResult = \posix_getgrnam($name);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets the group set of the current process.
*
* @return list Returns an array of integers containing the numeric group ids of the group
* set of the current process.
* @throws PosixException
*
*/
function posix_getgroups(): array
{
error_clear_last();
$safeResult = \posix_getgroups();
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the login name of the user owning the current process.
*
* @return string Returns the login name of the user, as a string.
* @throws PosixException
*
*/
function posix_getlogin(): string
{
error_clear_last();
$safeResult = \posix_getlogin();
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns an array of information about the user
* referenced by the given user ID.
*
* @param int $user_id The user identifier.
* @return array{name: string, passwd: string, uid: int, gid: int, gecos: string, dir: string, shell: string} Returns an associative array with the following elements:
*
* The user information array
*
*
*
* Element
* Description
*
*
*
*
* name
*
* The name element contains the username of the user. This is
* a short, usually less than 16 character "handle" of the
* user, not the real, full name.
*
*
*
* passwd
*
* The passwd element contains the user's password in an
* encrypted format. Often, for example on a system employing
* "shadow" passwords, an asterisk is returned instead.
*
*
*
* uid
*
* User ID, should be the same as the
* user_id parameter used when calling the
* function, and hence redundant.
*
*
*
* gid
*
* The group ID of the user. Use the function
* posix_getgrgid to resolve the group
* name and a list of its members.
*
*
*
* gecos
*
* GECOS is an obsolete term that refers to the finger
* information field on a Honeywell batch processing system.
* The field, however, lives on, and its contents have been
* formalized by POSIX. The field contains a comma separated
* list containing the user's full name, office phone, office
* number, and home phone number. On most systems, only the
* user's full name is available.
*
*
*
* dir
*
* This element contains the absolute path to the
* home directory of the user.
*
*
*
* shell
*
* The shell element contains the absolute path to the
* executable of the user's default shell.
*
*
*
*
*
* The function returns FALSE on failure.
* @throws PosixException
*
*/
function posix_getpwuid(int $user_id): array
{
error_clear_last();
$safeResult = \posix_getpwuid($user_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* posix_getrlimit returns an array
* of information about the current resource's soft and hard limits.
*
*
* Each resource has an associated soft and hard limit. The soft
* limit is the value that the kernel enforces for the corresponding
* resource. The hard limit acts as a ceiling for the soft limit.
* An unprivileged process may only set its soft limit to a value
* from 0 to the hard limit, and irreversibly lower its hard limit.
*
* @param int|null $resource If NULL all resource limits will be fetched.
* Otherwise, the only limits of the resource type provided will be returned.
* @return array Returns an associative array of elements for each
* limit that is defined. Each limit has a soft and a hard limit.
*
* List of possible limits returned
*
*
*
* Limit name
* Limit description
*
*
*
*
* core
*
* The maximum size of the core file. When 0, not core files are
* created. When core files are larger than this size, they will
* be truncated at this size.
*
*
*
* totalmem
*
* The maximum size of the memory of the process, in bytes.
*
*
*
* virtualmem
*
* The maximum size of the virtual memory for the process, in bytes.
*
*
*
* data
*
* The maximum size of the data segment for the process, in bytes.
*
*
*
* stack
*
* The maximum size of the process stack, in bytes.
*
*
*
* rss
*
* The maximum number of virtual pages resident in RAM
*
*
*
* maxproc
*
* The maximum number of processes that can be created for the
* real user ID of the calling process.
*
*
*
* memlock
*
* The maximum number of bytes of memory that may be locked into RAM.
*
*
*
* cpu
*
* The amount of time the process is allowed to use the CPU.
*
*
*
* filesize
*
* The maximum size of the data segment for the process, in bytes.
*
*
*
* openfiles
*
* One more than the maximum number of open file descriptors.
*
*
*
*
*
* The function returns FALSE on failure.
* @throws PosixException
*
*/
function posix_getrlimit(?int $resource = null): array
{
error_clear_last();
if ($resource !== null) {
$safeResult = \posix_getrlimit($resource);
} else {
$safeResult = \posix_getrlimit();
}
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* Return the session id of the process process_id.
* The session id of a process is the process group id of the session leader.
*
* @param int $process_id The process identifier. If set to 0, the current process is
* assumed. If an invalid process_id is
* specified, then FALSE is returned and an error is set which
* can be checked with posix_get_last_error.
* @return int Returns the identifier, as an int.
* @throws PosixException
*
*/
function posix_getsid(int $process_id): int
{
error_clear_last();
$safeResult = \posix_getsid($process_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* Calculates the group access list for the user specified in name.
*
* @param string $username The user to calculate the list for.
* @param int $group_id Typically the group number from the password file.
* @throws PosixException
*
*/
function posix_initgroups(string $username, int $group_id): void
{
error_clear_last();
$safeResult = \posix_initgroups($username, $group_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Send the signal signal to the process with
* the process identifier process_id.
*
* @param int $process_id The process identifier.
* @param int $signal One of the PCNTL signals constants.
* @throws PosixException
*
*/
function posix_kill(int $process_id, int $signal): void
{
error_clear_last();
$safeResult = \posix_kill($process_id, $signal);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* posix_mkfifo creates a special
* FIFO file which exists in the file system and acts as
* a bidirectional communication endpoint for processes.
*
* @param string $filename Path to the FIFO file.
* @param int $permissions The second parameter permissions has to be given in
* octal notation (e.g. 0644). The permission of the newly created
* FIFO also depends on the setting of the current
* umask. The permissions of the created file are
* (mode &amp; ~umask).
* @throws PosixException
*
*/
function posix_mkfifo(string $filename, int $permissions): void
{
error_clear_last();
$safeResult = \posix_mkfifo($filename, $permissions);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Creates a special or ordinary file.
*
* @param string $filename The file to create
* @param int $flags This parameter is constructed by a bitwise OR between file type (one of
* the following constants: POSIX_S_IFREG,
* POSIX_S_IFCHR, POSIX_S_IFBLK,
* POSIX_S_IFIFO or
* POSIX_S_IFSOCK) and permissions.
* @param int $major The major device kernel identifier (required to pass when using
* S_IFCHR or S_IFBLK).
* @param int $minor The minor device kernel identifier.
* @throws PosixException
*
*/
function posix_mknod(string $filename, int $flags, int $major = 0, int $minor = 0): void
{
error_clear_last();
$safeResult = \posix_mknod($filename, $flags, $major, $minor);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Set the effective group ID of the current process. This is a
* privileged function and needs appropriate privileges (usually
* root) on the system to be able to perform this function.
*
* @param int $group_id The group id.
* @throws PosixException
*
*/
function posix_setegid(int $group_id): void
{
error_clear_last();
$safeResult = \posix_setegid($group_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Set the effective user ID of the current process. This is a privileged
* function and needs appropriate privileges (usually root) on
* the system to be able to perform this function.
*
* @param int $user_id The user id.
* @throws PosixException
*
*/
function posix_seteuid(int $user_id): void
{
error_clear_last();
$safeResult = \posix_seteuid($user_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Set the real group ID of the current process. This is a
* privileged function and needs appropriate privileges (usually
* root) on the system to be able to perform this function. The
* appropriate order of function calls is
* posix_setgid first,
* posix_setuid last.
*
* @param int $group_id The group id.
* @throws PosixException
*
*/
function posix_setgid(int $group_id): void
{
error_clear_last();
$safeResult = \posix_setgid($group_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Let the process process_id join the process group
* process_group_id.
*
* @param int $process_id The process id.
* @param int $process_group_id The process group id.
* @throws PosixException
*
*/
function posix_setpgid(int $process_id, int $process_group_id): void
{
error_clear_last();
$safeResult = \posix_setpgid($process_id, $process_group_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* posix_setrlimit sets the soft and hard limits for a
* given system resource.
*
*
* Each resource has an associated soft and hard limit. The soft
* limit is the value that the kernel enforces for the corresponding
* resource. The hard limit acts as a ceiling for the soft limit.
* An unprivileged process may only set its soft limit to a value
* from 0 to the hard limit, and irreversibly lower its hard limit.
*
* @param int $resource The
* resource limit constant
* corresponding to the limit that is being set.
* @param int $soft_limit The soft limit, in whatever unit the resource limit requires, or
* POSIX_RLIMIT_INFINITY.
* @param int $hard_limit The hard limit, in whatever unit the resource limit requires, or
* POSIX_RLIMIT_INFINITY.
* @throws PosixException
*
*/
function posix_setrlimit(int $resource, int $soft_limit, int $hard_limit): void
{
error_clear_last();
$safeResult = \posix_setrlimit($resource, $soft_limit, $hard_limit);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Make the current process a session leader.
*
* @return int Returns the session ids.
* @throws PosixException
*
*/
function posix_setsid(): int
{
error_clear_last();
$safeResult = \posix_setsid();
if ($safeResult === -1) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* Set the real user ID of the current process. This is a privileged
* function that needs appropriate privileges (usually root) on
* the system to be able to perform this function.
*
* @param int $user_id The user id.
* @throws PosixException
*
*/
function posix_setuid(int $user_id): void
{
error_clear_last();
$safeResult = \posix_setuid($user_id);
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
}
/**
* Gets information about the current CPU usage.
*
* @return array Returns a hash of strings with information about the current
* process CPU usage. The indices of the hash are:
*
*
*
* ticks - the number of clock ticks that have elapsed since
* reboot.
*
*
*
*
* utime - user time used by the current process.
*
*
*
*
* stime - system time used by the current process.
*
*
*
*
* cutime - user time used by current process and children.
*
*
*
*
* cstime - system time used by current process and children.
*
*
*
* The function returns FALSE on failure.
* @throws PosixException
*
*/
function posix_times(): array
{
error_clear_last();
$safeResult = \posix_times();
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets information about the system.
*
* Posix requires that assumptions must not be made about the
* format of the values, e.g. the assumption that a release may contain
* three digits or anything else returned by this function.
*
* @return array Returns a hash of strings with information about the
* system. The indices of the hash are
*
*
* sysname - operating system name (e.g. Linux)
*
*
* nodename - system name (e.g. valiant)
*
*
* release - operating system release (e.g. 2.2.10)
*
*
* version - operating system version (e.g. #4 Tue Jul 20
* 17:01:36 MEST 1999)
*
*
* machine - system architecture (e.g. i586)
*
*
* domainname - DNS domainname (e.g. example.com)
*
*
*
* domainname is a GNU extension and not part of POSIX.1, so this
* field is only available on GNU systems or when using the GNU
* libc.
*
* The function returns FALSE on failure.
* @throws PosixException
*
*/
function posix_uname(): array
{
error_clear_last();
$safeResult = \posix_uname();
if ($safeResult === false) {
throw PosixException::createFromPhpError();
}
return $safeResult;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,497 @@
<?php
namespace Safe;
use Safe\Exceptions\PspellException;
/**
*
*
* @param int $dictionary An PSpell\Dictionary instance.
* @param string $word The added word.
* @throws PspellException
*
*/
function pspell_add_to_personal(int $dictionary, string $word): void
{
error_clear_last();
$safeResult = \pspell_add_to_personal($dictionary, $word);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
*
*
* @param int $dictionary An PSpell\Dictionary instance.
* @param string $word The added word.
* @throws PspellException
*
*/
function pspell_add_to_session(int $dictionary, string $word): void
{
error_clear_last();
$safeResult = \pspell_add_to_session($dictionary, $word);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
*
*
* @param int $dictionary An PSpell\Dictionary instance.
* @throws PspellException
*
*/
function pspell_clear_session(int $dictionary): void
{
error_clear_last();
$safeResult = \pspell_clear_session($dictionary);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
* Create a config used to open a dictionary.
*
* pspell_config_create has a very similar syntax to
* pspell_new. In fact, using
* pspell_config_create immediately followed by
* pspell_new_config will produce the exact same result.
* However, after creating a new config, you can also use
* pspell_config_* functions before calling
* pspell_new_config to take advantage of some
* advanced functionality.
*
* For more information and examples, check out inline manual pspell
* website:http://aspell.net/.
*
* @param string $language The language parameter is the language code which consists of the
* two letter ISO 639 language code and an optional two letter ISO
* 3166 country code after a dash or underscore.
* @param string $spelling The spelling parameter is the requested spelling for languages
* with more than one spelling such as English. Known values are
* 'american', 'british', and 'canadian'.
* @param string $jargon The jargon parameter contains extra information to distinguish
* two different words lists that have the same language and
* spelling parameters.
* @param string $encoding The encoding parameter is the encoding that words are expected to
* be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r',
* 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned
* 32'. This parameter is largely untested, so be careful when
* using.
* @return false|int Returns an PSpell\Config instance.
*
*/
function pspell_config_create(string $language, string $spelling = "", string $jargon = "", string $encoding = "")
{
error_clear_last();
$safeResult = \pspell_config_create($language, $spelling, $jargon, $encoding);
return $safeResult;
}
/**
* This function is
* currently not documented; only its argument list is available.
*
*
* @param int $config
* @param string $directory
* @throws PspellException
*
*/
function pspell_config_data_dir(int $config, string $directory): void
{
error_clear_last();
$safeResult = \pspell_config_data_dir($config, $directory);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
* This function is
* currently not documented; only its argument list is available.
*
*
* @param int $config
* @param string $directory
* @throws PspellException
*
*/
function pspell_config_dict_dir(int $config, string $directory): void
{
error_clear_last();
$safeResult = \pspell_config_dict_dir($config, $directory);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
*
*
* @param int $config An PSpell\Config instance.
* @param int $min_length Words less than min_length characters will be skipped.
* @throws PspellException
*
*/
function pspell_config_ignore(int $config, int $min_length): void
{
error_clear_last();
$safeResult = \pspell_config_ignore($config, $min_length);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
*
*
* @param int $config An PSpell\Config instance.
* @param int $mode The mode parameter is the mode in which spellchecker will work.
* There are several modes available:
*
*
*
* PSPELL_FAST - Fast mode (least number of
* suggestions)
*
*
*
*
* PSPELL_NORMAL - Normal mode (more suggestions)
*
*
*
*
* PSPELL_BAD_SPELLERS - Slow mode (a lot of
* suggestions)
*
*
*
* @throws PspellException
*
*/
function pspell_config_mode(int $config, int $mode): void
{
error_clear_last();
$safeResult = \pspell_config_mode($config, $mode);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
* Set a file that contains personal wordlist. The personal wordlist will be
* loaded and used in addition to the standard one after you call
* pspell_new_config. The file is also the file where
* pspell_save_wordlist will save personal wordlist to.
*
* pspell_config_personal should be used on a config
* before calling pspell_new_config.
*
* @param int $config An PSpell\Config instance.
* @param string $filename The personal wordlist. If the file does not exist, it will be created.
* The file should be writable by whoever PHP runs as (e.g. nobody).
* @throws PspellException
*
*/
function pspell_config_personal(int $config, string $filename): void
{
error_clear_last();
$safeResult = \pspell_config_personal($config, $filename);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
* Set a file that contains replacement pairs.
*
* The replacement pairs improve the quality of the spellchecker. When a word
* is misspelled, and a proper suggestion was not found in the list,
* pspell_store_replacement can be used to store a
* replacement pair and then pspell_save_wordlist to
* save the wordlist along with the replacement pairs.
*
* pspell_config_repl should be used on a config
* before calling pspell_new_config.
*
* @param int $config An PSpell\Config instance.
* @param string $filename The file should be writable by whoever PHP runs as (e.g. nobody).
* @throws PspellException
*
*/
function pspell_config_repl(int $config, string $filename): void
{
error_clear_last();
$safeResult = \pspell_config_repl($config, $filename);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
* This function determines whether run-together words will be treated as
* legal compounds. That is, "thecat" will be a legal compound, although
* there should be a space between the two words. Changing this setting only
* affects the results returned by pspell_check;
* pspell_suggest will still return suggestions.
*
* pspell_config_runtogether should be used on a config
* before calling pspell_new_config.
*
* @param int $config An PSpell\Config instance.
* @param bool $allow TRUE if run-together words should be treated as legal compounds,
* FALSE otherwise.
* @throws PspellException
*
*/
function pspell_config_runtogether(int $config, bool $allow): void
{
error_clear_last();
$safeResult = \pspell_config_runtogether($config, $allow);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
* pspell_config_save_repl determines whether
* pspell_save_wordlist will save the replacement pairs
* along with the wordlist. Usually there is no need to use this function
* because if pspell_config_repl is used, the
* replacement pairs will be saved by
* pspell_save_wordlist anyway, and if it is not,
* the replacement pairs will not be saved.
*
* pspell_config_save_repl should be used on a config
* before calling pspell_new_config.
*
* @param int $config An PSpell\Config instance.
* @param bool $save TRUE if replacement pairs should be saved, FALSE otherwise.
* @throws PspellException
*
*/
function pspell_config_save_repl(int $config, bool $save): void
{
error_clear_last();
$safeResult = \pspell_config_save_repl($config, $save);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
*
*
* @param int $config The config parameter is the one returned by
* pspell_config_create when the config was created.
* @return int Returns an PSpell\Dictionary instance on success
* @throws PspellException
*
*/
function pspell_new_config(int $config): int
{
error_clear_last();
$safeResult = \pspell_new_config($config);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
return $safeResult;
}
/**
* For more information and examples, check out inline manual pspell
* website:http://aspell.net/.
*
* @param string $filename The file where words added to the personal list will be stored.
* It should be an absolute filename beginning with '/' because otherwise
* it will be relative to $HOME, which is "/root" for most systems, and
* is probably not what you want.
* @param string $language The language code which consists of the two letter ISO 639 language
* code and an optional two letter ISO 3166 country code after a dash
* or underscore.
* @param string $spelling The requested spelling for languages with more than one spelling such
* as English. Known values are 'american', 'british', and 'canadian'.
* @param string $jargon Extra information to distinguish two different words lists that have
* the same language and spelling parameters.
* @param string $encoding The encoding that words are expected to be in. Valid values are
* utf-8, iso8859-*,
* koi8-r, viscii,
* cp1252, machine unsigned 16,
* machine unsigned 32.
* @param int $mode The mode in which spellchecker will work. There are several modes available:
*
*
*
* PSPELL_FAST - Fast mode (least number of
* suggestions)
*
*
*
*
* PSPELL_NORMAL - Normal mode (more suggestions)
*
*
*
*
* PSPELL_BAD_SPELLERS - Slow mode (a lot of
* suggestions)
*
*
*
*
* PSPELL_RUN_TOGETHER - Consider run-together words
* as legal compounds. That is, "thecat" will be a legal compound,
* although there should be a space between the two words. Changing this
* setting only affects the results returned by
* pspell_check; pspell_suggest
* will still return suggestions.
*
*
*
* Mode is a bitmask constructed from different constants listed above.
* However, PSPELL_FAST,
* PSPELL_NORMAL and
* PSPELL_BAD_SPELLERS are mutually exclusive, so you
* should select only one of them.
* @return int Returns an PSpell\Dictionary instance on success.
* @throws PspellException
*
*/
function pspell_new_personal(string $filename, string $language, string $spelling = "", string $jargon = "", string $encoding = "", int $mode = 0): int
{
error_clear_last();
$safeResult = \pspell_new_personal($filename, $language, $spelling, $jargon, $encoding, $mode);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
return $safeResult;
}
/**
* pspell_new opens up a new dictionary and
* returns an PSpell\Dictionary instance for use in other pspell
* functions.
*
* For more information and examples, check out inline manual pspell
* website:http://aspell.net/.
*
* @param string $language The language parameter is the language code which consists of the
* two letter ISO 639 language code and an optional two letter ISO
* 3166 country code after a dash or underscore.
* @param string $spelling The spelling parameter is the requested spelling for languages
* with more than one spelling such as English. Known values are
* 'american', 'british', and 'canadian'.
* @param string $jargon The jargon parameter contains extra information to distinguish
* two different words lists that have the same language and
* spelling parameters.
* @param string $encoding The encoding parameter is the encoding that words are expected to
* be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r',
* 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned
* 32'. This parameter is largely untested, so be careful when
* using.
* @param int $mode The mode parameter is the mode in which spellchecker will work.
* There are several modes available:
*
*
*
* PSPELL_FAST - Fast mode (least number of
* suggestions)
*
*
*
*
* PSPELL_NORMAL - Normal mode (more suggestions)
*
*
*
*
* PSPELL_BAD_SPELLERS - Slow mode (a lot of
* suggestions)
*
*
*
*
* PSPELL_RUN_TOGETHER - Consider run-together words
* as legal compounds. That is, "thecat" will be a legal compound,
* although there should be a space between the two words. Changing this
* setting only affects the results returned by
* pspell_check; pspell_suggest
* will still return suggestions.
*
*
*
* Mode is a bitmask constructed from different constants listed above.
* However, PSPELL_FAST,
* PSPELL_NORMAL and
* PSPELL_BAD_SPELLERS are mutually exclusive, so you
* should select only one of them.
* @return int Returns an PSpell\Dictionary instance on success.
* @throws PspellException
*
*/
function pspell_new(string $language, string $spelling = "", string $jargon = "", string $encoding = "", int $mode = 0): int
{
error_clear_last();
$safeResult = \pspell_new($language, $spelling, $jargon, $encoding, $mode);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param int $dictionary An PSpell\Dictionary instance.
* @throws PspellException
*
*/
function pspell_save_wordlist(int $dictionary): void
{
error_clear_last();
$safeResult = \pspell_save_wordlist($dictionary);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}
/**
*
*
* @param int $dictionary An PSpell\Dictionary instance.
* @param string $misspelled The misspelled word.
* @param string $correct The fixed spelling for the misspelled word.
* @throws PspellException
*
*/
function pspell_store_replacement(int $dictionary, string $misspelled, string $correct): void
{
error_clear_last();
$safeResult = \pspell_store_replacement($dictionary, $misspelled, $correct);
if ($safeResult === false) {
throw PspellException::createFromPhpError();
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Safe;
use Safe\Exceptions\ReadlineException;
/**
* This function adds a line to the command line history.
*
* @param string $prompt The line to be added in the history.
* @return bool Always returns TRUE.
*
*/
function readline_add_history(string $prompt): bool
{
error_clear_last();
$safeResult = \readline_add_history($prompt);
return $safeResult;
}
/**
* Sets up a readline callback interface then prints
* prompt and immediately returns.
* Calling this function twice without removing the previous
* callback interface will automatically and conveniently overwrite the old
* interface.
*
* The callback feature is useful when combined with
* stream_select as it allows interleaving of IO and
* user input, unlike readline.
*
* @param string $prompt The prompt message.
* @param callable $callback The callback function takes one parameter; the
* user input returned.
* @return bool Always returns TRUE.
*
*/
function readline_callback_handler_install(string $prompt, callable $callback): bool
{
error_clear_last();
$safeResult = \readline_callback_handler_install($prompt, $callback);
return $safeResult;
}
/**
* This function clears the entire command line history.
*
* @return bool Always returns TRUE.
*
*/
function readline_clear_history(): bool
{
error_clear_last();
$safeResult = \readline_clear_history();
return $safeResult;
}
/**
* This function registers a completion function. This is the same kind of
* functionality you'd get if you hit your tab key while using Bash.
*
* @param callable $callback You must supply the name of an existing function which accepts a
* partial command line and returns an array of possible matches.
* @throws ReadlineException
*
*/
function readline_completion_function(callable $callback): void
{
error_clear_last();
$safeResult = \readline_completion_function($callback);
if ($safeResult === false) {
throw ReadlineException::createFromPhpError();
}
}
/**
* This function reads a command history from a file.
*
* @param null|string $filename Path to the filename containing the command history.
* @throws ReadlineException
*
*/
function readline_read_history(?string $filename = null): void
{
error_clear_last();
if ($filename !== null) {
$safeResult = \readline_read_history($filename);
} else {
$safeResult = \readline_read_history();
}
if ($safeResult === false) {
throw ReadlineException::createFromPhpError();
}
}
/**
* This function writes the command history to a file.
*
* @param null|string $filename Path to the saved file.
* @throws ReadlineException
*
*/
function readline_write_history(?string $filename = null): void
{
error_clear_last();
if ($filename !== null) {
$safeResult = \readline_write_history($filename);
} else {
$safeResult = \readline_write_history();
}
if ($safeResult === false) {
throw ReadlineException::createFromPhpError();
}
}

0
vendor/thecodingmachine/safe/generated/8.5/rector-migrate.php vendored Normal file → Executable file
View File

View File

@@ -0,0 +1,629 @@
<?php
namespace Safe;
use Safe\Exceptions\RnpException;
/**
* Private keys used for decryption should be loaded into the FFI object before calling this function.
* If password encryption was used, then password provider should be set by calling
* rnp_ffi_set_pass_provider.
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $input Encrypted message.
* @return string Decrypted message on success.
* @throws RnpException
*
*/
function rnp_decrypt(\RnpFFI $ffi, string $input): string
{
error_clear_last();
$safeResult = \rnp_decrypt($ffi, $input);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param string $input Input string containing OpenPGP data, either in binary or ASCII-armored format.
* @param int $flags See RNP_JSON_DUMP_* predefined constants.
* @return string JSON string with dump.
* @throws RnpException
*
*/
function rnp_dump_packets_to_json(string $input, int $flags): string
{
error_clear_last();
$safeResult = \rnp_dump_packets_to_json($input, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param string $input Input string containing OpenPGP data, either in binary or ASCII-armored format.
* @param int $flags See RNP_DUMP_* predefined constants.
* @return string Text describing packet sequence.
* @throws RnpException
*
*/
function rnp_dump_packets(string $input, int $flags): string
{
error_clear_last();
$safeResult = \rnp_dump_packets($input, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param string $pub_format the format of the public keyring, RNP_KEYSTORE_GPG or other
* RNP_KEYSTORE_* constant.
* @param string $sec_format the format of the secret keyring, RNP_KEYSTORE_GPG or other
* RNP_KEYSTORE_* constant
* @return \RnpFFI Returns RnpFFI object on success.
* @throws RnpException
*
*/
function rnp_ffi_create(string $pub_format, string $sec_format): \RnpFFI
{
error_clear_last();
$safeResult = \rnp_ffi_create($pub_format, $sec_format);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
* Sets password provider function. This function can ask for the password on a standard input
* (if PHP script is executed in a command line environment), display GUI dialog or provide
* password in any other possible ways. Requested passwords are used to encrypt or decrypt
* secret keys or perform symmetric encryption/decryption operations.
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param callable $password_callback The function that is to be called for every password request. It has the following signature:
*
* boolpassword_callback
* stringkey_fp
* stringpgp_context
* stringpassword
*
*
* $key_fp - The key fingerprint, if any. Can be empty.
* $pgp_context - String describing why the key is being requested.
* $password - Password string reference where provided password should be stored to.
*
* Callback function should return TRUE if password was successfully set or FALSE on failure.
* @throws RnpException
*
*/
function rnp_ffi_set_pass_provider(\RnpFFI $ffi, callable $password_callback): void
{
error_clear_last();
$safeResult = \rnp_ffi_set_pass_provider($ffi, $password_callback);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $input OpenPGP packets containing key(s) to be loaded. Can be either binary or ASCII armored.
* @param int $flags See RNP_LOAD_SAVE_* predefined constants.
* @return string JSON string with information about new and updated keys on success.
* @throws RnpException
*
*/
function rnp_import_keys(\RnpFFI $ffi, string $input, int $flags): string
{
error_clear_last();
$safeResult = \rnp_import_keys($ffi, $input, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $input OpenPGP packets containing signatures to be imported. Can be either binary or ASCII armored.
* @param int $flags Currently must be 0.
* @return string JSON string with information about updated keys on success.
* @throws RnpException
*
*/
function rnp_import_signatures(\RnpFFI $ffi, string $input, int $flags): string
{
error_clear_last();
$safeResult = \rnp_import_signatures($ffi, $input, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $key_fp Primary key fingerprint.
* @param string $subkey_fp Subkey to export. Can be an empty string
* to pick the first suitable subkey.
* @param string $uid User ID to export. Can be an empty string
* if exported key has only one uid.
* @param int $flags Only RNP_KEY_EXPORT_BASE64 is currently supported. Enabling
* it would export base64-encoded key data instead of binary.
* @return string OpenPGP packets of exported key on success.
* @throws RnpException
*
*/
function rnp_key_export_autocrypt(\RnpFFI $ffi, string $key_fp, string $subkey_fp, string $uid, int $flags): string
{
error_clear_last();
$safeResult = \rnp_key_export_autocrypt($ffi, $key_fp, $subkey_fp, $uid, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
* Note: to revoke a key you'll need to import this signature into the keystore or use
* rnp_key_revoke function.
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $key_fp Key fingerprint of the primary key to be revoked.
* @param int $flags RNP_KEY_EXPORT_ARMORED or 0.
* @param array $options An associative array with options.
* @return string Exported revocation signature on success.
* @throws RnpException
*
*/
function rnp_key_export_revocation(\RnpFFI $ffi, string $key_fp, int $flags, ?array $options = null): string
{
error_clear_last();
if ($options !== null) {
$safeResult = \rnp_key_export_revocation($ffi, $key_fp, $flags, $options);
} else {
$safeResult = \rnp_key_export_revocation($ffi, $key_fp, $flags);
}
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $key_fp Key fingerprint.
* @param int $flags See RNP_KEY_EXPORT_* predefined constants
* (except RNP_KEY_EXPORT_BASE64).
* @return string OpenPGP packets of exported key (binary or ASCII-armored) on success.
* @throws RnpException
*
*/
function rnp_key_export(\RnpFFI $ffi, string $key_fp, int $flags): string
{
error_clear_last();
$safeResult = \rnp_key_export($ffi, $key_fp, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $key_fp Key fingerprint.
* @return array An associative array with information about the key.
* @throws RnpException
*
*/
function rnp_key_get_info(\RnpFFI $ffi, string $key_fp): array
{
error_clear_last();
$safeResult = \rnp_key_get_info($ffi, $key_fp);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
* Note: you need to call rnp_save_keys to write updated keyring(s) out.
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $key_fp Key fingerprint.
* @param int $flags See RNP_KEY_REMOVE_* constants. Flag RNP_KEY_REMOVE_SUBKEYS will work only for
* the primary key and will remove all of its subkeys as well.
* @throws RnpException
*
*/
function rnp_key_remove(\RnpFFI $ffi, string $key_fp, int $flags): void
{
error_clear_last();
$safeResult = \rnp_key_remove($ffi, $key_fp, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
}
/**
* Note: you need to call rnp_save_keys to write updated keyring(s) out.
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $key_fp Key fingerprint.
* @param int $flags Currently must be 0.
* @param array $options An associative array with options.
* @throws RnpException
*
*/
function rnp_key_revoke(\RnpFFI $ffi, string $key_fp, int $flags, ?array $options = null): void
{
error_clear_last();
if ($options !== null) {
$safeResult = \rnp_key_revoke($ffi, $key_fp, $flags, $options);
} else {
$safeResult = \rnp_key_revoke($ffi, $key_fp, $flags);
}
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $identifier_type Key identifier type ("userid", "keyid", "grip", "fingerprint").
* @return array An associative array where key is an identifier string and value is a PGP key fingerprint.
* @throws RnpException
*
*/
function rnp_list_keys(\RnpFFI $ffi, string $identifier_type): array
{
error_clear_last();
$safeResult = \rnp_list_keys($ffi, $identifier_type);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
* Note that for G10, the input must be a directory (which must already exist).
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $format The key format of the data (GPG, KBX, G10).
* @param string $input_path file or directory containing the keys.
* @param int $flags See RNP_LOAD_SAVE_* flags description.
* @throws RnpException
*
*/
function rnp_load_keys_from_path(\RnpFFI $ffi, string $format, string $input_path, int $flags): void
{
error_clear_last();
$safeResult = \rnp_load_keys_from_path($ffi, $format, $input_path, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
}
/**
* Note that for G10, the input must be a directory (which must already exist).
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $format The key format of the data (GPG, KBX, G10).
* @param string $input OpenPGP packets containing key(s) to be loaded. Can be either binary or ASCII armored.
* @param int $flags See RNP_LOAD_SAVE_* flags description.
* @throws RnpException
*
*/
function rnp_load_keys(\RnpFFI $ffi, string $format, string $input, int $flags): void
{
error_clear_last();
$safeResult = \rnp_load_keys($ffi, $format, $input, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
}
/**
* Note: only valid userids are checked while searching by userid.
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $identifier_type Identifier type string: "userid", "keyid", "fingerprint", "grip".
* @param string $identifier PGP User ID (name and email) for "userid" type, hexadecimal string
* that represents key id, fingerprint or key grip correspondingly.
* @return string Returns hexadecimal fingerprint of the key found on success.
* @throws RnpException
*
*/
function rnp_locate_key(\RnpFFI $ffi, string $identifier_type, string $identifier): string
{
error_clear_last();
$safeResult = \rnp_locate_key($ffi, $identifier_type, $identifier);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $message Message to be encrypted.
* @param array $recipient_keys_fp Array with fingerprints of recipient's keys. At least one key must be present.
* @param array $options An associative array with options.
* @return string Encrypted data on success.
* @throws RnpException
*
*/
function rnp_op_encrypt(\RnpFFI $ffi, string $message, array $recipient_keys_fp, ?array $options = null): string
{
error_clear_last();
if ($options !== null) {
$safeResult = \rnp_op_encrypt($ffi, $message, $recipient_keys_fp, $options);
} else {
$safeResult = \rnp_op_encrypt($ffi, $message, $recipient_keys_fp);
}
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $userid PGP User ID - text that is intended to represent
* the name and email address of the key holder.
* @param string $key_alg Primary key algorithm (i.e. 'RSA', 'DSA', etc).
* @param string $sub_alg Subkey algorithm. If not set, subkey will not be generated.
* @param array $options An associative array with options.
* @return string Fingerprint of the generated primary key. This fingerprint can be used
* later to reference the key in sign and encrypt operations. The key data is stored in FFI
* memory context and can be saved using
* rnp_save_keys or rnp_save_keys_to_path.
* @throws RnpException
*
*/
function rnp_op_generate_key(\RnpFFI $ffi, string $userid, string $key_alg, ?string $sub_alg = null, ?array $options = null): string
{
error_clear_last();
if ($options !== null) {
$safeResult = \rnp_op_generate_key($ffi, $userid, $key_alg, $sub_alg, $options);
} elseif ($sub_alg !== null) {
$safeResult = \rnp_op_generate_key($ffi, $userid, $key_alg, $sub_alg);
} else {
$safeResult = \rnp_op_generate_key($ffi, $userid, $key_alg);
}
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $data Data to be signed.
* @param array $keys_fp Array with key fingerprints. At least one key must be provided.
* Keys should be present in ffi.
* @param array $options An associative array with options.
* @return string Cleartext signed message containing source data with
* additional headers and ASCII-armored signature on success.
* @throws RnpException
*
*/
function rnp_op_sign_cleartext(\RnpFFI $ffi, string $data, array $keys_fp, ?array $options = null): string
{
error_clear_last();
if ($options !== null) {
$safeResult = \rnp_op_sign_cleartext($ffi, $data, $keys_fp, $options);
} else {
$safeResult = \rnp_op_sign_cleartext($ffi, $data, $keys_fp);
}
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $data Data to be signed.
* @param array $keys_fp Array with key fingerprints. At least one key must be provided.
* Keys should be present in ffi.
* @param array $options An associative array with options.
* @return string Detached signature(s) data on success.
* @throws RnpException
*
*/
function rnp_op_sign_detached(\RnpFFI $ffi, string $data, array $keys_fp, ?array $options = null): string
{
error_clear_last();
if ($options !== null) {
$safeResult = \rnp_op_sign_detached($ffi, $data, $keys_fp, $options);
} else {
$safeResult = \rnp_op_sign_detached($ffi, $data, $keys_fp);
}
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $data Data to be signed.
* @param array $keys_fp Array with key fingerprints. At least one key must be provided.
* Keys should be present in ffi.
* @param array $options An associative array with options.
* @return string Data with embedded signature(s) on success.
* @throws RnpException
*
*/
function rnp_op_sign(\RnpFFI $ffi, string $data, array $keys_fp, ?array $options = null): string
{
error_clear_last();
if ($options !== null) {
$safeResult = \rnp_op_sign($ffi, $data, $keys_fp, $options);
} else {
$safeResult = \rnp_op_sign($ffi, $data, $keys_fp);
}
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $data Source data.
* @param string $signature Detached signature data.
* @return array An associative array with information about verification results.
*
* "signatures" sub-array.
* @throws RnpException
*
*/
function rnp_op_verify_detached(\RnpFFI $ffi, string $data, string $signature): array
{
error_clear_last();
$safeResult = \rnp_op_verify_detached($ffi, $data, $signature);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $data Signed data.
* @return array An associative array with information about verification results.
*
* "signatures" sub-array.
* @throws RnpException
*
*/
function rnp_op_verify(\RnpFFI $ffi, string $data): array
{
error_clear_last();
$safeResult = \rnp_op_verify($ffi, $data);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}
/**
* Saves keys present in the FFI object (loaded or generated) to the specified file or directory.
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $format The key format of the data (GPG, KBX, G10).
* @param string $output_path File or directory path where keys should be saved to.
* @param int $flags See RNP_LOAD_SAVE_* flags description.
* @throws RnpException
*
*/
function rnp_save_keys_to_path(\RnpFFI $ffi, string $format, string $output_path, int $flags): void
{
error_clear_last();
$safeResult = \rnp_save_keys_to_path($ffi, $format, $output_path, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
}
/**
* Note that for G10, the output must be a directory (which must already exist).
*
* @param \RnpFFI $ffi The FFI object returned by rnp_ffi_create.
* @param string $format The key format of the data (GPG, KBX, G10).
* @param string $output key packets will be saved to the string referenced by output.
* @param int $flags See RNP_LOAD_SAVE_* flags description.
* @throws RnpException
*
*/
function rnp_save_keys(\RnpFFI $ffi, string $format, string &$output, int $flags): void
{
error_clear_last();
$safeResult = \rnp_save_keys($ffi, $format, $output, $flags);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
}
/**
* Get the JSON formatted string containing array of supported rnp feature values (algorithms, curves, etc) by type.
*
* @param string $type See RNP_FEATURE_* constants for supported values.
* @return string String containing JSON formatted array of supported algorithms, curves, etc.
* @throws RnpException
*
*/
function rnp_supported_features(string $type): string
{
error_clear_last();
$safeResult = \rnp_supported_features($type);
if ($safeResult === false) {
throw RnpException::createFromPhpError();
}
return $safeResult;
}

0
vendor/thecodingmachine/safe/generated/8.5/rpminfo.php vendored Normal file → Executable file
View File

View File

@@ -0,0 +1,190 @@
<?php
namespace Safe;
use Safe\Exceptions\RrdException;
/**
* Creates the rdd database file.
*
* @param string $filename Filename for newly created rrd file.
* @param array $options Options for rrd create - list of strings. See man page of rrd create
* for whole list of options.
* @throws RrdException
*
*/
function rrd_create(string $filename, array $options): void
{
error_clear_last();
$safeResult = \rrd_create($filename, $options);
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
}
/**
* Returns the first data sample from the specified RRA of the RRD file.
*
* @param string $file RRD database file name.
* @param int $raaindex The index number of the RRA that is to be examined. Default value is 0.
* @return int Integer number of unix timestamp.
* @throws RrdException
*
*/
function rrd_first(string $file, int $raaindex = 0): int
{
error_clear_last();
$safeResult = \rrd_first($file, $raaindex);
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
return $safeResult;
}
/**
* Creates image for a particular data from RRD file.
*
* @param string $filename The filename to output the graph to. This will generally end in either
* .png, .svg or
* .eps, depending on the format you want to output.
* @param array $options Options for generating image. See man page of rrd graph for all
* possible options. All options (data definitions, variable definitions, etc.)
* are allowed.
* @return array Array with information about generated image is returned.
* @throws RrdException
*
*/
function rrd_graph(string $filename, array $options): array
{
error_clear_last();
$safeResult = \rrd_graph($filename, $options);
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns information about particular RRD database file.
*
* @param string $filename RRD database file name.
* @return array Array with information about requested RRD file.
* @throws RrdException
*
*/
function rrd_info(string $filename): array
{
error_clear_last();
$safeResult = \rrd_info($filename);
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets array of the UNIX timestamp and the values stored for each date in the
* most recent update of the RRD database file.
*
* @param string $filename RRD database file name.
* @return array Array of information about last update.
* @throws RrdException
*
*/
function rrd_lastupdate(string $filename): array
{
error_clear_last();
$safeResult = \rrd_lastupdate($filename);
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
return $safeResult;
}
/**
* Restores the RRD file from the XML dump.
*
* @param string $xml_file XML filename with the dump of the original RRD database file.
* @param string $rrd_file Restored RRD database file name.
* @param array $options Array of options for restoring. See man page for rrd restore.
* @throws RrdException
*
*/
function rrd_restore(string $xml_file, string $rrd_file, ?array $options = null): void
{
error_clear_last();
if ($options !== null) {
$safeResult = \rrd_restore($xml_file, $rrd_file, $options);
} else {
$safeResult = \rrd_restore($xml_file, $rrd_file);
}
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
}
/**
* Change some options in the RRD dabase header file. E.g. renames the source for
* the data etc.
*
* @param string $filename RRD database file name.
* @param array $options Options with RRD database file properties which will be changed. See
* rrd tune man page for details.
* @throws RrdException
*
*/
function rrd_tune(string $filename, array $options): void
{
error_clear_last();
$safeResult = \rrd_tune($filename, $options);
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
}
/**
* Updates the RRD database file. The input data is time interpolated according to the
* properties of the RRD database file.
*
* @param string $filename RRD database file name. This database will be updated.
* @param array $options Options for updating the RRD database. This is list of strings. See man page of rrd update
* for whole list of options.
* @throws RrdException
*
*/
function rrd_update(string $filename, array $options): void
{
error_clear_last();
$safeResult = \rrd_update($filename, $options);
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
}
/**
* Exports the information about RRD database file. This data can be converted
* to XML file via user space PHP script and then restored back as RRD database
* file.
*
* @param array $options Array of options for the export, see rrd xport man page.
* @return array Array with information about RRD database file.
* @throws RrdException
*
*/
function rrd_xport(array $options): array
{
error_clear_last();
$safeResult = \rrd_xport($options);
if ($safeResult === false) {
throw RrdException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,545 @@
<?php
namespace Safe;
use Safe\Exceptions\SemException;
/**
* msg_get_queue returns an id that can be used to
* access the System V message queue with the given
* key. The first call creates the message queue with
* the optional permissions.
* A second call to msg_get_queue for the same
* key will return a different message queue
* identifier, but both identifiers access the same underlying message
* queue.
*
* @param int $key Message queue numeric ID
* @param int $permissions Queue permissions. Default to 0666. If the message queue already
* exists, the permissions will be ignored.
* @return \SysvMessageQueue Returns SysvMessageQueue instance that can be used to access the System V message queue.
* @throws SemException
*
*/
function msg_get_queue(int $key, int $permissions = 0666): \SysvMessageQueue
{
error_clear_last();
$safeResult = \msg_get_queue($key, $permissions);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
return $safeResult;
}
/**
* Checks whether the message queue key exists.
*
* @param int $key Queue key.
* @throws SemException
*
*/
function msg_queue_exists(int $key): void
{
error_clear_last();
$safeResult = \msg_queue_exists($key);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* msg_receive will receive the first message from the
* specified queue of the type specified by
* desired_message_type.
*
* @param \SysvMessageQueue $queue The message queue.
* @param int $desired_message_type If desired_message_type is 0, the message from the front
* of the queue is returned. If desired_message_type is
* greater than 0, then the first message of that type is returned.
* If desired_message_type is less than 0, the first
* message on the queue with a type less than or equal to the
* absolute value of desired_message_type will be read.
* If no messages match the criteria, your script will wait until a suitable
* message arrives on the queue. You can prevent the script from blocking
* by specifying MSG_IPC_NOWAIT in the
* flags parameter.
* @param int|null $received_message_type The type of the message that was received will be stored in this
* parameter.
* @param int $max_message_size The maximum size of message to be accepted is specified by the
* max_message_size; if the message in the queue is larger
* than this size the function will fail (unless you set
* flags as described below).
* @param mixed $message The received message will be stored in message,
* unless there were errors receiving the message.
* @param bool $unserialize If set to
* TRUE, the message is treated as though it was serialized using the
* same mechanism as the session module. The message will be unserialized
* and then returned to your script. This allows you to easily receive
* arrays or complex object structures from other PHP scripts, or if you
* are using the WDDX serializer, from any WDDX compatible source.
*
* If unserialize is FALSE, the message will be
* returned as a binary-safe string.
* @param int $flags The optional flags allows you to pass flags to the
* low-level msgrcv system call. It defaults to 0, but you may specify one
* or more of the following values (by adding or ORing them together).
*
* Flag values for msg_receive
*
*
*
* MSG_IPC_NOWAIT
* If there are no messages of the
* desired_message_type, return immediately and do not
* wait. The function will fail and return an integer value
* corresponding to MSG_ENOMSG.
*
*
*
* MSG_EXCEPT
* Using this flag in combination with a
* desired_message_type greater than 0 will cause the
* function to receive the first message that is not equal to
* desired_message_type.
*
*
* MSG_NOERROR
*
* If the message is longer than max_message_size,
* setting this flag will truncate the message to
* max_message_size and will not signal an error.
*
*
*
*
*
* @param int|null $error_code If the function fails, the optional error_code
* will be set to the value of the system errno variable.
* @throws SemException
*
*/
function msg_receive(\SysvMessageQueue $queue, int $desired_message_type, ?int &$received_message_type, int $max_message_size, &$message, bool $unserialize = true, int $flags = 0, ?int &$error_code = null): void
{
error_clear_last();
$safeResult = \msg_receive($queue, $desired_message_type, $received_message_type, $max_message_size, $message, $unserialize, $flags, $error_code);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* msg_remove_queue destroys the message queue specified
* by the queue. Only use this function when all
* processes have finished working with the message queue and you need to
* release the system resources held by it.
*
* @param \SysvMessageQueue $queue The message queue.
* @throws SemException
*
*/
function msg_remove_queue(\SysvMessageQueue $queue): void
{
error_clear_last();
$safeResult = \msg_remove_queue($queue);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* msg_send sends a message of type
* message_type (which MUST be greater than 0) to
* the message queue specified by queue.
*
* @param \SysvMessageQueue $queue The message queue.
* @param int $message_type The type of the message (MUST be greater than 0)
* @param mixed $message The body of the message.
*
* If serialize set to FALSE is supplied,
* MUST be of type: string, int, float
* or bool. In other case a warning will be issued.
* @param bool $serialize The optional serialize controls how the
* message is sent. serialize
* defaults to TRUE which means that the message is
* serialized using the same mechanism as the session module before being
* sent to the queue. This allows complex arrays and objects to be sent to
* other PHP scripts, or if you are using the WDDX serializer, to any WDDX
* compatible client.
* @param bool $blocking If the message is too large to fit in the queue, your script will wait
* until another process reads messages from the queue and frees enough
* space for your message to be sent.
* This is called blocking; you can prevent blocking by setting the
* optional blocking parameter to FALSE, in which
* case msg_send will immediately return FALSE if the
* message is too big for the queue, and set the optional
* error_code to MSG_EAGAIN,
* indicating that you should try to send your message again a little
* later on.
* @param int|null $error_code If the function fails, the optional errorcode will be set to the value of the system errno variable.
* @throws SemException
*
*/
function msg_send(\SysvMessageQueue $queue, int $message_type, $message, bool $serialize = true, bool $blocking = true, ?int &$error_code = null): void
{
error_clear_last();
$safeResult = \msg_send($queue, $message_type, $message, $serialize, $blocking, $error_code);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* msg_set_queue allows you to change the values of the
* msg_perm.uid, msg_perm.gid, msg_perm.mode and msg_qbytes fields of the
* underlying message queue data structure.
*
* Changing the data structure will require that PHP be running as the same
* user that created the queue, owns the queue (as determined by the
* existing msg_perm.xxx fields), or be running with root privileges.
* root privileges are required to raise the msg_qbytes values above the
* system defined limit.
*
* @param \SysvMessageQueue $queue The message queue.
* @param array $data You specify the values you require by setting the value of the keys
* that you require in the data array.
* @throws SemException
*
*/
function msg_set_queue(\SysvMessageQueue $queue, array $data): void
{
error_clear_last();
$safeResult = \msg_set_queue($queue, $data);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* msg_stat_queue returns the message queue meta data
* for the message queue specified by the queue.
* This is useful, for example, to determine which process sent the message
* that was just received.
*
* @param \SysvMessageQueue $queue The message queue.
* @return array On success, the return value is an array whose keys and values have the following
* meanings:
*
* Array structure for msg_stat_queue
*
*
*
* msg_perm.uid
*
* The uid of the owner of the queue.
*
*
*
* msg_perm.gid
*
* The gid of the owner of the queue.
*
*
*
* msg_perm.mode
*
* The file access mode of the queue.
*
*
*
* msg_stime
*
* The time that the last message was sent to the queue.
*
*
*
* msg_rtime
*
* The time that the last message was received from the queue.
*
*
*
* msg_ctime
*
* The time that the queue was last changed.
*
*
*
* msg_qnum
*
* The number of messages waiting to be read from the queue.
*
*
*
* msg_qbytes
*
* The maximum number of bytes allowed in one message queue. On
* Linux, this value may be read and modified via
* /proc/sys/kernel/msgmnb.
*
*
*
* msg_lspid
*
* The pid of the process that sent the last message to the queue.
*
*
*
* msg_lrpid
*
* The pid of the process that received the last message from the queue.
*
*
*
*
*
*
* Returns FALSE on failure.
* @throws SemException
*
*/
function msg_stat_queue(\SysvMessageQueue $queue): array
{
error_clear_last();
$safeResult = \msg_stat_queue($queue);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
return $safeResult;
}
/**
* sem_acquire by default blocks (if necessary) until the
* semaphore can be acquired. A process attempting to acquire a semaphore which
* it has already acquired will block forever if acquiring the semaphore would
* cause its maximum number of semaphore to be exceeded.
*
* After processing a request, any semaphores acquired by the process but not
* explicitly released will be released automatically and a warning will be
* generated.
*
* @param \SysvSemaphore $semaphore semaphore is a semaphore
* obtained from sem_get.
* @param bool $non_blocking Specifies if the process shouldn't wait for the semaphore to be acquired.
* If set to TRUE, the call will return
* FALSE immediately if a semaphore cannot be immediately
* acquired.
* @throws SemException
*
*/
function sem_acquire(\SysvSemaphore $semaphore, bool $non_blocking = false): void
{
error_clear_last();
$safeResult = \sem_acquire($semaphore, $non_blocking);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* sem_get returns an id that can be used to
* access the System V semaphore with the given key.
*
* A second call to sem_get for the same key
* will return a different semaphore identifier, but both
* identifiers access the same underlying semaphore.
*
* If key is 0, a new private semaphore
* is created for each call to sem_get.
*
* @param int $key
* @param int $max_acquire The number of processes that can acquire the semaphore simultaneously
* is set to max_acquire.
* @param int $permissions The semaphore permissions. Actually this value is
* set only if the process finds it is the only process currently
* attached to the semaphore.
* @param bool $auto_release Specifies if the semaphore should be automatically released on request
* shutdown.
* @return \SysvSemaphore Returns a positive semaphore identifier on success.
* @throws SemException
*
*/
function sem_get(int $key, int $max_acquire = 1, int $permissions = 0666, bool $auto_release = true): \SysvSemaphore
{
error_clear_last();
$safeResult = \sem_get($key, $max_acquire, $permissions, $auto_release);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
return $safeResult;
}
/**
* sem_release releases the semaphore if it
* is currently acquired by the calling process, otherwise
* a warning is generated.
*
* After releasing the semaphore, sem_acquire
* may be called to re-acquire it.
*
* @param \SysvSemaphore $semaphore A Semaphore as returned by
* sem_get.
* @throws SemException
*
*/
function sem_release(\SysvSemaphore $semaphore): void
{
error_clear_last();
$safeResult = \sem_release($semaphore);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* sem_remove removes the given semaphore.
*
* After removing the semaphore, it is no longer accessible.
*
* @param \SysvSemaphore $semaphore A semaphore as returned
* by sem_get.
* @throws SemException
*
*/
function sem_remove(\SysvSemaphore $semaphore): void
{
error_clear_last();
$safeResult = \sem_remove($semaphore);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* shm_attach returns an id that can be used to access
* the System V shared memory with the given key, the
* first call creates the shared memory segment with
* size and the optional perm-bits
* permissions.
*
* A second call to shm_attach for the same
* key will return a different SysvSharedMemory
* instance, but both instances access the same underlying
* shared memory. size and
* permissions will be ignored.
*
* @param int $key A numeric shared memory segment ID
* @param int|null $size The memory size. If not provided, default to the
* sysvshm.init_mem in the php.ini, otherwise 10000
* bytes.
* @param int $permissions The optional permission bits. Default to 0666.
* @return \SysvSharedMemory Returns a SysvSharedMemory instance on success.
* @throws SemException
*
*/
function shm_attach(int $key, ?int $size = null, int $permissions = 0666): \SysvSharedMemory
{
error_clear_last();
if ($permissions !== 0666) {
$safeResult = \shm_attach($key, $size, $permissions);
} elseif ($size !== null) {
$safeResult = \shm_attach($key, $size);
} else {
$safeResult = \shm_attach($key);
}
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
return $safeResult;
}
/**
* shm_detach disconnects from the shared memory given
* by the shm created by
* shm_attach. Remember, that shared memory still exist
* in the Unix system and the data is still present.
*
* @param \SysvSharedMemory $shm A shared memory segment obtained from shm_attach.
* @throws SemException
*
*/
function shm_detach(\SysvSharedMemory $shm): void
{
error_clear_last();
$safeResult = \shm_detach($shm);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* shm_put_var inserts or updates the
* value with the given
* key.
*
* Warnings (E_WARNING level) will be issued if
* shm is not a valid SysV shared memory
* index or if there was not enough shared memory remaining to complete your
* request.
*
* @param \SysvSharedMemory $shm A shared memory segment obtained from shm_attach.
* @param int $key The variable key.
* @param mixed $value The variable. All variable types
* that serialize supports may be used: generally
* this means all types except for resources and some internal objects
* that cannot be serialized.
* @throws SemException
*
*/
function shm_put_var(\SysvSharedMemory $shm, int $key, $value): void
{
error_clear_last();
$safeResult = \shm_put_var($shm, $key, $value);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* Removes a variable with a given key
* and frees the occupied memory.
*
* @param \SysvSharedMemory $shm A shared memory segment obtained from shm_attach.
* @param int $key The variable key.
* @throws SemException
*
*/
function shm_remove_var(\SysvSharedMemory $shm, int $key): void
{
error_clear_last();
$safeResult = \shm_remove_var($shm, $key);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}
/**
* shm_remove removes the shared memory
* shm. All data will be destroyed.
*
* @param \SysvSharedMemory $shm A shared memory segment obtained from shm_attach.
* @throws SemException
*
*/
function shm_remove(\SysvSharedMemory $shm): void
{
error_clear_last();
$safeResult = \shm_remove($shm);
if ($safeResult === false) {
throw SemException::createFromPhpError();
}
}

View File

@@ -0,0 +1,542 @@
<?php
namespace Safe;
use Safe\Exceptions\SessionException;
/**
* session_abort finishes session without saving
* data. Thus the original values in session data are kept.
*
* @throws SessionException
*
*/
function session_abort(): void
{
error_clear_last();
$safeResult = \session_abort();
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
}
/**
* session_cache_expire returns the current setting of
* session.cache_expire.
*
* The cache expire is reset to the default value of 180 stored in
* session.cache_expire
* at request startup time. Thus,
* you need to call session_cache_expire for every
* request (and before session_start is called).
*
* @param int|null $value If value is given and not NULL, the current cache
* expire is replaced with value.
*
*
*
* Setting value is of value only, if
* session.cache_limiter is set to a value
* different from nocache.
*
*
* @return int Returns the current setting of session.cache_expire.
* The value returned should be read in minutes, defaults to 180.
* @throws SessionException
*
*/
function session_cache_expire(?int $value = null): int
{
error_clear_last();
if ($value !== null) {
$safeResult = \session_cache_expire($value);
} else {
$safeResult = \session_cache_expire();
}
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_cache_limiter returns the name of the
* current cache limiter.
*
* The cache limiter defines which cache control HTTP headers are sent to
* the client. These headers determine the rules by which the page content
* may be cached by the client and intermediate proxies. Setting the cache
* limiter to nocache disallows any client/proxy caching.
* A value of public permits caching by proxies and the
* client, whereas private disallows caching by proxies
* and permits the client to cache the contents.
*
* In private mode, the Expire header sent to the client
* may cause confusion for some browsers, including Mozilla.
* You can avoid this problem by using private_no_expire mode. The
* Expire header is never sent to the client in this mode.
*
* Setting the cache limiter to '' will turn off automatic sending
* of cache headers entirely.
*
* The cache limiter is reset to the default value stored in
* session.cache_limiter
* at request startup time. Thus, you need to call
* session_cache_limiter for every
* request (and before session_start is called).
*
* @param null|string $value If value is specified and not NULL, the name of the
* current cache limiter is changed to the new value.
* @return string Returns the name of the current cache limiter.
* @throws SessionException
*
*/
function session_cache_limiter(?string $value = null): string
{
error_clear_last();
if ($value !== null) {
$safeResult = \session_cache_limiter($value);
} else {
$safeResult = \session_cache_limiter();
}
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_create_id is used to create new
* session id for the current session. It returns collision free
* session id.
*
* If session is not active, collision check is omitted.
*
* Session ID is created according to php.ini settings.
*
* It is important to use the same user ID of your web server for GC
* task script. Otherwise, you may have permission problems especially
* with files save handler.
*
* @param string $prefix If prefix is specified, new session id
* is prefixed by prefix. Not all
* characters are allowed within the session id. Characters in
* the range [a-zA-Z0-9,-] are allowed. Maximum length is 256 characters.
* @return string session_create_id returns new collision free
* session id for the current session. If it is used without active
* session, it omits collision check.
* On failure, FALSE is returned.
* @throws SessionException
*
*/
function session_create_id(string $prefix = ""): string
{
error_clear_last();
$safeResult = \session_create_id($prefix);
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_decode decodes the serialized session data provided in
* $data, and populates the $_SESSION superglobal
* with the result.
*
* By default, the unserialization method used is internal to PHP, and is not the same as unserialize.
* The serialization method can be set using session.serialize_handler.
*
* @param string $data The encoded data to be stored.
* @throws SessionException
*
*/
function session_decode(string $data): void
{
error_clear_last();
$safeResult = \session_decode($data);
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
}
/**
* In order to kill the session altogether, the
* session ID must also be unset. If a cookie is used to propagate the
* session ID (default behavior), then the session cookie must be deleted.
* setcookie may be used for that.
*
* When session.use_strict_mode
* is enabled. You do not have to remove obsolete session ID cookie because
* session module will not accept session ID cookie when there is no
* data associated to the session ID and set new session ID cookie.
* Enabling session.use_strict_mode
* is recommended for all sites.
*
* @throws SessionException
*
*/
function session_destroy(): void
{
error_clear_last();
$safeResult = \session_destroy();
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
}
/**
* session_encode returns a serialized string of the
* contents of the current session data stored in the $_SESSION superglobal.
*
* By default, the serialization method used is internal to PHP, and is not the same as serialize.
* The serialization method can be set using session.serialize_handler.
*
* @return string Returns the contents of the current session encoded.
* @throws SessionException
*
*/
function session_encode(): string
{
error_clear_last();
$safeResult = \session_encode();
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_gc is used to perform session data
* GC (garbage collection). PHP does probability based session GC by
* default.
*
* Probability based GC works somewhat but it has few problems. 1) Low
* traffic sites' session data may not be deleted within the preferred
* duration. 2) High traffic sites' GC may be too frequent GC. 3) GC is
* performed on the user's request and the user will experience a GC
* delay.
*
* Therefore, it is recommended to execute GC periodically for
* production systems using, e.g., "cron" for UNIX-like systems.
* Make sure to disable probability based GC by setting
* session.gc_probability
* to 0.
*
* @return int session_gc returns number of deleted session
* data for success.
*
* Old save handlers do not return number of deleted session data, but
* only success/failure flag. If this is the case, number of deleted
* session data became 1 regardless of actually deleted data.
* @throws SessionException
*
*/
function session_gc(): int
{
error_clear_last();
$safeResult = \session_gc();
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_id is used to get or set the session id for
* the current session.
*
* The constant SID can also be used to
* retrieve the current name and session id as a string suitable for
* adding to URLs. See also Session
* handling.
*
* @param null|string $id If id is specified and not NULL, it will replace the current
* session id. session_id needs to be called before
* session_start for that purpose. Depending on the
* session handler, not all characters are allowed within the session id.
* For example, the file session handler only allows characters in the
* range [a-zA-Z0-9,-]!
* @return string session_id returns the session id for the current
* session or the empty string ("") if there is no current
* session (no current session id exists).
* On failure, FALSE is returned.
* @throws SessionException
*
*/
function session_id(?string $id = null): string
{
error_clear_last();
if ($id !== null) {
$safeResult = \session_id($id);
} else {
$safeResult = \session_id();
}
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_module_name gets the name of the current
* session module, which is also known as
* session.save_handler.
*
* @param null|string $module If module is specified and not NULL, that module will be
* used instead.
* Passing "user" to this parameter is forbidden. Instead
* session_set_save_handler has to be called to set a user
* defined session handler.
* @return string Returns the name of the current session module.
* @throws SessionException
*
*/
function session_module_name(?string $module = null): string
{
error_clear_last();
if ($module !== null) {
$safeResult = \session_module_name($module);
} else {
$safeResult = \session_module_name();
}
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_name returns the name of the current
* session. If name is given,
* session_name will update the session name and return
* the old session name.
*
* If a new session name is
* supplied, session_name modifies the HTTP cookie
* (and outputs the content when session.use_trans_sid is
* enabled). Once the HTTP cookie has been
* sent, calling session_name raises an E_WARNING.
* session_name must be called
* before session_start for the session to work
* properly.
*
* The session name is reset to the default value stored in
* session.name at request startup time. Thus, you need to
* call session_name for every request (and before
* session_start is called).
*
* @param null|string $name The session name references the name of the session, which is
* used in cookies and URLs (e.g. PHPSESSID). It
* should contain only alphanumeric characters; it should be short and
* descriptive (i.e. for users with enabled cookie warnings).
* If name is specified and not NULL, the name of the current
* session is changed to its value.
*
*
*
* The session name can't consist of digits only, at least one letter
* must be present. Otherwise a new session id is generated every time.
*
*
*
* The session name can't consist of digits only, at least one letter
* must be present. Otherwise a new session id is generated every time.
* @return non-falsy-string Returns the name of the current session. If name is given
* and function updates the session name, name of the old session
* is returned.
* @throws SessionException
*
*/
function session_name(?string $name = null): string
{
error_clear_last();
if ($name !== null) {
$safeResult = \session_name($name);
} else {
$safeResult = \session_name();
}
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_regenerate_id will replace the current
* session id with a new one, and keep the current session information.
*
* When session.use_trans_sid
* is enabled, output must be started after session_regenerate_id
* call. Otherwise, old session ID is used.
*
* @param bool $delete_old_session Whether to delete the old associated session file or not.
* You should not delete old session if you need to avoid
* races caused by deletion or detect/avoid session hijack
* attacks.
* @throws SessionException
*
*/
function session_regenerate_id(bool $delete_old_session = false): void
{
error_clear_last();
$safeResult = \session_regenerate_id($delete_old_session);
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
}
/**
* session_reset reinitializes a session with
* original values stored in session storage. This function requires an active session and
* discards changes in $_SESSION.
*
* @throws SessionException
*
*/
function session_reset(): void
{
error_clear_last();
$safeResult = \session_reset();
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
}
/**
* session_save_path returns the path of the current
* directory used to save session data.
*
* @param null|string $path Session data path. If specified and not NULL, the path to which data is saved will
* be changed. session_save_path needs to be called
* before session_start for that purpose.
*
*
*
* On some operating systems, you may want to specify a path on a
* filesystem that handles lots of small files efficiently.
*
*
*
* On some operating systems, you may want to specify a path on a
* filesystem that handles lots of small files efficiently.
* @return string Returns the path of the current directory used for data storage.
* @throws SessionException
*
*/
function session_save_path(?string $path = null): string
{
error_clear_last();
if ($path !== null) {
$safeResult = \session_save_path($path);
} else {
$safeResult = \session_save_path();
}
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
return $safeResult;
}
/**
* session_start creates a session or resumes the
* current one based on a session identifier passed via a GET or POST
* request, or passed via a cookie.
*
* When session_start is called or when a session auto starts,
* PHP will call the open and read session save handlers. These will either be a built-in
* save handler provided by default or by PHP extensions (such as SQLite or Memcached); or can be
* custom handler as defined by session_set_save_handler.
* The read callback will retrieve any existing session data (stored in a special serialized format)
* and will be unserialized and used to automatically populate the $_SESSION superglobal when the
* read callback returns the saved session data back to PHP session handling.
*
* To use a named session, call
* session_name before calling
* session_start.
*
* When session.use_trans_sid
* is enabled, the session_start function will
* register an internal output handler for URL rewriting.
*
* If a user uses ob_gzhandler or similar with
* ob_start, the function order is important for
* proper output. For example,
* ob_gzhandler must be registered before starting the session.
*
* @param array $options If provided, this is an associative array of options that will override
* the currently set
* session configuration directives.
* The keys should not include the session. prefix.
*
* In addition to the normal set of configuration directives, a
* read_and_close option may also be provided. If set to
* TRUE, this will result in the session being closed immediately after
* being read, thereby avoiding unnecessary locking if the session data
* won't be changed.
* @throws SessionException
*
*/
function session_start(array $options = []): void
{
error_clear_last();
$safeResult = \session_start($options);
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
}
/**
* The session_unset function frees all session variables
* currently registered.
*
* @throws SessionException
*
*/
function session_unset(): void
{
error_clear_last();
$safeResult = \session_unset();
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
}
/**
* End the current session and store session data.
*
* Session data is usually stored after your script terminated without the
* need to call session_write_close, but as session data
* is locked to prevent concurrent writes only one script may operate on a
* session at any time. When using framesets together with sessions you will
* experience the frames loading one by one due to this locking. You can
* reduce the time needed to load all the frames by ending the session as
* soon as all changes to session variables are done.
*
* @throws SessionException
*
*/
function session_write_close(): void
{
error_clear_last();
$safeResult = \session_write_close();
if ($safeResult === false) {
throw SessionException::createFromPhpError();
}
}

0
vendor/thecodingmachine/safe/generated/8.5/shmop.php vendored Normal file → Executable file
View File

View File

@@ -0,0 +1,871 @@
<?php
namespace Safe;
use Safe\Exceptions\SocketsException;
/**
* After the socket socket has been created
* using socket_create, bound to a name with
* socket_bind, and told to listen for connections
* with socket_listen, this function will accept
* incoming connections on that socket. Once a successful connection
* is made, a new Socket instance is returned,
* which may be used for communication. If there are multiple connections
* queued on the socket, the first will be used. If there are no pending
* connections, socket_accept will block until
* a connection becomes present. If socket
* has been made non-blocking using
* socket_set_blocking or
* socket_set_nonblock, FALSE will be returned.
*
* The Socket instance returned by
* socket_accept may not be used to accept new
* connections. The original listening socket
* socket, however, remains open and may be
* reused.
*
* @param \Socket $socket A Socket instance created with socket_create.
* @return \Socket Returns a new Socket instance on success. The actual
* error code can be retrieved by calling
* socket_last_error. This error code may be passed to
* socket_strerror to get a textual explanation of the
* error.
* @throws SocketsException
*
*/
function socket_accept(\Socket $socket): \Socket
{
error_clear_last();
$safeResult = \socket_accept($socket);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* Create a Socket instance, and bind it to the provided AddressInfo. The return
* value of this function may be used with socket_listen.
*
* @param \AddressInfo $address AddressInfo instance created from socket_addrinfo_lookup.
* @return \Socket Returns a Socket instance on success.
* @throws SocketsException
*
*/
function socket_addrinfo_bind(\AddressInfo $address): \Socket
{
error_clear_last();
$safeResult = \socket_addrinfo_bind($address);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* Create a Socket instance, and connect it to the provided AddressInfo instance. The return
* value of this function may be used with the rest of the socket functions.
*
* @param \AddressInfo $address AddressInfo instance created from socket_addrinfo_lookup.
* @return \Socket Returns a Socket instance on success.
* @throws SocketsException
*
*/
function socket_addrinfo_connect(\AddressInfo $address): \Socket
{
error_clear_last();
$safeResult = \socket_addrinfo_connect($address);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* Lookup different ways we can connect to host. The returned array contains
* a set of AddressInfo instances that we can bind to using socket_addrinfo_bind.
*
* @param string $host Hostname to search.
* @param mixed $service The service to connect to. If service is a numeric string, it designates the port.
* Otherwise it designates a network service name, which is mapped to a port by the operating system.
* @param array $hints Hints provide criteria for selecting addresses returned. You may specify the
* hints as defined by getaddrinfo.
* @return \AddressInfo[] Returns an array of AddressInfo instances that can be used with
* the socket_addrinfo_* family of functions.
* On failure, FALSE is returned.
* @throws SocketsException
*
*/
function socket_addrinfo_lookup(string $host, $service = null, array $hints = []): array
{
error_clear_last();
if ($hints !== []) {
$safeResult = \socket_addrinfo_lookup($host, $service, $hints);
} elseif ($service !== null) {
$safeResult = \socket_addrinfo_lookup($host, $service);
} else {
$safeResult = \socket_addrinfo_lookup($host);
}
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* Determines whether socket is at out-of-band mark.
*
* @param \Socket $socket A Socket instance created with socket_create.
* @throws SocketsException
*
*/
function socket_atmark(\Socket $socket): void
{
error_clear_last();
$safeResult = \socket_atmark($socket);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* Binds the name given in address to the socket
* described by socket. This has to be done before
* a connection is established using socket_connect
* or socket_listen.
*
* @param \Socket $socket A Socket instance created with socket_create.
* @param string $address If the socket is of the AF_INET family, the
* address is an IP in dotted-quad notation
* (e.g. 127.0.0.1).
*
* If the socket is of the AF_UNIX family, the
* address is the path of a
* Unix-domain socket (e.g. /tmp/my.sock).
* @param int $port The port parameter is only used when
* binding an AF_INET socket, and designates
* the port on which to listen for connections.
* @throws SocketsException
*
*/
function socket_bind(\Socket $socket, string $address, int $port = 0): void
{
error_clear_last();
$safeResult = \socket_bind($socket, $address, $port);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* Initiate a connection to address using the Socket instance
* socket, which must be Socket
* instance created with socket_create.
*
* @param \Socket $socket A Socket instance created with
* socket_create.
* @param string $address The address parameter is either an IPv4 address
* in dotted-quad notation (e.g. 127.0.0.1) if
* socket is AF_INET, a valid
* IPv6 address (e.g. ::1) if IPv6 support is enabled and
* socket is AF_INET6
* or the pathname of a Unix domain socket, if the socket family is
* AF_UNIX.
* @param int|null $port The port parameter is only used and is mandatory
* when connecting to an AF_INET or an
* AF_INET6 socket, and designates
* the port on the remote host to which a connection should be made.
* @throws SocketsException
*
*/
function socket_connect(\Socket $socket, string $address, ?int $port = null): void
{
error_clear_last();
if ($port !== null) {
$safeResult = \socket_connect($socket, $address, $port);
} else {
$safeResult = \socket_connect($socket, $address);
}
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* socket_create_listen creates a new Socket instance of
* type AF_INET listening on all
* local interfaces on the given port waiting for new connections.
*
* This function is meant to ease the task of creating a new socket which
* only listens to accept new connections.
*
* @param int $port The port on which to listen on all interfaces.
* @param int $backlog The backlog parameter defines the maximum length
* the queue of pending connections may grow to.
* SOMAXCONN may be passed as
* backlog parameter, see
* socket_listen for more information.
* @return \Socket socket_create_listen returns a new Socket instance
* on success. The error code can be retrieved with
* socket_last_error. This code may be passed to
* socket_strerror to get a textual explanation of the
* error.
* @throws SocketsException
*
*/
function socket_create_listen(int $port, int $backlog = SOMAXCONN): \Socket
{
error_clear_last();
$safeResult = \socket_create_listen($port, $backlog);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* socket_create_pair creates two connected and
* indistinguishable sockets, and stores them in pair.
* This function is commonly used in IPC (InterProcess Communication).
*
* @param int $domain The domain parameter specifies the protocol
* family to be used by the socket. See socket_create
* for the full list.
* @param int $type The type parameter selects the type of communication
* to be used by the socket. See socket_create for the
* full list.
* @param int $protocol The protocol parameter sets the specific
* protocol within the specified domain to be used
* when communicating on the returned socket. The proper value can be retrieved by
* name by using getprotobyname. If
* the desired protocol is TCP, or UDP the corresponding constants
* SOL_TCP, and SOL_UDP
* can also be used.
*
* See socket_create for the full list of supported
* protocols.
* @param \Socket[]|null $pair Reference to an array in which the two Socket instances will be inserted.
* @throws SocketsException
*
*/
function socket_create_pair(int $domain, int $type, int $protocol, ?array &$pair): void
{
error_clear_last();
$safeResult = \socket_create_pair($domain, $type, $protocol, $pair);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* Creates and returns a Socket instance, also referred to as an endpoint
* of communication. A typical network connection is made up of 2 sockets, one
* performing the role of the client, and another performing the role of the server.
*
* @param int $domain The domain parameter specifies the protocol
* family to be used by the socket.
* @param int $type The type parameter selects the type of communication
* to be used by the socket.
* @param int $protocol The protocol parameter sets the specific
* protocol within the specified domain to be used
* when communicating on the returned socket. The proper value can be
* retrieved by name by using getprotobyname. If
* the desired protocol is TCP, or UDP the corresponding constants
* SOL_TCP, and SOL_UDP
* can also be used.
* @return \Socket socket_create returns a Socket instance on success. The actual error code can be retrieved by calling
* socket_last_error. This error code may be passed to
* socket_strerror to get a textual explanation of the
* error.
* @throws SocketsException
*
*/
function socket_create(int $domain, int $type, int $protocol): \Socket
{
error_clear_last();
$safeResult = \socket_create($domain, $type, $protocol);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \Socket $socket
* @return resource Return resource.
* @throws SocketsException
*
*/
function socket_export_stream(\Socket $socket)
{
error_clear_last();
$safeResult = \socket_export_stream($socket);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* The socket_get_option function retrieves the value for
* the option specified by the option parameter for the
* specified socket.
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_accept.
* @param int $level The level parameter specifies the protocol
* level at which the option resides. For example, to retrieve options at
* the socket level, a level parameter of
* SOL_SOCKET would be used. Other levels, such as
* TCP, can be used by
* specifying the protocol number of that level. Protocol numbers can be
* found by using the getprotobyname function.
* @param int $option Reports whether the socket lingers on
* socket_close if data is present. By default,
* when the socket is closed, it attempts to send all unsent data.
* In the case of a connection-oriented socket,
* socket_close will wait for its peer to
* acknowledge the data.
*
* If l_onoff is non-zero and
* l_linger is zero, all the
* unsent data will be discarded and RST (reset) is sent to the
* peer in the case of a connection-oriented socket.
*
* On the other hand, if l_onoff is
* non-zero and l_linger is non-zero,
* socket_close will block until all the data
* is sent or the time specified in l_linger
* elapses. If the socket is non-blocking,
* socket_close will fail and return an error.
* @return mixed Returns the value of the given option.
* @throws SocketsException
*
*/
function socket_get_option(\Socket $socket, int $level, int $option)
{
error_clear_last();
$safeResult = \socket_get_option($socket, $level, $option);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* Queries the remote side of the given socket which may either result in
* host/port or in a Unix filesystem path, dependent on its type.
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_accept.
* @param null|string $address If the given socket is of type AF_INET or
* AF_INET6, socket_getpeername
* will return the peers (remote) IP address in
* appropriate notation (e.g. 127.0.0.1 or
* fe80::1) in the address
* parameter and, if the optional port parameter is
* present, also the associated port.
*
* If the given socket is of type AF_UNIX,
* socket_getpeername will return the Unix filesystem
* path (e.g. /var/run/daemon.sock) in the
* address parameter.
* @param int|null $port If given, this will hold the port associated to
* address.
* @throws SocketsException
*
*/
function socket_getpeername(\Socket $socket, ?string &$address, ?int &$port = null): void
{
error_clear_last();
$safeResult = \socket_getpeername($socket, $address, $port);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
*
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_accept.
* @param null|string $address If the given socket is of type AF_INET
* or AF_INET6, socket_getsockname
* will return the local IP address in appropriate notation (e.g.
* 127.0.0.1 or fe80::1) in the
* address parameter and, if the optional
* port parameter is present, also the associated port.
*
* If the given socket is of type AF_UNIX,
* socket_getsockname will return the Unix filesystem
* path (e.g. /var/run/daemon.sock) in the
* address parameter.
* @param int|null $port If provided, this will hold the associated port.
* @throws SocketsException
*
*/
function socket_getsockname(\Socket $socket, ?string &$address, ?int &$port = null): void
{
error_clear_last();
$safeResult = \socket_getsockname($socket, $address, $port);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* Imports a stream that encapsulates a socket into a socket extension resource.
*
* @param resource $stream The stream resource to import.
* @return \Socket Returns FALSE on failure.
* @throws SocketsException
*
*/
function socket_import_stream($stream): \Socket
{
error_clear_last();
$safeResult = \socket_import_stream($stream);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* After the socket socket has been created
* using socket_create and bound to a name with
* socket_bind, it may be told to listen for incoming
* connections on socket.
*
* socket_listen is applicable only to sockets of
* type SOCK_STREAM or
* SOCK_SEQPACKET.
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_addrinfo_bind
* @param int $backlog A maximum of backlog incoming connections will be
* queued for processing. If a connection request arrives with the queue
* full the client may receive an error with an indication of
* ECONNREFUSED, or, if the underlying protocol supports
* retransmission, the request may be ignored so that retries may succeed.
*
* The maximum number passed to the backlog
* parameter highly depends on the underlying platform. On Linux, it is
* silently truncated to SOMAXCONN. On win32, if
* passed SOMAXCONN, the underlying service provider
* responsible for the socket will set the backlog to a maximum
* reasonable value. There is no standard provision to
* find out the actual backlog value on this platform.
* @throws SocketsException
*
*/
function socket_listen(\Socket $socket, int $backlog = 0): void
{
error_clear_last();
$safeResult = \socket_listen($socket, $backlog);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* The function socket_read reads from the Socket instance
* socket created by the
* socket_create or
* socket_accept functions.
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_accept.
* @param int $length The maximum number of bytes read is specified by the
* length parameter. Otherwise you can use
* \r, \n,
* or \0 to end reading (depending on the mode
* parameter, see below).
* @param int $mode Optional mode parameter is a named constant:
*
*
*
* PHP_BINARY_READ (Default) - use the system
* recv() function. Safe for reading binary data.
*
*
*
*
* PHP_NORMAL_READ - reading stops at
* \n or \r.
*
*
*
* @return string socket_read returns the data as a string on success (including if the remote host has closed the
* connection). The error code can be retrieved with
* socket_last_error. This code may be passed to
* socket_strerror to get a textual representation of
* the error.
* @throws SocketsException
*
*/
function socket_read(\Socket $socket, int $length, int $mode = PHP_BINARY_READ): string
{
error_clear_last();
$safeResult = \socket_read($socket, $length, $mode);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* The function socket_send sends
* length bytes to the socket
* socket from data.
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_accept.
* @param string $data A buffer containing the data that will be sent to the remote host.
* @param int $length The number of bytes that will be sent to the remote host from
* data.
* @param int $flags The value of flags can be any combination of
* the following flags, joined with the binary OR (|)
* operator.
*
* Possible values for flags
*
*
*
* MSG_OOB
*
* Send OOB (out-of-band) data.
*
*
*
* MSG_EOR
*
* Indicate a record mark. The sent data completes the record.
*
*
*
* MSG_EOF
*
* Close the sender side of the socket and include an appropriate
* notification of this at the end of the sent data. The sent data
* completes the transaction.
*
*
*
* MSG_DONTROUTE
*
* Bypass routing, use direct interface.
*
*
*
*
*
* @return int socket_send returns the number of bytes sent.
* @throws SocketsException
*
*/
function socket_send(\Socket $socket, string $data, int $length, int $flags): int
{
error_clear_last();
$safeResult = \socket_send($socket, $data, $length, $flags);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param \Socket $socket
* @param array $message
* @param int $flags
* @return int Returns the number of bytes sent.
* @throws SocketsException
*
*/
function socket_sendmsg(\Socket $socket, array $message, int $flags = 0): int
{
error_clear_last();
$safeResult = \socket_sendmsg($socket, $message, $flags);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* The function socket_sendto sends
* length bytes from data
* through the socket socket to the
* port at the address address.
*
* @param \Socket $socket A Socket instance created using socket_create.
* @param string $data The sent data will be taken from buffer data.
* @param int $length length bytes from data will be
* sent.
* @param int $flags The value of flags can be any combination of
* the following flags, joined with the binary OR (|)
* operator.
*
* Possible values for flags
*
*
*
* MSG_OOB
*
* Send OOB (out-of-band) data.
*
*
*
* MSG_EOR
*
* Indicate a record mark. The sent data completes the record.
*
*
*
* MSG_EOF
*
* Close the sender side of the socket and include an appropriate
* notification of this at the end of the sent data. The sent data
* completes the transaction.
*
*
*
* MSG_DONTROUTE
*
* Bypass routing, use direct interface.
*
*
*
*
*
* @param string $address IP address of the remote host.
* @param int|null $port port is the remote port number at which the data
* will be sent.
* @return int socket_sendto returns the number of bytes sent to the
* remote host.
* @throws SocketsException
*
*/
function socket_sendto(\Socket $socket, string $data, int $length, int $flags, string $address, ?int $port = null): int
{
error_clear_last();
if ($port !== null) {
$safeResult = \socket_sendto($socket, $data, $length, $flags, $address, $port);
} else {
$safeResult = \socket_sendto($socket, $data, $length, $flags, $address);
}
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* The socket_set_block function removes the
* O_NONBLOCK flag on the socket specified by the
* socket parameter.
*
* When an operation (e.g. receive, send, connect, accept, ...) is performed on
* a blocking socket, the script will pause its execution until it receives
* a signal or it can perform the operation.
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_accept.
* @throws SocketsException
*
*/
function socket_set_block(\Socket $socket): void
{
error_clear_last();
$safeResult = \socket_set_block($socket);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* The socket_set_nonblock function sets the
* O_NONBLOCK flag on the socket specified by
* the socket parameter.
*
* When an operation (e.g. receive, send, connect, accept, ...) is performed on
* a non-blocking socket, the script will not pause its execution until it receives a
* signal or it can perform the operation. Rather, if the operation would result
* in a block, the called function will fail.
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_accept.
* @throws SocketsException
*
*/
function socket_set_nonblock(\Socket $socket): void
{
error_clear_last();
$safeResult = \socket_set_nonblock($socket);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* The socket_set_option function sets the option
* specified by the option parameter, at the
* specified protocol level, to the value pointed to
* by the value parameter for the
* socket.
*
* @param \Socket $socket A Socket instance created with socket_create
* or socket_accept.
* @param int $level The level parameter specifies the protocol
* level at which the option resides. For example, to set options at
* the socket level, a level parameter of
* SOL_SOCKET would be used. Other levels, such as
* TCP, can be used by specifying the protocol number of that level.
* Protocol numbers can be found by using the
* getprotobyname function.
* @param int $option The available socket options are the same as those for the
* socket_get_option function.
* @param array|int|string $value The option value.
* @throws SocketsException
*
*/
function socket_set_option(\Socket $socket, int $level, int $option, $value): void
{
error_clear_last();
$safeResult = \socket_set_option($socket, $level, $option, $value);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* The socket_shutdown function allows you to stop
* incoming, outgoing or all data (the default) from being sent through the
* socket
*
* @param \Socket $socket A Socket instance created with socket_create.
* @param int $mode The value of mode can be one of the following:
*
* possible values for mode
*
*
*
* 0
*
* Shutdown socket reading
*
*
*
* 1
*
* Shutdown socket writing
*
*
*
* 2
*
* Shutdown socket reading and writing
*
*
*
*
*
* @throws SocketsException
*
*/
function socket_shutdown(\Socket $socket, int $mode = 2): void
{
error_clear_last();
$safeResult = \socket_shutdown($socket, $mode);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}
/**
* Exports the WSAPROTOCOL_INFO structure into shared memory and returns
* an identifier to be used with socket_wsaprotocol_info_import. The
* exported ID is only valid for the given process_id.
*
* @param \Socket $socket A Socket instance.
* @param int $process_id The ID of the process which will import the socket.
* @return string Returns an identifier to be used for the import
* @throws SocketsException
*
*/
function socket_wsaprotocol_info_export(\Socket $socket, int $process_id): string
{
error_clear_last();
$safeResult = \socket_wsaprotocol_info_export($socket, $process_id);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* Imports a socket which has formerly been exported from another process.
*
* @param string $info_id The ID which has been returned by a former call to
* socket_wsaprotocol_info_export.
* @return \Socket Returns a Socket instance on success
* @throws SocketsException
*
*/
function socket_wsaprotocol_info_import(string $info_id): \Socket
{
error_clear_last();
$safeResult = \socket_wsaprotocol_info_import($info_id);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
return $safeResult;
}
/**
* Releases the shared memory corresponding to the given info_id.
*
* @param string $info_id The ID which has been returned by a former call to
* socket_wsaprotocol_info_export.
* @throws SocketsException
*
*/
function socket_wsaprotocol_info_release(string $info_id): void
{
error_clear_last();
$safeResult = \socket_wsaprotocol_info_release($info_id);
if ($safeResult === false) {
throw SocketsException::createFromPhpError();
}
}

View File

@@ -0,0 +1,392 @@
<?php
namespace Safe;
use Safe\Exceptions\SodiumException;
/**
*
*
* @param string $ciphertext
* @param string $additional_data
* @param string $nonce
* @param string $key
* @return string
* @throws SodiumException
*
*/
function sodium_crypto_aead_aegis128l_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_aegis128l_decrypt($ciphertext, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param string $ciphertext
* @param string $additional_data
* @param string $nonce
* @param string $key
* @return string
* @throws SodiumException
*
*/
function sodium_crypto_aead_aegis256_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_aegis256_decrypt($ciphertext, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Verify then decrypt with AES-256-GCM.
* Only available if sodium_crypto_aead_aes256gcm_is_available returns TRUE.
*
* @param string $ciphertext Must be in the format provided by sodium_crypto_aead_aes256gcm_encrypt
* (ciphertext and tag, concatenated).
* @param string $additional_data Additional, authenticated data. This is used in the verification of the authentication tag
* appended to the ciphertext, but it is not encrypted or stored in the ciphertext.
* @param string $nonce A number that must be only used once, per message. 12 bytes long.
* @param string $key Encryption key (256-bit).
* @return string Returns the plaintext on success.
* @throws SodiumException
*
*/
function sodium_crypto_aead_aes256gcm_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Verify then decrypt with ChaCha20-Poly1305.
*
* @param string $ciphertext Must be in the format provided by sodium_crypto_aead_chacha20poly1305_encrypt
* (ciphertext and tag, concatenated).
* @param string $additional_data Additional, authenticated data. This is used in the verification of the authentication tag
* appended to the ciphertext, but it is not encrypted or stored in the ciphertext.
* @param string $nonce A number that must be only used once, per message. 8 bytes long.
* @param string $key Encryption key (256-bit).
* @return string Returns the plaintext on success.
* @throws SodiumException
*
*/
function sodium_crypto_aead_chacha20poly1305_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Encrypt then authenticate with ChaCha20-Poly1305.
*
* @param string $message The plaintext message to encrypt.
* @param string $additional_data Additional, authenticated data. This is used in the verification of the authentication tag
* appended to the ciphertext, but it is not encrypted or stored in the ciphertext.
* @param string $nonce A number that must be only used once, per message. 8 bytes long.
* @param string $key Encryption key (256-bit).
* @return string Returns the ciphertext and tag on success.
* @throws SodiumException
*
*/
function sodium_crypto_aead_chacha20poly1305_encrypt(string $message, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_chacha20poly1305_encrypt($message, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Verify then decrypt with ChaCha20-Poly1305 (IETF variant).
*
* The IETF variant uses 96-bit nonces and 32-bit internal counters, instead of 64-bit for both.
*
* @param string $ciphertext Must be in the format provided by sodium_crypto_aead_chacha20poly1305_ietf_encrypt
* (ciphertext and tag, concatenated).
* @param string $additional_data Additional, authenticated data. This is used in the verification of the authentication tag
* appended to the ciphertext, but it is not encrypted or stored in the ciphertext.
* @param string $nonce A number that must be only used once, per message. 12 bytes long.
* @param string $key Encryption key (256-bit).
* @return string Returns the plaintext on success.
* @throws SodiumException
*
*/
function sodium_crypto_aead_chacha20poly1305_ietf_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Encrypt then authenticate with ChaCha20-Poly1305 (IETF variant).
*
* The IETF variant uses 96-bit nonces and 32-bit internal counters, instead of 64-bit for both.
*
* @param string $message The plaintext message to encrypt.
* @param string $additional_data Additional, authenticated data. This is used in the verification of the authentication tag
* appended to the ciphertext, but it is not encrypted or stored in the ciphertext.
* @param string $nonce A number that must be only used once, per message. 12 bytes long.
* @param string $key Encryption key (256-bit).
* @return string Returns the ciphertext and tag on success.
* @throws SodiumException
*
*/
function sodium_crypto_aead_chacha20poly1305_ietf_encrypt(string $message, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_chacha20poly1305_ietf_encrypt($message, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Verify then decrypt with ChaCha20-Poly1305 (eXtended-nonce variant).
*
* Generally, XChaCha20-Poly1305 is the best of the provided AEAD modes to use.
*
* @param string $ciphertext Must be in the format provided by sodium_crypto_aead_chacha20poly1305_ietf_encrypt
* (ciphertext and tag, concatenated).
* @param string $additional_data Additional, authenticated data. This is used in the verification of the authentication tag
* appended to the ciphertext, but it is not encrypted or stored in the ciphertext.
* @param string $nonce A number that must be only used once, per message. 24 bytes long.
* This is a large enough bound to generate randomly (i.e. random_bytes).
* @param string $key Encryption key (256-bit).
* @return string Returns the plaintext on success.
* @throws SodiumException
*
*/
function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Encrypt then authenticate with XChaCha20-Poly1305 (eXtended-nonce variant).
*
* Generally, XChaCha20-Poly1305 is the best of the provided AEAD modes to use.
*
* @param string $message The plaintext message to encrypt.
* @param string $additional_data Additional, authenticated data. This is used in the verification of the authentication tag
* appended to the ciphertext, but it is not encrypted or stored in the ciphertext.
* @param string $nonce A number that must be only used once, per message. 24 bytes long.
* This is a large enough bound to generate randomly (i.e. random_bytes).
* @param string $key Encryption key (256-bit).
* @return string Returns the ciphertext and tag on success.
* @throws SodiumException
*
*/
function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(string $message, string $additional_data, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($message, $additional_data, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Verify the authentication tag is valid for a given message and key.
*
* Unlike with digital signatures (e.g. sodium_crypto_sign_verify_detached),
* any party capable of verifying a message is also capable of authenticating
* their own messages. (Hence, symmetric authentication.)
*
* @param string $mac Authentication tag produced by sodium_crypto_auth
* @param string $message Message
* @param string $key Authentication key
* @throws SodiumException
*
*/
function sodium_crypto_auth_verify(string $mac, string $message, string $key): void
{
error_clear_last();
$safeResult = \sodium_crypto_auth_verify($mac, $message, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
}
/**
* Decrypt a message using asymmetric (public key) cryptography.
*
* @param string $ciphertext The encrypted message to attempt to decrypt.
* @param string $nonce A number that must be only used once, per message. 24 bytes long.
* This is a large enough bound to generate randomly (i.e. random_bytes).
* @param string $key_pair See sodium_crypto_box_keypair_from_secretkey_and_publickey.
* This should include the sender's public key and the recipient's secret key.
* @return string Returns the plaintext message on success.
* @throws SodiumException
*
*/
function sodium_crypto_box_open(string $ciphertext, string $nonce, string $key_pair): string
{
error_clear_last();
$safeResult = \sodium_crypto_box_open($ciphertext, $nonce, $key_pair);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Decrypt a message that was encrypted with sodium_crypto_box_seal
*
* @param string $ciphertext The encrypted message
* @param string $key_pair The keypair of the recipient. Must include the secret key.
* @return string The plaintext on success.
* @throws SodiumException
*
*/
function sodium_crypto_box_seal_open(string $ciphertext, string $key_pair): string
{
error_clear_last();
$safeResult = \sodium_crypto_box_seal_open($ciphertext, $key_pair);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Appends a message to the internal hash state.
*
* @param non-empty-string $state The return value of sodium_crypto_generichash_init.
* @param string $message Data to append to the hashing state.
* @return bool Always returns TRUE.
*
*/
function sodium_crypto_generichash_update(string &$state, string $message): bool
{
error_clear_last();
$safeResult = \sodium_crypto_generichash_update($state, $message);
return $safeResult;
}
/**
* Decrypt an encrypted message with a symmetric (shared) key.
*
* @param string $ciphertext Must be in the format provided by sodium_crypto_secretbox
* (ciphertext and tag, concatenated).
* @param string $nonce A number that must be only used once, per message. 24 bytes long.
* This is a large enough bound to generate randomly (i.e. random_bytes).
* @param string $key Encryption key (256-bit).
* @return string The decrypted string on success.
* @throws SodiumException
*
*/
function sodium_crypto_secretbox_open(string $ciphertext, string $nonce, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_secretbox_open($ciphertext, $nonce, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Verify the signature attached to a message and return the message
*
* @param string $signed_message A message signed with sodium_crypto_sign
* @param non-empty-string $public_key An Ed25519 public key
* @return string Returns the original signed message on success.
* @throws SodiumException
*
*/
function sodium_crypto_sign_open(string $signed_message, string $public_key): string
{
error_clear_last();
$safeResult = \sodium_crypto_sign_open($signed_message, $public_key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}
/**
* Verify signature for the message
*
* @param non-empty-string $signature The cryptographic signature obtained from sodium_crypto_sign_detached
* @param string $message The message being verified
* @param non-empty-string $public_key Ed25519 public key
* @throws SodiumException
*
*/
function sodium_crypto_sign_verify_detached(string $signature, string $message, string $public_key): void
{
error_clear_last();
$safeResult = \sodium_crypto_sign_verify_detached($signature, $message, $public_key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
}
/**
* The function is similar to sodium_crypto_stream_xchacha20_xor
* but adds the ability to set the initial value of the block counter to a non-zero value.
* This permits direct access to any block without having to compute the previous ones.
*
* @param string $message The message to encrypt.
* @param string $nonce 24-byte nonce.
* @param int $counter The initial value of the block counter.
* @param string $key Key, possibly generated from sodium_crypto_stream_xchacha20_keygen.
* @return string Encrypted message.
* @throws SodiumException
*
*/
function sodium_crypto_stream_xchacha20_xor_ic(string $message, string $nonce, int $counter, string $key): string
{
error_clear_last();
$safeResult = \sodium_crypto_stream_xchacha20_xor_ic($message, $nonce, $counter, $key);
if ($safeResult === false) {
throw SodiumException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Safe;
use Safe\Exceptions\SolrException;
/**
* This function returns the current version of the extension as a string.
*
* @return string It returns a string on success.
* @throws SolrException
*
*/
function solr_get_version(): string
{
error_clear_last();
$safeResult = \solr_get_version();
if ($safeResult === false) {
throw SolrException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,147 @@
<?php
namespace Safe;
use Safe\Exceptions\SplException;
/**
* This function returns an array with the names of the interfaces that the
* given object_or_class and its parents implement.
*
* @param object|string $object_or_class An object (class instance) or a string (class or interface name).
* @param bool $autoload Whether to autoload
* if not already loaded.
* @return array An array on success, or FALSE when the given class doesn't exist.
* @throws SplException
*
*/
function class_implements($object_or_class, bool $autoload = true): array
{
error_clear_last();
$safeResult = \class_implements($object_or_class, $autoload);
if ($safeResult === false) {
throw SplException::createFromPhpError();
}
return $safeResult;
}
/**
* This function returns an array with the name of the parent classes of
* the given object_or_class.
*
* @param object|string $object_or_class An object (class instance) or a string (class name).
* @param bool $autoload Whether to autoload
* if not already loaded.
* @return array An array on success, or FALSE when the given class doesn't exist.
* @throws SplException
*
*/
function class_parents($object_or_class, bool $autoload = true): array
{
error_clear_last();
$safeResult = \class_parents($object_or_class, $autoload);
if ($safeResult === false) {
throw SplException::createFromPhpError();
}
return $safeResult;
}
/**
* This function returns an array with the names of the traits that the
* given object_or_class uses. This does however not include
* any traits used by a parent class.
*
* @param object|string $object_or_class An object (class instance) or a string (class name).
* @param bool $autoload Whether to autoload
* if not already loaded.
* @return array An array on success, or FALSE when the given class doesn't exist.
* @throws SplException
*
*/
function class_uses($object_or_class, bool $autoload = true): array
{
error_clear_last();
$safeResult = \class_uses($object_or_class, $autoload);
if ($safeResult === false) {
throw SplException::createFromPhpError();
}
return $safeResult;
}
/**
* Register a function with the spl provided __autoload queue. If the queue
* is not yet activated it will be activated.
*
* If your code has an existing __autoload function then
* this function must be explicitly registered on the __autoload queue. This
* is because spl_autoload_register will effectively
* replace the engine cache for the __autoload function
* by either spl_autoload or
* spl_autoload_call.
*
* If there must be multiple autoload functions, spl_autoload_register
* allows for this. It effectively creates a queue of autoload functions, and
* runs through each of them in the order they are defined. By contrast,
* __autoload may only be defined once.
*
* @param callable(string):void|null $callback The autoload function being registered.
* If NULL, then the default implementation of
* spl_autoload will be registered.
*
* The class will not contain the leading
* backslash of a fully-qualified identifier.
* @param bool $throw This parameter specifies whether
* spl_autoload_register should throw
* exceptions when the callback
* cannot be registered.
*
* This parameter is ignored as of PHP 8.0.0, and a notice will be
* emitted if set to FALSE. spl_autoload_register
* will now always throw a TypeError on invalid
* arguments.
* @param bool $prepend If TRUE, spl_autoload_register will prepend
* the autoloader on the autoload queue instead of appending it.
* @throws SplException
*
*/
function spl_autoload_register(?callable $callback = null, bool $throw = true, bool $prepend = false): void
{
error_clear_last();
if ($prepend !== false) {
$safeResult = \spl_autoload_register($callback, $throw, $prepend);
} elseif ($throw !== true) {
$safeResult = \spl_autoload_register($callback, $throw);
} elseif ($callback !== null) {
$safeResult = \spl_autoload_register($callback);
} else {
$safeResult = \spl_autoload_register();
}
if ($safeResult === false) {
throw SplException::createFromPhpError();
}
}
/**
* Removes a function from the autoload queue. If the queue
* is activated and empty after removing the given function then it will
* be deactivated.
*
* When this function results in the queue being deactivated, any
* __autoload function that previously existed will not be reactivated.
*
* @param mixed $callback The autoload function being unregistered.
* @throws SplException
*
*/
function spl_autoload_unregister($callback): void
{
error_clear_last();
$safeResult = \spl_autoload_unregister($callback);
if ($safeResult === false) {
throw SplException::createFromPhpError();
}
}

View File

@@ -0,0 +1,571 @@
<?php
namespace Safe;
use Safe\Exceptions\SqlsrvException;
/**
* The transaction begun by sqlsrv_begin_transaction includes
* all statements that were executed after the call to
* sqlsrv_begin_transaction and before calls to
* sqlsrv_rollback or sqlsrv_commit.
* Explicit transactions should be started and committed or rolled back using
* these functions instead of executing SQL statements that begin and commit/roll
* back transactions. For more information, see
* SQLSRV Transactions.
*
* @param resource $conn The connection resource returned by a call to sqlsrv_connect.
* @throws SqlsrvException
*
*/
function sqlsrv_begin_transaction($conn): void
{
error_clear_last();
$safeResult = \sqlsrv_begin_transaction($conn);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
}
/**
* Cancels a statement. Any results associated with the statement that have not
* been consumed are deleted. After sqlsrv_cancel has been
* called, the specified statement can be re-executed if it was created with
* sqlsrv_prepare. Calling sqlsrv_cancel
* is not necessary if all the results associated with the statement have been
* consumed.
*
* @param resource $stmt The statement resource to be cancelled.
* @throws SqlsrvException
*
*/
function sqlsrv_cancel($stmt): void
{
error_clear_last();
$safeResult = \sqlsrv_cancel($stmt);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
}
/**
* Returns information about the client and specified connection
*
* @param resource $conn The connection about which information is returned.
* @return array Returns an associative array with keys described in the table below.
*
* Array returned by sqlsrv_client_info
*
*
*
* Key
* Description
*
*
*
*
* DriverDllName
* SQLNCLI10.DLL
*
*
* DriverODBCVer
* ODBC version (xx.yy)
*
*
* DriverVer
* SQL Server Native Client DLL version (10.5.xxx)
*
*
* ExtensionVer
* php_sqlsrv.dll version (2.0.xxx.x)
*
*
*
*
* @throws SqlsrvException
*
*/
function sqlsrv_client_info($conn): array
{
error_clear_last();
$safeResult = \sqlsrv_client_info($conn);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Closes an open connection and releases resourses associated with the connection.
*
* @param resource $conn The connection to be closed.
* @throws SqlsrvException
*
*/
function sqlsrv_close($conn): void
{
error_clear_last();
$safeResult = \sqlsrv_close($conn);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
}
/**
* Commits a transaction that was begun with sqlsrv_begin_transaction.
* The connection is returned to auto-commit mode after sqlsrv_commit
* is called. The transaction that is committed includes all statements that were
* executed after the call to sqlsrv_begin_transaction.
* Explicit transactions should be started and committed or rolled back using these
* functions instead of executing SQL statements that begin and commit/roll back
* transactions. For more information, see
* SQLSRV Transactions.
*
* @param resource $conn The connection on which the transaction is to be committed.
* @throws SqlsrvException
*
*/
function sqlsrv_commit($conn): void
{
error_clear_last();
$safeResult = \sqlsrv_commit($conn);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
}
/**
* Changes the driver error handling and logging configurations.
*
* @param string $setting The name of the setting to set. The possible values are
* "WarningsReturnAsErrors", "LogSubsystems", and "LogSeverity".
* @param mixed $value The value of the specified setting. The following table shows possible values:
*
* Error and Logging Setting Options
*
*
*
* Setting
* Options
*
*
*
*
* WarningsReturnAsErrors
* 1 (TRUE) or 0 (FALSE)
*
*
* LogSubsystems
* SQLSRV_LOG_SYSTEM_ALL (-1)
* SQLSRV_LOG_SYSTEM_CONN (2)
* SQLSRV_LOG_SYSTEM_INIT (1)
* SQLSRV_LOG_SYSTEM_OFF (0)
* SQLSRV_LOG_SYSTEM_STMT (4)
* SQLSRV_LOG_SYSTEM_UTIL (8)
*
*
* LogSeverity
* SQLSRV_LOG_SEVERITY_ALL (-1)
* SQLSRV_LOG_SEVERITY_ERROR (1)
* SQLSRV_LOG_SEVERITY_NOTICE (4)
* SQLSRV_LOG_SEVERITY_WARNING (2)
*
*
*
*
* @throws SqlsrvException
*
*/
function sqlsrv_configure(string $setting, $value): void
{
error_clear_last();
$safeResult = \sqlsrv_configure($setting, $value);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
}
/**
* Executes a statement prepared with sqlsrv_prepare. This
* function is ideal for executing a prepared statement multiple times with
* different parameter values.
*
* @param resource $stmt A statement resource returned by sqlsrv_prepare.
* @throws SqlsrvException
*
*/
function sqlsrv_execute($stmt): void
{
error_clear_last();
$safeResult = \sqlsrv_execute($stmt);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
}
/**
* Returns the next available row of data as an associative array, a numeric
* array, or both (the default).
*
* @param resource $stmt A statement resource returned by sqlsrv_query or sqlsrv_prepare.
* @param int $fetchType A predefined constant specifying the type of array to return. Possible
* values are SQLSRV_FETCH_ASSOC,
* SQLSRV_FETCH_NUMERIC, and
* SQLSRV_FETCH_BOTH (the default).
*
* A fetch type of SQLSRV_FETCH_ASSOC should not be used when consuming a
* result set with multiple columns of the same name.
* @param int $row Specifies the row to access in a result set that uses a scrollable cursor.
* Possible values are SQLSRV_SCROLL_NEXT,
* SQLSRV_SCROLL_PRIOR, SQLSRV_SCROLL_FIRST,
* SQLSRV_SCROLL_LAST, SQLSRV_SCROLL_ABSOLUTE and,
* SQLSRV_SCROLL_RELATIVE (the default). When this parameter
* is specified, the fetchType must be explicitly defined.
* @param int $offset Specifies the row to be accessed if the row parameter is set to
* SQLSRV_SCROLL_ABSOLUTE or
* SQLSRV_SCROLL_RELATIVE. Note that the first row in
* a result set has index 0.
* @return array|null Returns an array on success, NULL if there are no more rows to return, and
* FALSE if an error occurs.
* @throws SqlsrvException
*
*/
function sqlsrv_fetch_array($stmt, ?int $fetchType = null, ?int $row = null, ?int $offset = null): ?array
{
error_clear_last();
if ($offset !== null) {
$safeResult = \sqlsrv_fetch_array($stmt, $fetchType, $row, $offset);
} elseif ($row !== null) {
$safeResult = \sqlsrv_fetch_array($stmt, $fetchType, $row);
} elseif ($fetchType !== null) {
$safeResult = \sqlsrv_fetch_array($stmt, $fetchType);
} else {
$safeResult = \sqlsrv_fetch_array($stmt);
}
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the next row of data in a result set as an instance of the specified
* class with properties that match the row field names and values that correspond
* to the row field values.
*
* @param resource $stmt A statement resource created by sqlsrv_query or
* sqlsrv_execute.
* @param string $className The name of the class to instantiate. If no class name is specified,
* stdClass is instantiated.
* @param array $ctorParams Values passed to the constructor of the specified class. If the constructor
* of the specified class takes parameters, the ctorParams array must be
* supplied.
* @param int $row The row to be accessed. This parameter can only be used if the specified
* statement was prepared with a scrollable cursor. In that case, this parameter
* can take on one of the following values:
*
* SQLSRV_SCROLL_NEXT
* SQLSRV_SCROLL_PRIOR
* SQLSRV_SCROLL_FIRST
* SQLSRV_SCROLL_LAST
* SQLSRV_SCROLL_ABSOLUTE
* SQLSRV_SCROLL_RELATIVE
*
* @param int $offset Specifies the row to be accessed if the row parameter is set to
* SQLSRV_SCROLL_ABSOLUTE or
* SQLSRV_SCROLL_RELATIVE. Note that the first row in
* a result set has index 0.
* @return null|object Returns an object on success, NULL if there are no more rows to return,
* and FALSE if an error occurs or if the specified class does not exist.
* @throws SqlsrvException
*
*/
function sqlsrv_fetch_object($stmt, ?string $className = null, ?array $ctorParams = null, ?int $row = null, ?int $offset = null): ?object
{
error_clear_last();
if ($offset !== null) {
$safeResult = \sqlsrv_fetch_object($stmt, $className, $ctorParams, $row, $offset);
} elseif ($row !== null) {
$safeResult = \sqlsrv_fetch_object($stmt, $className, $ctorParams, $row);
} elseif ($ctorParams !== null) {
$safeResult = \sqlsrv_fetch_object($stmt, $className, $ctorParams);
} elseif ($className !== null) {
$safeResult = \sqlsrv_fetch_object($stmt, $className);
} else {
$safeResult = \sqlsrv_fetch_object($stmt);
}
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Makes the next row in a result set available for reading. Use
* sqlsrv_get_field to read the fields of the row.
*
* @param resource $stmt A statement resource created by executing sqlsrv_query
* or sqlsrv_execute.
* @param int $row The row to be accessed. This parameter can only be used if the specified
* statement was prepared with a scrollable cursor. In that case, this parameter
* can take on one of the following values:
*
* SQLSRV_SCROLL_NEXT
* SQLSRV_SCROLL_PRIOR
* SQLSRV_SCROLL_FIRST
* SQLSRV_SCROLL_LAST
* SQLSRV_SCROLL_ABSOLUTE
* SQLSRV_SCROLL_RELATIVE
*
* @param int $offset Specifies the row to be accessed if the row parameter is set to
* SQLSRV_SCROLL_ABSOLUTE or
* SQLSRV_SCROLL_RELATIVE. Note that the first row in
* a result set has index 0.
* @return bool|null Returns TRUE if the next row of a result set was successfully retrieved,
* FALSE if an error occurs, and NULL if there are no more rows in the result set.
* @throws SqlsrvException
*
*/
function sqlsrv_fetch($stmt, ?int $row = null, ?int $offset = null): ?bool
{
error_clear_last();
if ($offset !== null) {
$safeResult = \sqlsrv_fetch($stmt, $row, $offset);
} elseif ($row !== null) {
$safeResult = \sqlsrv_fetch($stmt, $row);
} else {
$safeResult = \sqlsrv_fetch($stmt);
}
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Frees all resources for the specified statement. The statement cannot be used
* after sqlsrv_free_stmt has been called on it. If
* sqlsrv_free_stmt is called on an in-progress statement
* that alters server state, statement execution is terminated and the statement
* is rolled back.
*
* @param resource $stmt The statement for which resources are freed.
* Note that NULL is a valid parameter value. This allows the function to be
* called multiple times in a script.
* @throws SqlsrvException
*
*/
function sqlsrv_free_stmt($stmt): void
{
error_clear_last();
$safeResult = \sqlsrv_free_stmt($stmt);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
}
/**
* Gets field data from the currently selected row. Fields must be accessed in
* order. Field indices start at 0.
*
* @param resource $stmt A statement resource returned by sqlsrv_query or
* sqlsrv_execute.
* @param int $fieldIndex The index of the field to be retrieved. Field indices start at 0. Fields
* must be accessed in order. i.e. If you access field index 1, then field
* index 0 will not be available.
* @param int $getAsType The PHP data type for the returned field data. If this parameter is not
* set, the field data will be returned as its default PHP data type.
* For information about default PHP data types, see
* Default PHP Data Types
* in the Microsoft SQLSRV documentation.
* @return mixed Returns data from the specified field on success.
* @throws SqlsrvException
*
*/
function sqlsrv_get_field($stmt, int $fieldIndex, ?int $getAsType = null)
{
error_clear_last();
if ($getAsType !== null) {
$safeResult = \sqlsrv_get_field($stmt, $fieldIndex, $getAsType);
} else {
$safeResult = \sqlsrv_get_field($stmt, $fieldIndex);
}
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Makes the next result of the specified statement active. Results include result
* sets, row counts, and output parameters.
*
* @param resource $stmt The statement on which the next result is being called.
* @return bool|null Returns TRUE if the next result was successfully retrieved, FALSE if an error
* occurred, and NULL if there are no more results to retrieve.
* @throws SqlsrvException
*
*/
function sqlsrv_next_result($stmt): ?bool
{
error_clear_last();
$safeResult = \sqlsrv_next_result($stmt);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the number of fields (columns) on a statement.
*
* @param resource $stmt The statement for which the number of fields is returned.
* sqlsrv_num_fields can be called on a statement before
* or after statement execution.
* @return int Returns the number of fields on success.
* @throws SqlsrvException
*
*/
function sqlsrv_num_fields($stmt): int
{
error_clear_last();
$safeResult = \sqlsrv_num_fields($stmt);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Retrieves the number of rows in a result set. This function requires that the
* statement resource be created with a static or keyset cursor. For more information,
* see sqlsrv_query, sqlsrv_prepare,
* or Specifying a Cursor Type and Selecting Rows
* in the Microsoft SQLSRV documentation.
*
* @param resource $stmt The statement for which the row count is returned. The statement resource
* must be created with a static or keyset cursor. For more information, see
* sqlsrv_query, sqlsrv_prepare, or
* Specifying a Cursor Type and Selecting Rows
* in the Microsoft SQLSRV documentation.
* @return int Returns the number of rows retrieved on success.
* If a forward cursor (the default) or dynamic cursor is used, FALSE is returned.
* @throws SqlsrvException
*
*/
function sqlsrv_num_rows($stmt): int
{
error_clear_last();
$safeResult = \sqlsrv_num_rows($stmt);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Prepares a query for execution. This function is ideal for preparing a query
* that will be executed multiple times with different parameter values.
*
* @param resource $conn A connection resource returned by sqlsrv_connect.
* @param string $sql The string that defines the query to be prepared and executed.
* @param array $params An array specifying parameter information when executing a parameterized
* query. Array elements can be any of the following:
*
* A literal value
* A PHP variable
* An array with this structure:
* array($value [, $direction [, $phpType [, $sqlType]]])
*
* The following table describes the elements in the array structure above:
* @param array $options An array specifying query property options. The supported keys are described
* in the following table:
* @return mixed Returns a statement resource on success.
* @throws SqlsrvException
*
*/
function sqlsrv_prepare($conn, string $sql, ?array $params = null, ?array $options = null)
{
error_clear_last();
if ($options !== null) {
$safeResult = \sqlsrv_prepare($conn, $sql, $params, $options);
} elseif ($params !== null) {
$safeResult = \sqlsrv_prepare($conn, $sql, $params);
} else {
$safeResult = \sqlsrv_prepare($conn, $sql);
}
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Prepares and executes a query.
*
* @param resource $conn A connection resource returned by sqlsrv_connect.
* @param string $sql The string that defines the query to be prepared and executed.
* @param array $params An array specifying parameter information when executing a parameterized query.
* Array elements can be any of the following:
*
* A literal value
* A PHP variable
* An array with this structure:
* array($value [, $direction [, $phpType [, $sqlType]]])
*
* The following table describes the elements in the array structure above:
* @param array $options An array specifying query property options. The supported keys are described
* in the following table:
* @return mixed Returns a statement resource on success.
* @throws SqlsrvException
*
*/
function sqlsrv_query($conn, string $sql, ?array $params = null, ?array $options = null)
{
error_clear_last();
if ($options !== null) {
$safeResult = \sqlsrv_query($conn, $sql, $params, $options);
} elseif ($params !== null) {
$safeResult = \sqlsrv_query($conn, $sql, $params);
} else {
$safeResult = \sqlsrv_query($conn, $sql);
}
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
return $safeResult;
}
/**
* Rolls back a transaction that was begun with sqlsrv_begin_transaction
* and returns the connection to auto-commit mode.
*
* @param resource $conn The connection resource returned by a call to sqlsrv_connect.
* @throws SqlsrvException
*
*/
function sqlsrv_rollback($conn): void
{
error_clear_last();
$safeResult = \sqlsrv_rollback($conn);
if ($safeResult === false) {
throw SqlsrvException::createFromPhpError();
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Safe;
use Safe\Exceptions\SsdeepException;
/**
* Calculates the match score between signature1
* and signature2 using
* context-triggered piecewise hashing, and returns the match
* score.
*
* @param string $signature1 The first fuzzy hash signature string.
* @param string $signature2 The second fuzzy hash signature string.
* @return int Returns an integer from 0 to 100 on success.
* @throws SsdeepException
*
*/
function ssdeep_fuzzy_compare(string $signature1, string $signature2): int
{
error_clear_last();
$safeResult = \ssdeep_fuzzy_compare($signature1, $signature2);
if ($safeResult === false) {
throw SsdeepException::createFromPhpError();
}
return $safeResult;
}
/**
* ssdeep_fuzzy_hash_filename calculates the hash
* of the file specified by file_name using
* context-triggered piecewise
* hashing, and returns that hash.
*
* @param string $file_name The filename of the file to hash.
* @return string Returns a string on success.
* @throws SsdeepException
*
*/
function ssdeep_fuzzy_hash_filename(string $file_name): string
{
error_clear_last();
$safeResult = \ssdeep_fuzzy_hash_filename($file_name);
if ($safeResult === false) {
throw SsdeepException::createFromPhpError();
}
return $safeResult;
}
/**
* ssdeep_fuzzy_hash calculates the hash of
* to_hash using
* context-triggered piecewise hashing, and returns that hash.
*
* @param string $to_hash The input string.
* @return string Returns a string on success.
* @throws SsdeepException
*
*/
function ssdeep_fuzzy_hash(string $to_hash): string
{
error_clear_last();
$safeResult = \ssdeep_fuzzy_hash($to_hash);
if ($safeResult === false) {
throw SsdeepException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,749 @@
<?php
namespace Safe;
use Safe\Exceptions\Ssh2Exception;
/**
* Authenticate over SSH using the ssh agent
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @param string $username Remote user name.
* @throws Ssh2Exception
*
*/
function ssh2_auth_agent($session, string $username): void
{
error_clear_last();
$safeResult = \ssh2_auth_agent($session, $username);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Authenticate using a public hostkey read from a file.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @param string $username
* @param string $hostname
* @param string $pubkeyfile
* @param string $privkeyfile
* @param string $passphrase If privkeyfile is encrypted (which it should
* be), the passphrase must be provided.
* @param string $local_username If local_username is omitted, then the value
* for username will be used for it.
* @throws Ssh2Exception
*
*/
function ssh2_auth_hostbased_file($session, string $username, string $hostname, string $pubkeyfile, string $privkeyfile, ?string $passphrase = null, ?string $local_username = null): void
{
error_clear_last();
if ($local_username !== null) {
$safeResult = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile, $passphrase, $local_username);
} elseif ($passphrase !== null) {
$safeResult = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile, $passphrase);
} else {
$safeResult = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile);
}
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Authenticate over SSH using a plain password. Since version 0.12 this function
* also supports keyboard_interactive method.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @param string $username Remote user name.
* @param string $password Password for username
* @throws Ssh2Exception
*
*/
function ssh2_auth_password($session, string $username, string $password): void
{
error_clear_last();
$safeResult = \ssh2_auth_password($session, $username, $password);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Authenticate using a public key read from a file.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @param string $username
* @param string $pubkeyfile The public key file needs to be in OpenSSH's format. It should look something like:
*
* ssh-rsa AAAAB3NzaC1yc2EAAA....NX6sqSnHA8= rsa-key-20121110
* @param string $privkeyfile
* @param string $passphrase If privkeyfile is encrypted (which it should
* be), the passphrase must be provided.
* @throws Ssh2Exception
*
*/
function ssh2_auth_pubkey_file($session, string $username, string $pubkeyfile, string $privkeyfile, ?string $passphrase = null): void
{
error_clear_last();
if ($passphrase !== null) {
$safeResult = \ssh2_auth_pubkey_file($session, $username, $pubkeyfile, $privkeyfile, $passphrase);
} else {
$safeResult = \ssh2_auth_pubkey_file($session, $username, $pubkeyfile, $privkeyfile);
}
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Establish a connection to a remote SSH server.
*
* Once connected, the client should verify the server's hostkey using
* ssh2_fingerprint, then authenticate using either
* password or public key.
*
* @param string $host
* @param int $port
* @param array $methods methods may be an associative array with up to four parameters
* as described below.
*
*
* methods may be an associative array
* with any or all of the following parameters.
*
*
*
* Index
* Meaning
* Supported Values*
*
*
*
*
* kex
*
* List of key exchange methods to advertise, comma separated
* in order of preference.
*
*
* diffie-hellman-group1-sha1,
* diffie-hellman-group14-sha1, and
* diffie-hellman-group-exchange-sha1
*
*
*
* hostkey
*
* List of hostkey methods to advertise, comma separated
* in order of preference.
*
*
* ssh-rsa and
* ssh-dss
*
*
*
* client_to_server
*
* Associative array containing crypt, compression, and
* message authentication code (MAC) method preferences
* for messages sent from client to server.
*
*
*
*
* server_to_client
*
* Associative array containing crypt, compression, and
* message authentication code (MAC) method preferences
* for messages sent from server to client.
*
*
*
*
*
*
*
* * - Supported Values are dependent on methods supported by underlying library.
* See libssh2 documentation for additional
* information.
*
*
*
* client_to_server and
* server_to_client may be an associative array
* with any or all of the following parameters.
*
*
*
*
* Index
* Meaning
* Supported Values*
*
*
*
*
* crypt
* List of crypto methods to advertise, comma separated
* in order of preference.
*
* rijndael-cbc@lysator.liu.se,
* aes256-cbc,
* aes192-cbc,
* aes128-cbc,
* 3des-cbc,
* blowfish-cbc,
* cast128-cbc,
* arcfour, and
* none**
*
*
*
* comp
* List of compression methods to advertise, comma separated
* in order of preference.
*
* zlib and
* none
*
*
*
* mac
* List of MAC methods to advertise, comma separated
* in order of preference.
*
* hmac-sha1,
* hmac-sha1-96,
* hmac-ripemd160,
* hmac-ripemd160@openssh.com, and
* none**
*
*
*
*
*
*
*
* Crypt and MAC method "none"
*
* For security reasons, none is disabled by the underlying
* libssh2 library unless explicitly enabled
* during build time by using the appropriate ./configure options. See documentation
* for the underlying library for more information.
*
*
*
* For security reasons, none is disabled by the underlying
* libssh2 library unless explicitly enabled
* during build time by using the appropriate ./configure options. See documentation
* for the underlying library for more information.
* @param array $callbacks callbacks may be an associative array with any
* or all of the following parameters.
*
*
* Callbacks parameters
*
*
*
*
* Index
* Meaning
* Prototype
*
*
*
*
* ignore
*
* Name of function to call when an
* SSH2_MSG_IGNORE packet is received
*
* void ignore_cb($message)
*
*
* debug
*
* Name of function to call when an
* SSH2_MSG_DEBUG packet is received
*
* void debug_cb($message, $language, $always_display)
*
*
* macerror
*
* Name of function to call when a packet is received but the
* message authentication code failed. If the callback returns
* TRUE, the mismatch will be ignored, otherwise the connection
* will be terminated.
*
* bool macerror_cb($packet)
*
*
* disconnect
*
* Name of function to call when an
* SSH2_MSG_DISCONNECT packet is received
*
* void disconnect_cb($reason, $message, $language)
*
*
*
*
* @return resource Returns a resource on success.
* @throws Ssh2Exception
*
*/
function ssh2_connect(string $host, int $port = 22, ?array $methods = null, ?array $callbacks = null)
{
error_clear_last();
if ($callbacks !== null) {
$safeResult = \ssh2_connect($host, $port, $methods, $callbacks);
} elseif ($methods !== null) {
$safeResult = \ssh2_connect($host, $port, $methods);
} else {
$safeResult = \ssh2_connect($host, $port);
}
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
return $safeResult;
}
/**
* Close a connection to a remote SSH server.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @throws Ssh2Exception
*
*/
function ssh2_disconnect($session): void
{
error_clear_last();
$safeResult = \ssh2_disconnect($session);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Execute a command at the remote end and allocate a channel for it.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @param string $command
* @param string $pty
* @param array $env env may be passed as an associative array of
* name/value pairs to set in the target environment.
* @param int $width Width of the virtual terminal.
* @param int $height Height of the virtual terminal.
* @param int $width_height_type width_height_type should be one of
* SSH2_TERM_UNIT_CHARS or
* SSH2_TERM_UNIT_PIXELS.
* @return resource Returns a stream on success.
* @throws Ssh2Exception
*
*/
function ssh2_exec($session, string $command, ?string $pty = null, ?array $env = null, int $width = 80, int $height = 25, int $width_height_type = SSH2_TERM_UNIT_CHARS)
{
error_clear_last();
if ($width_height_type !== SSH2_TERM_UNIT_CHARS) {
$safeResult = \ssh2_exec($session, $command, $pty, $env, $width, $height, $width_height_type);
} elseif ($height !== 25) {
$safeResult = \ssh2_exec($session, $command, $pty, $env, $width, $height);
} elseif ($width !== 80) {
$safeResult = \ssh2_exec($session, $command, $pty, $env, $width);
} elseif ($env !== null) {
$safeResult = \ssh2_exec($session, $command, $pty, $env);
} elseif ($pty !== null) {
$safeResult = \ssh2_exec($session, $command, $pty);
} else {
$safeResult = \ssh2_exec($session, $command);
}
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
return $safeResult;
}
/**
* Accepts a connection created by a listener.
*
* @param resource $listener An SSH2 Listener resource, obtained from a call to ssh2_forward_listen.
* @return resource Returns a stream resource.
* @throws Ssh2Exception
*
*/
function ssh2_forward_accept($listener)
{
error_clear_last();
$safeResult = \ssh2_forward_accept($listener);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
return $safeResult;
}
/**
* Binds a port on the remote server and listen for connections.
*
* @param resource $session An SSH Session resource, obtained from a call to ssh2_connect.
* @param int $port The port of the remote server.
* @param string $host
* @param int $max_connections
* @return resource Returns an SSH2 Listener.
* @throws Ssh2Exception
*
*/
function ssh2_forward_listen($session, int $port, ?string $host = null, int $max_connections = 16)
{
error_clear_last();
if ($max_connections !== 16) {
$safeResult = \ssh2_forward_listen($session, $port, $host, $max_connections);
} elseif ($host !== null) {
$safeResult = \ssh2_forward_listen($session, $port, $host);
} else {
$safeResult = \ssh2_forward_listen($session, $port);
}
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param resource $pkey Publickey Subsystem resource created by ssh2_publickey_init.
* @param string $algoname Publickey algorithm (e.g.): ssh-dss, ssh-rsa
* @param string $blob Publickey blob as raw binary data
* @param bool $overwrite If the specified key already exists, should it be overwritten?
* @param array $attributes Associative array of attributes to assign to this public key.
* Refer to ietf-secsh-publickey-subsystem for a list of supported attributes.
* To mark an attribute as mandatory, precede its name with an asterisk.
* If the server is unable to support an attribute marked mandatory,
* it will abort the add process.
* @throws Ssh2Exception
*
*/
function ssh2_publickey_add($pkey, string $algoname, string $blob, bool $overwrite = false, ?array $attributes = null): void
{
error_clear_last();
if ($attributes !== null) {
$safeResult = \ssh2_publickey_add($pkey, $algoname, $blob, $overwrite, $attributes);
} else {
$safeResult = \ssh2_publickey_add($pkey, $algoname, $blob, $overwrite);
}
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Request the Publickey subsystem from an already connected SSH2 server.
*
* The publickey subsystem allows an already connected and authenticated
* client to manage the list of authorized public keys stored on the
* target server in an implementation agnostic manner.
* If the remote server does not support the publickey subsystem,
* the ssh2_publickey_init function will return FALSE.
*
* @param resource $session
* @return resource Returns an SSH2 Publickey Subsystem resource for use
* with all other ssh2_publickey_*() methods.
* @throws Ssh2Exception
*
*/
function ssh2_publickey_init($session)
{
error_clear_last();
$safeResult = \ssh2_publickey_init($session);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
return $safeResult;
}
/**
* Removes an authorized publickey.
*
* @param resource $pkey Publickey Subsystem Resource
* @param string $algoname Publickey algorithm (e.g.): ssh-dss, ssh-rsa
* @param string $blob Publickey blob as raw binary data
* @throws Ssh2Exception
*
*/
function ssh2_publickey_remove($pkey, string $algoname, string $blob): void
{
error_clear_last();
$safeResult = \ssh2_publickey_remove($pkey, $algoname, $blob);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Copy a file from the remote server to the local filesystem using the SCP protocol.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @param string $remote_file Path to the remote file.
* @param string $local_file Path to the local file.
* @throws Ssh2Exception
*
*/
function ssh2_scp_recv($session, string $remote_file, string $local_file): void
{
error_clear_last();
$safeResult = \ssh2_scp_recv($session, $remote_file, $local_file);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Copy a file from the local filesystem to the remote server using the SCP protocol.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @param string $local_file Path to the local file.
* @param string $remote_file Path to the remote file.
* @param int $create_mode The file will be created with the mode specified by
* create_mode.
* @throws Ssh2Exception
*
*/
function ssh2_scp_send($session, string $local_file, string $remote_file, int $create_mode = 0644): void
{
error_clear_last();
$safeResult = \ssh2_scp_send($session, $local_file, $remote_file, $create_mode);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Sends an EOF to the stream; this is typically used to close standard input,
* while keeping output and error alive. For example, one can send a remote
* process some data over standard input, close it to start processing, and
* still be able to read out the results without creating additional files.
*
* @param resource $channel An SSH stream; can be acquired through functions like ssh2_fetch_stream
* or ssh2_connect.
* @throws Ssh2Exception
*
*/
function ssh2_send_eof($channel): void
{
error_clear_last();
$safeResult = \ssh2_send_eof($channel);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Attempts to change the mode of the specified file to that given in
* mode.
*
* @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
* @param string $filename Path to the file.
* @param int $mode Permissions on the file. See the chmod for more details on this parameter.
* @throws Ssh2Exception
*
*/
function ssh2_sftp_chmod($sftp, string $filename, int $mode): void
{
error_clear_last();
$safeResult = \ssh2_sftp_chmod($sftp, $filename, $mode);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Creates a directory on the remote file server with permissions set to
* mode.
*
* This function is similar to using mkdir with the
* ssh2.sftp:// wrapper.
*
* @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
* @param string $dirname Path of the new directory.
* @param int $mode Permissions on the new directory.
* The actual mode is affected by the current umask.
* @param bool $recursive If recursive is TRUE any parent directories
* required for dirname will be automatically created as well.
* @throws Ssh2Exception
*
*/
function ssh2_sftp_mkdir($sftp, string $dirname, int $mode = 0777, bool $recursive = false): void
{
error_clear_last();
$safeResult = \ssh2_sftp_mkdir($sftp, $dirname, $mode, $recursive);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Renames a file on the remote filesystem.
*
* @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
* @param string $from The current file that is being renamed.
* @param string $to The new file name that replaces from.
* @throws Ssh2Exception
*
*/
function ssh2_sftp_rename($sftp, string $from, string $to): void
{
error_clear_last();
$safeResult = \ssh2_sftp_rename($sftp, $from, $to);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Removes a directory from the remote file server.
*
* This function is similar to using rmdir with the
* ssh2.sftp:// wrapper.
*
* @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
* @param string $dirname
* @throws Ssh2Exception
*
*/
function ssh2_sftp_rmdir($sftp, string $dirname): void
{
error_clear_last();
$safeResult = \ssh2_sftp_rmdir($sftp, $dirname);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Creates a symbolic link named link on the remote
* filesystem pointing to target.
*
* @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
* @param string $target Target of the symbolic link.
* @param string $link
* @throws Ssh2Exception
*
*/
function ssh2_sftp_symlink($sftp, string $target, string $link): void
{
error_clear_last();
$safeResult = \ssh2_sftp_symlink($sftp, $target, $link);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Deletes a file on the remote filesystem.
*
* @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
* @param string $filename
* @throws Ssh2Exception
*
*/
function ssh2_sftp_unlink($sftp, string $filename): void
{
error_clear_last();
$safeResult = \ssh2_sftp_unlink($sftp, $filename);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
}
/**
* Request the SFTP subsystem from an already connected SSH2 server.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @return resource This method returns an SSH2 SFTP resource for use with
* all other ssh2_sftp_*() methods and the
* ssh2.sftp:// fopen wrapper.
* @throws Ssh2Exception
*
*/
function ssh2_sftp($session)
{
error_clear_last();
$safeResult = \ssh2_sftp($session);
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
return $safeResult;
}
/**
* Open a shell at the remote end and allocate a stream for it.
*
* @param resource $session An SSH connection link identifier, obtained from a call to
* ssh2_connect.
* @param string $termtype termtype should correspond to one of the
* entries in the target system's /etc/termcap file.
* @param array|null $env env may be passed as an associative array of
* name/value pairs to set in the target environment.
* @param int $width Width of the virtual terminal.
* @param int $height Height of the virtual terminal.
* @param int $width_height_type width_height_type should be one of
* SSH2_TERM_UNIT_CHARS or
* SSH2_TERM_UNIT_PIXELS.
* @return resource Returns a stream resource on success.
* @throws Ssh2Exception
*
*/
function ssh2_shell($session, string $termtype = "vanilla", ?array $env = null, int $width = 80, int $height = 25, int $width_height_type = SSH2_TERM_UNIT_CHARS)
{
error_clear_last();
if ($width_height_type !== SSH2_TERM_UNIT_CHARS) {
$safeResult = \ssh2_shell($session, $termtype, $env, $width, $height, $width_height_type);
} elseif ($height !== 25) {
$safeResult = \ssh2_shell($session, $termtype, $env, $width, $height);
} elseif ($width !== 80) {
$safeResult = \ssh2_shell($session, $termtype, $env, $width);
} elseif ($env !== null) {
$safeResult = \ssh2_shell($session, $termtype, $env);
} else {
$safeResult = \ssh2_shell($session, $termtype);
}
if ($safeResult === false) {
throw Ssh2Exception::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,790 @@
<?php
namespace Safe;
use Safe\Exceptions\StreamException;
/**
* Sets options on the specified context.
*
* @param resource $context The stream or context resource to apply the options to.
* @param array $options The options to set for context.
*
* options must be an associative
* array of associative arrays in the format
* $array['wrapper']['option'] = $value.
*
* Refer to context options and parameters
* for a listing of stream options.
* @return true Returns TRUE on success.
* @throws StreamException
*
*/
function stream_context_set_options($context, array $options): void
{
error_clear_last();
$safeResult = \stream_context_set_options($context, $options);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Sets parameters on the specified context.
*
* @param resource $context The stream or context to apply the parameters too.
* @param array $params An associative array of parameters to be set in the following format:
* $params['paramname'] = "paramvalue";.
* @throws StreamException
*
*/
function stream_context_set_params($context, array $params): void
{
error_clear_last();
$safeResult = \stream_context_set_params($context, $params);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Makes a copy of up to length bytes
* of data from the current position (or from the
* offset position, if specified) in
* from to to. If
* length is NULL, all remaining content in
* from will be copied.
*
* @param resource $from The source stream
* @param resource $to The destination stream
* @param int|null $length Maximum bytes to copy. By default all bytes left are copied.
* @param int $offset The offset where to start to copy data
* @return int Returns the total count of bytes copied.
* @throws StreamException
*
*/
function stream_copy_to_stream($from, $to, ?int $length = null, int $offset = 0): int
{
error_clear_last();
if ($offset !== 0) {
$safeResult = \stream_copy_to_stream($from, $to, $length, $offset);
} elseif ($length !== null) {
$safeResult = \stream_copy_to_stream($from, $to, $length);
} else {
$safeResult = \stream_copy_to_stream($from, $to);
}
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Adds filtername to the list of filters
* attached to stream.
*
* @param resource $stream The target stream.
* @param string $filtername The filter name.
* @param int $read_write By default, stream_filter_append will
* attach the filter to the read filter chain
* if the file was opened for reading (i.e. File Mode:
* r, and/or +). The filter
* will also be attached to the write filter chain
* if the file was opened for writing (i.e. File Mode:
* w, a, and/or +).
* STREAM_FILTER_READ,
* STREAM_FILTER_WRITE, and/or
* STREAM_FILTER_ALL can also be passed to the
* read_write parameter to override this behavior.
* @param mixed $params This filter will be added with the specified
* params to the end of
* the list and will therefore be called last during stream operations.
* To add a filter to the beginning of the list, use
* stream_filter_prepend.
* @return resource Returns a resource on success. The resource can be
* used to refer to this filter instance during a call to
* stream_filter_remove.
*
* FALSE is returned if stream is not a resource or
* if filtername cannot be located.
* @throws StreamException
*
*/
function stream_filter_append($stream, string $filtername, ?int $read_write = null, $params = null)
{
error_clear_last();
if ($params !== null) {
$safeResult = \stream_filter_append($stream, $filtername, $read_write, $params);
} elseif ($read_write !== null) {
$safeResult = \stream_filter_append($stream, $filtername, $read_write);
} else {
$safeResult = \stream_filter_append($stream, $filtername);
}
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Adds filtername to the list of filters
* attached to stream.
*
* @param resource $stream The target stream.
* @param string $filtername The filter name.
* @param int $read_write By default, stream_filter_prepend will
* attach the filter to the read filter chain
* if the file was opened for reading (i.e. File Mode:
* r, and/or +). The filter
* will also be attached to the write filter chain
* if the file was opened for writing (i.e. File Mode:
* w, a, and/or +).
* STREAM_FILTER_READ,
* STREAM_FILTER_WRITE, and/or
* STREAM_FILTER_ALL can also be passed to the
* read_write parameter to override this behavior.
* See stream_filter_append for an example of
* using this parameter.
* @param mixed $params This filter will be added with the specified params
* to the beginning of the list and will therefore be
* called first during stream operations. To add a filter to the end of the
* list, use stream_filter_append.
* @return resource Returns a resource on success. The resource can be
* used to refer to this filter instance during a call to
* stream_filter_remove.
*
* FALSE is returned if stream is not a resource or
* if filtername cannot be located.
* @throws StreamException
*
*/
function stream_filter_prepend($stream, string $filtername, ?int $read_write = null, $params = null)
{
error_clear_last();
if ($params !== null) {
$safeResult = \stream_filter_prepend($stream, $filtername, $read_write, $params);
} elseif ($read_write !== null) {
$safeResult = \stream_filter_prepend($stream, $filtername, $read_write);
} else {
$safeResult = \stream_filter_prepend($stream, $filtername);
}
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* stream_filter_register allows you to implement
* your own filter on any registered stream used with all the other
* filesystem functions (such as fopen,
* fread etc.).
*
* @param string $filter_name The filter name to be registered.
* @param string $class To implement a filter, you need to define a class as an extension of
* php_user_filter with a number of member
* functions. When performing read/write operations on the stream
* to which your filter is attached, PHP will pass the data through your
* filter (and any other filters attached to that stream) so that the
* data may be modified as desired. You must implement the methods
* exactly as described in php_user_filter - doing
* otherwise will lead to undefined behaviour.
* @throws StreamException
*
*/
function stream_filter_register(string $filter_name, string $class): void
{
error_clear_last();
$safeResult = \stream_filter_register($filter_name, $class);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Removes a stream filter previously added to a stream with
* stream_filter_prepend or
* stream_filter_append. Any data remaining in the
* filter's internal buffer will be flushed through to the next filter before
* removing it.
*
* @param resource $stream_filter The stream filter to be removed.
* @throws StreamException
*
*/
function stream_filter_remove($stream_filter): void
{
error_clear_last();
$safeResult = \stream_filter_remove($stream_filter);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Identical to file_get_contents, except that
* stream_get_contents operates on an already open
* stream resource and returns the remaining contents in a string, up to
* length bytes and starting at the specified
* offset.
*
* @param resource $stream A stream resource (e.g. returned from fopen)
* @param int|null $length The maximum bytes to read. Defaults to NULL (read all the remaining
* buffer).
* @param int $offset Seek to the specified offset before reading. If this number is negative,
* no seeking will occur and reading will start from the current position.
* @return string Returns a string.
* @throws StreamException
*
*/
function stream_get_contents($stream, ?int $length = null, int $offset = -1): string
{
error_clear_last();
if ($offset !== -1) {
$safeResult = \stream_get_contents($stream, $length, $offset);
} elseif ($length !== null) {
$safeResult = \stream_get_contents($stream, $length);
} else {
$safeResult = \stream_get_contents($stream);
}
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Gets a line from the given handle.
*
* Reading ends when length bytes have been read, when
* the non-empty string specified by ending is found (which is
* not included in the return value), or on EOF
* (whichever comes first).
*
* This function is nearly identical to fgets except in
* that it allows end of line delimiters other than the standard \n, \r, and
* \r\n, and does not return the delimiter itself.
*
* @param resource $stream A valid file handle.
* @param int $length The maximum number of bytes to read from the handle.
* Negative values are not supported.
* Zero (0) means the default socket chunk size,
* i.e. 8192 bytes.
* @param string $ending An optional string delimiter.
* @return string Returns a string of up to length bytes read from the file
* pointed to by stream.
* @throws StreamException
*
*/
function stream_get_line($stream, int $length, string $ending = ""): string
{
error_clear_last();
$safeResult = \stream_get_line($stream, $length, $ending);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Determines if stream stream refers to a valid terminal type device.
* This is a more portable version of posix_isatty, since it works on Windows systems too.
*
* @param resource $stream
* @throws StreamException
*
*/
function stream_isatty($stream): void
{
error_clear_last();
$safeResult = \stream_isatty($stream);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Resolve filename against the include path according to the same rules as fopen/include.
*
* @param string $filename The filename to resolve.
* @return string Returns a string containing the resolved absolute filename.
* @throws StreamException
*
*/
function stream_resolve_include_path(string $filename): string
{
error_clear_last();
$safeResult = \stream_resolve_include_path($filename);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Sets blocking or non-blocking mode on a stream.
*
* This function works for any stream that supports non-blocking mode
* (currently, regular files and socket streams).
*
* @param resource $stream The stream.
* @param bool $enable If enable is FALSE, the given stream
* will be switched to non-blocking mode, and if TRUE, it
* will be switched to blocking mode. This affects calls like
* fgets and fread
* that read from the stream. In non-blocking mode an
* fgets call will always return right away
* while in blocking mode it will wait for data to become available
* on the stream.
* @throws StreamException
*
*/
function stream_set_blocking($stream, bool $enable): void
{
error_clear_last();
$safeResult = \stream_set_blocking($stream, $enable);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Sets the timeout value on stream,
* expressed in the sum of seconds and
* microseconds.
*
* When the stream times out, the 'timed_out' key of the array returned by
* stream_get_meta_data is set to TRUE, although no
* error/warning is generated.
*
* @param resource $stream The target stream.
* @param int $seconds The seconds part of the timeout to be set.
* @param int $microseconds The microseconds part of the timeout to be set.
* @throws StreamException
*
*/
function stream_set_timeout($stream, int $seconds, int $microseconds = 0): void
{
error_clear_last();
$safeResult = \stream_set_timeout($stream, $seconds, $microseconds);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Accept a connection on a socket previously created by
* stream_socket_server.
*
* @param resource $socket The server socket to accept a connection from.
* @param float|null $timeout Override the default socket accept timeout. Time should be given in
* seconds. By default, default_socket_timeout
* is used.
* @param null|string $peer_name Will be set to the name (address) of the client which connected, if
* included and available from the selected transport.
*
* Can also be determined later using
* stream_socket_get_name.
* @return resource Returns a stream to the accepted socket connection.
* @throws StreamException
*
*/
function stream_socket_accept($socket, ?float $timeout = null, ?string &$peer_name = null)
{
error_clear_last();
if ($peer_name !== null) {
$safeResult = \stream_socket_accept($socket, $timeout, $peer_name);
} elseif ($timeout !== null) {
$safeResult = \stream_socket_accept($socket, $timeout);
} else {
$safeResult = \stream_socket_accept($socket);
}
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Initiates a stream or datagram connection to the destination specified
* by address. The type of socket created
* is determined by the transport specified using standard URL formatting:
* transport://target. For Internet Domain sockets
* (AF_INET) such as TCP and UDP, the target portion
* of the address parameter should consist of
* a hostname or IP address followed by a colon and a port number. For Unix
* domain sockets, the target portion should point
* to the socket file on the filesystem.
*
* @param string $address Address to the socket to connect to.
* @param int|null $error_code Will be set to the system level error number if connection fails.
* @param null|string $error_message Will be set to the system level error message if the connection fails.
* @param float|null $timeout Number of seconds until the connect() system call
* should timeout. By default, default_socket_timeout
* is used.
*
*
* This parameter only applies when not making asynchronous
* connection attempts.
*
*
*
*
* To set a timeout for reading/writing data over the socket, use the
* stream_set_timeout, as the
* timeout only applies while making connecting
* the socket.
*
*
*
* To set a timeout for reading/writing data over the socket, use the
* stream_set_timeout, as the
* timeout only applies while making connecting
* the socket.
* @param int-mask $flags Bitmask field which may be set to any combination of connection flags.
* Currently the select of connection flags is limited to
* STREAM_CLIENT_CONNECT (default),
* STREAM_CLIENT_ASYNC_CONNECT and
* STREAM_CLIENT_PERSISTENT.
* @param null|resource $context A valid context resource created with stream_context_create.
* @return resource On success a stream resource is returned which may
* be used together with the other file functions (such as
* fgets, fgetss,
* fwrite, fclose, and
* feof).
* @throws StreamException
*
*/
function stream_socket_client(string $address, ?int &$error_code = null, ?string &$error_message = null, ?float $timeout = null, int $flags = STREAM_CLIENT_CONNECT, $context = null)
{
error_clear_last();
if ($context !== null) {
$safeResult = \stream_socket_client($address, $error_code, $error_message, $timeout, $flags, $context);
} elseif ($flags !== STREAM_CLIENT_CONNECT) {
$safeResult = \stream_socket_client($address, $error_code, $error_message, $timeout, $flags);
} elseif ($timeout !== null) {
$safeResult = \stream_socket_client($address, $error_code, $error_message, $timeout);
} else {
$safeResult = \stream_socket_client($address, $error_code, $error_message);
}
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the local or remote name of a given socket connection.
*
* @param resource $socket The socket to get the name of.
* @param bool $remote If set to TRUE the remote socket name will be returned, if set
* to FALSE the local socket name will be returned.
* @return string The name of the socket.
* @throws StreamException
*
*/
function stream_socket_get_name($socket, bool $remote): string
{
error_clear_last();
$safeResult = \stream_socket_get_name($socket, $remote);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* stream_socket_pair creates a pair of connected,
* indistinguishable socket streams. This function is commonly used in IPC
* (Inter-Process Communication).
*
* @param int $domain The protocol family to be used: STREAM_PF_INET,
* STREAM_PF_INET6 or
* STREAM_PF_UNIX
* @param int $type The type of communication to be used:
* STREAM_SOCK_DGRAM,
* STREAM_SOCK_RAW,
* STREAM_SOCK_RDM,
* STREAM_SOCK_SEQPACKET or
* STREAM_SOCK_STREAM
* @param int $protocol The protocol to be used: STREAM_IPPROTO_ICMP,
* STREAM_IPPROTO_IP,
* STREAM_IPPROTO_RAW,
* STREAM_IPPROTO_TCP or
* STREAM_IPPROTO_UDP
* @return resource[] Returns an array with the two socket resources on success.
* @throws StreamException
*
*/
function stream_socket_pair(int $domain, int $type, int $protocol): array
{
error_clear_last();
$safeResult = \stream_socket_pair($domain, $type, $protocol);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* stream_socket_recvfrom accepts
* data from a remote socket up to length bytes.
*
* @param resource $socket The remote socket.
* @param int $length The number of bytes to receive from the socket.
* @param int $flags The value of flags can be any combination
* of the following:
*
* Possible values for flags
*
*
*
* STREAM_OOB
*
* Process OOB (out-of-band) data.
*
*
*
* STREAM_PEEK
*
* Retrieve data from the socket, but do not consume the buffer.
* Subsequent calls to fread or
* stream_socket_recvfrom will see
* the same data.
*
*
*
*
*
* @param null|string $address If address is provided it will be populated with
* the address of the remote socket.
* @return string Returns the read data, as a string.
* @throws StreamException
*
*/
function stream_socket_recvfrom($socket, int $length, int $flags = 0, ?string &$address = null): string
{
error_clear_last();
$safeResult = \stream_socket_recvfrom($socket, $length, $flags, $address);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Sends the specified data through the
* socket.
*
* @param resource $socket The socket to send data to.
* @param string $data The data to be sent.
* @param int $flags The value of flags can be any combination
* of the following:
*
* possible values for flags
*
*
*
* STREAM_OOB
*
* Process OOB (out-of-band) data.
*
*
*
*
*
* @param string $address The address specified when the socket stream was created will be used
* unless an alternate address is specified in address.
*
* If specified, it must be in dotted quad (or [ipv6]) format.
* @return int Returns a result code, as an integer.
* @throws StreamException
*
*/
function stream_socket_sendto($socket, string $data, int $flags = 0, string $address = ""): int
{
error_clear_last();
$safeResult = \stream_socket_sendto($socket, $data, $flags, $address);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Creates a stream or datagram socket on the specified
* address.
*
* This function only creates a socket, to begin accepting connections
* use stream_socket_accept.
*
* @param string $address The type of socket created is determined by the transport specified
* using standard URL formatting: transport://target.
*
* For Internet Domain sockets (AF_INET) such as TCP and UDP, the
* target portion of the
* remote_socket parameter should consist of a
* hostname or IP address followed by a colon and a port number. For
* Unix domain sockets, the target portion should
* point to the socket file on the filesystem.
*
* Depending on the environment, Unix domain sockets may not be available.
* A list of available transports can be retrieved using
* stream_get_transports. See
* for a list of bulitin transports.
* @param int|null $error_code If the optional error_code and error_message
* arguments are present they will be set to indicate the actual system
* level error that occurred in the system-level socket(),
* bind(), and listen() calls. If
* the value returned in error_code is
* 0 and the function returned FALSE, it is an
* indication that the error occurred before the bind()
* call. This is most likely due to a problem initializing the socket.
* Note that the error_code and
* error_message arguments will always be passed by reference.
* @param null|string $error_message See error_code description.
* @param int $flags A bitmask field which may be set to any combination of socket creation
* flags.
*
* For UDP sockets, you must use STREAM_SERVER_BIND as
* the flags parameter.
* @param null|resource $context
* @return resource Returns the created stream.
* @throws StreamException
*
*/
function stream_socket_server(string $address, ?int &$error_code = null, ?string &$error_message = null, int $flags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context = null)
{
error_clear_last();
if ($context !== null) {
$safeResult = \stream_socket_server($address, $error_code, $error_message, $flags, $context);
} else {
$safeResult = \stream_socket_server($address, $error_code, $error_message, $flags);
}
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}
/**
* Shutdowns (partially or not) a full-duplex connection.
*
* @param resource $stream An open stream (opened with stream_socket_client,
* for example)
* @param int $mode One of the following constants: STREAM_SHUT_RD
* (disable further receptions), STREAM_SHUT_WR
* (disable further transmissions) or
* STREAM_SHUT_RDWR (disable further receptions and
* transmissions).
* @throws StreamException
*
*/
function stream_socket_shutdown($stream, int $mode): void
{
error_clear_last();
$safeResult = \stream_socket_shutdown($stream, $mode);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Tells whether the stream supports locking through
* flock.
*
* @param resource $stream The stream to check.
* @throws StreamException
*
*/
function stream_supports_lock($stream): void
{
error_clear_last();
$safeResult = \stream_supports_lock($stream);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Allows you to implement your own protocol handlers and streams for use
* with all the other filesystem functions (such as fopen,
* fread etc.).
*
* @param string $protocol The wrapper name to be registered.
* Valid protocol names must contain alphanumerics, dots (.), plusses (+), or hyphens (-) only.
* @param string $class The classname which implements the protocol.
* @param int $flags Should be set to STREAM_IS_URL if
* protocol is a URL protocol. Default is 0, local
* stream.
* @throws StreamException
*
*/
function stream_wrapper_register(string $protocol, string $class, int $flags = 0): void
{
error_clear_last();
$safeResult = \stream_wrapper_register($protocol, $class, $flags);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Restores a built-in wrapper previously unregistered with
* stream_wrapper_unregister.
*
* @param string $protocol
* @throws StreamException
*
*/
function stream_wrapper_restore(string $protocol): void
{
error_clear_last();
$safeResult = \stream_wrapper_restore($protocol);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}
/**
* Allows you to disable an already defined stream wrapper. Once the wrapper
* has been disabled you may override it with a user-defined wrapper using
* stream_wrapper_register or reenable it later on with
* stream_wrapper_restore.
*
* @param string $protocol
* @throws StreamException
*
*/
function stream_wrapper_unregister(string $protocol): void
{
error_clear_last();
$safeResult = \stream_wrapper_unregister($protocol);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace Safe;
use Safe\Exceptions\StringsException;
/**
* convert_uudecode decodes a uuencoded string.
*
* @param string $string The uuencoded data.
* @return string Returns the decoded data as a string.
* @throws StringsException
*
*/
function convert_uudecode(string $string): string
{
error_clear_last();
$safeResult = \convert_uudecode($string);
if ($safeResult === false) {
throw StringsException::createFromPhpError();
}
return $safeResult;
}
/**
* Decodes a hexadecimally encoded binary string.
*
* @param string $string Hexadecimal representation of data.
* @return string Returns the binary representation of the given data.
* @throws StringsException
*
*/
function hex2bin(string $string): string
{
error_clear_last();
$safeResult = \hex2bin($string);
if ($safeResult === false) {
throw StringsException::createFromPhpError();
}
return $safeResult;
}
/**
* Calculates the MD5 hash of the file specified by the
* filename parameter using the
* RSA Data Security, Inc.
* MD5 Message-Digest Algorithm, and returns that hash.
* The hash is a 32-character hexadecimal number.
*
* @param string $filename The filename
* @param bool $binary When TRUE, returns the digest in raw binary format with a length of
* 16.
* @return non-falsy-string&lowercase-string Returns a string on success.
* @throws StringsException
*
*/
function md5_file(string $filename, bool $binary = false): string
{
error_clear_last();
$safeResult = \md5_file($filename, $binary);
if ($safeResult === false) {
throw StringsException::createFromPhpError();
}
return $safeResult;
}
/**
*
*
* @param string $filename The filename of the file to hash.
* @param bool $binary When TRUE, returns the digest in raw binary format with a length of
* 20.
* @return non-falsy-string&lowercase-string Returns a string on success.
* @throws StringsException
*
*/
function sha1_file(string $filename, bool $binary = false): string
{
error_clear_last();
$safeResult = \sha1_file($filename, $binary);
if ($safeResult === false) {
throw StringsException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,148 @@
<?php
namespace Safe;
use Safe\Exceptions\SwooleException;
/**
*
*
* @param string $hostname The host name.
* @param callable $callback The host name.
*
* The IP address.
* @throws SwooleException
*
*/
function swoole_async_dns_lookup(string $hostname, callable $callback): void
{
error_clear_last();
$safeResult = \swoole_async_dns_lookup($hostname, $callback);
if ($safeResult === false) {
throw SwooleException::createFromPhpError();
}
}
/**
*
*
* @param string $filename The filename of the file being read.
* @param string $callback The name of the file.
*
* The content read from the file.
* @throws SwooleException
*
*/
function swoole_async_readfile(string $filename, string $callback): void
{
error_clear_last();
$safeResult = \swoole_async_readfile($filename, $callback);
if ($safeResult === false) {
throw SwooleException::createFromPhpError();
}
}
/**
*
*
* @param string $filename The filename being written.
* @param string $content The content writing to the file.
* @param int $offset The offset.
* @param callable $callback
* @throws SwooleException
*
*/
function swoole_async_write(string $filename, string $content, ?int $offset = null, ?callable $callback = null): void
{
error_clear_last();
if ($callback !== null) {
$safeResult = \swoole_async_write($filename, $content, $offset, $callback);
} elseif ($offset !== null) {
$safeResult = \swoole_async_write($filename, $content, $offset);
} else {
$safeResult = \swoole_async_write($filename, $content);
}
if ($safeResult === false) {
throw SwooleException::createFromPhpError();
}
}
/**
*
*
* @param string $filename The filename being written.
* @param string $content The content writing to the file.
* @param callable $callback
* @param int $flags
* @throws SwooleException
*
*/
function swoole_async_writefile(string $filename, string $content, ?callable $callback = null, int $flags = 0): void
{
error_clear_last();
if ($flags !== 0) {
$safeResult = \swoole_async_writefile($filename, $content, $callback, $flags);
} elseif ($callback !== null) {
$safeResult = \swoole_async_writefile($filename, $content, $callback);
} else {
$safeResult = \swoole_async_writefile($filename, $content);
}
if ($safeResult === false) {
throw SwooleException::createFromPhpError();
}
}
/**
*
*
* @param callable $callback
* @throws SwooleException
*
*/
function swoole_event_defer(callable $callback): void
{
error_clear_last();
$safeResult = \swoole_event_defer($callback);
if ($safeResult === false) {
throw SwooleException::createFromPhpError();
}
}
/**
*
*
* @param int $fd
* @throws SwooleException
*
*/
function swoole_event_del(int $fd): void
{
error_clear_last();
$safeResult = \swoole_event_del($fd);
if ($safeResult === false) {
throw SwooleException::createFromPhpError();
}
}
/**
*
*
* @param int $fd
* @param string $data
* @throws SwooleException
*
*/
function swoole_event_write(int $fd, string $data): void
{
error_clear_last();
$safeResult = \swoole_event_write($fd, $data);
if ($safeResult === false) {
throw SwooleException::createFromPhpError();
}
}

0
vendor/thecodingmachine/safe/generated/8.5/uodbc.php vendored Normal file → Executable file
View File

View File

@@ -0,0 +1,40 @@
<?php
namespace Safe;
use Safe\Exceptions\UopzException;
/**
* Makes class extend parent
*
* @param string $class The name of the class to extend
* @param string $parent The name of the class to inherit
* @throws UopzException
*
*/
function uopz_extend(string $class, string $parent): void
{
error_clear_last();
$safeResult = \uopz_extend($class, $parent);
if ($safeResult === false) {
throw UopzException::createFromPhpError();
}
}
/**
* Makes class implement interface
*
* @param string $class
* @param string $interface
* @throws UopzException
*
*/
function uopz_implement(string $class, string $interface): void
{
error_clear_last();
$safeResult = \uopz_implement($class, $interface);
if ($safeResult === false) {
throw UopzException::createFromPhpError();
}
}

View File

@@ -0,0 +1,204 @@
<?php
namespace Safe;
use Safe\Exceptions\UrlException;
/**
* Decodes a base64 encoded string.
*
* @param string $string The encoded data.
* @param bool $strict If the strict parameter is set to TRUE
* then the base64_decode function will return
* FALSE if the input contains character from outside the base64
* alphabet. Otherwise invalid characters will be silently discarded.
* @return string Returns the decoded data. The returned data may be
* binary.
* @throws UrlException
*
*/
function base64_decode(string $string, bool $strict = false): string
{
error_clear_last();
$safeResult = \base64_decode($string, $strict);
if ($safeResult === false) {
throw UrlException::createFromPhpError();
}
return $safeResult;
}
/**
* get_headers returns an array with the headers sent
* by the server in response to a HTTP request.
*
* @param string $url The target URL.
* @param bool $associative If the optional associative parameter is set to true,
* get_headers parses the response and sets the
* array's keys.
* @param null|resource $context A valid context resource created with
* stream_context_create, or NULL to use the
* default context.
* @return array Returns an indexed or associative array with the headers.
* @throws UrlException
*
*/
function get_headers(string $url, bool $associative = false, $context = null): array
{
error_clear_last();
if ($context !== null) {
$safeResult = \get_headers($url, $associative, $context);
} else {
$safeResult = \get_headers($url, $associative);
}
if ($safeResult === false) {
throw UrlException::createFromPhpError();
}
return $safeResult;
}
/**
* Opens filename and parses it line by line for
* &lt;meta&gt; tags in the file. The parsing stops at
* &lt;/head&gt;.
*
* @param string $filename The path to the HTML file, as a string. This can be a local file or an
* URL.
*
*
* What get_meta_tags parses
*
*
*
*
*
*
* ]]>
*
*
* @param bool $use_include_path Setting use_include_path to TRUE will result
* in PHP trying to open the file along the standard include path as per
* the include_path directive.
* This is used for local files, not URLs.
* @return array Returns an array with all the parsed meta tags.
*
* The value of the name property becomes the key, the value of the content
* property becomes the value of the returned array, so you can easily use
* standard array functions to traverse it or access single values.
* Special characters in the value of the name property are substituted with
* '_', the rest is converted to lower case. If two meta tags have the same
* name, only the last one is returned.
*
* Returns FALSE on failure.
* @throws UrlException
*
*/
function get_meta_tags(string $filename, bool $use_include_path = false): array
{
error_clear_last();
$safeResult = \get_meta_tags($filename, $use_include_path);
if ($safeResult === false) {
throw UrlException::createFromPhpError();
}
return $safeResult;
}
/**
* This function parses a URL and returns an associative array containing any
* of the various components of the URL that are present.
* The values of the array elements are not URL decoded.
*
* This function is not meant to validate
* the given URL, it only breaks it up into the parts listed below. Partial and invalid
* URLs are also accepted, parse_url tries its best to
* parse them correctly.
*
* @param string $url The URL to parse.
* @param int $component Specify one of PHP_URL_SCHEME,
* PHP_URL_HOST, PHP_URL_PORT,
* PHP_URL_USER, PHP_URL_PASS,
* PHP_URL_PATH, PHP_URL_QUERY
* or PHP_URL_FRAGMENT to retrieve just a specific
* URL component as a string (except when
* PHP_URL_PORT is given, in which case the return
* value will be an int).
* @return array|int|null|string On seriously malformed URLs, parse_url.
*
* If the component parameter is omitted, an
* associative array is returned. At least one element will be
* present within the array. Potential keys within this array are:
*
*
*
* scheme - e.g. http
*
*
*
*
* host
*
*
*
*
* port
*
*
*
*
* user
*
*
*
*
* pass
*
*
*
*
* path
*
*
*
*
* query - after the question mark ?
*
*
*
*
* fragment - after the hashmark #
*
*
*
*
* If the component parameter is specified,
* parse_url returns a string (or an
* int, in the case of PHP_URL_PORT)
* instead of an array. If the requested component doesn't exist
* within the given URL, NULL will be returned.
* As of PHP 8.0.0, parse_url distinguishes absent and empty
* queries and fragments:
*
*
*
*
*
*
*
* Previously all cases resulted in query and fragment being NULL.
*
* Note that control characters (cf. ctype_cntrl) in the
* components are replaced with underscores (_).
* @throws UrlException
*
*/
function parse_url(string $url, int $component = -1)
{
error_clear_last();
$safeResult = \parse_url($url, $component);
if ($safeResult === false) {
throw UrlException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Safe;
use Safe\Exceptions\VarException;
/**
* Set the type of variable var to
* type.
*
* @param mixed $var The variable being converted.
* @param string $type Possibles values of type are:
*
*
*
* "boolean" or "bool"
*
*
*
*
* "integer" or "int"
*
*
*
*
* "float" or "double"
*
*
*
*
* "string"
*
*
*
*
* "array"
*
*
*
*
* "object"
*
*
*
*
* "null"
*
*
*
* @throws VarException
*
*/
function settype(&$var, string $type): void
{
error_clear_last();
$safeResult = \settype($var, $type);
if ($safeResult === false) {
throw VarException::createFromPhpError();
}
}

0
vendor/thecodingmachine/safe/generated/8.5/xdiff.php vendored Normal file → Executable file
View File

View File

@@ -0,0 +1,883 @@
<?php
namespace Safe;
use Safe\Exceptions\XmlException;
/**
* Frees the given XML parser.
*
* @param \XMLParser $parser
* @throws XmlException
*
*/
function xml_parser_free(\XMLParser $parser): void
{
error_clear_last();
$safeResult = \xml_parser_free($parser);
if ($safeResult === false) {
throw XmlException::createFromPhpError();
}
}
/**
* Sets an option in an XML parser.
*
* @param \XMLParser $parser A reference to the XML parser to set an option in.
* @param int $option Which option to set. See below.
*
* The following options are available:
*
* XML parser options
*
*
*
* Option constant
* Data type
* Description
*
*
*
*
* XML_OPTION_CASE_FOLDING
* bool
*
* Controls whether case-folding is enabled for this
* XML parser. Enabled by default.
*
*
*
* XML_OPTION_PARSE_HUGE
* bool
*
* Allows parsing documents larger than 10 MB.
* This option should only be enabled when the document size is
* bounded because this could otherwise lead to a DoS.
* This option is only available when using libxml2.
*
*
*
* XML_OPTION_SKIP_TAGSTART
* integer
*
* Specify how many characters should be skipped in the beginning of a
* tag name.
*
*
*
* XML_OPTION_SKIP_WHITE
* bool
*
* Whether to skip values consisting of whitespace characters.
*
*
*
* XML_OPTION_TARGET_ENCODING
* string
*
* Sets which target encoding to
* use in this XML parser.By default, it is set to the same as the
* source encoding used by xml_parser_create.
* Supported target encodings are ISO-8859-1,
* US-ASCII and UTF-8.
*
*
*
*
*
* @param mixed $value The option's new value.
* @throws XmlException
*
*/
function xml_parser_set_option(\XMLParser $parser, int $option, $value): void
{
error_clear_last();
$safeResult = \xml_parser_set_option($parser, $option, $value);
if ($safeResult === false) {
throw XmlException::createFromPhpError();
}
}
/**
* Sets the character data handler function for the XML parser
* parser.
*
* @param \XMLParser $parser The XML parser.
* @param callable $handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* voidhandler
* XMLParserparser
* stringdata
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
* data
*
*
* Character data as a string.
*
*
*
*
*
* Character data handler is called for every piece of a text in the XML
* document. It can be called multiple times inside each fragment (e.g.
* for non-ASCII strings).
* @return bool Always returns TRUE.
*
*/
function xml_set_character_data_handler(\XMLParser $parser, callable $handler): bool
{
error_clear_last();
$safeResult = \xml_set_character_data_handler($parser, $handler);
return $safeResult;
}
/**
* Sets the default handler function for the XML parser
* parser.
*
* @param \XMLParser $parser The XML parser.
* @param callable $handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* voidhandler
* XMLParserparser
* stringdata
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
*
* data
*
*
*
* data contains the character data.
* This may be the XML declaration, document type declaration,
* entities or other data for which no other handler exists.
*
*
*
*
* @return bool Always returns TRUE.
*
*/
function xml_set_default_handler(\XMLParser $parser, callable $handler): bool
{
error_clear_last();
$safeResult = \xml_set_default_handler($parser, $handler);
return $safeResult;
}
/**
* Sets the element handler functions for the XML parser.
*
* start_handler is called when a new XML element is
* opened. end_handler is called when an XML element
* is closed.
*
* @param \XMLParser $parser The XML parser.
* @param callable $start_handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* voidstart_element_handler
* XMLParserparser
* stringname
* arrayattributes
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
* name
*
*
* Contains the name of the element for which this handler is called.
* If case-folding is in effect
* for this parser, the element name will be in uppercase letters.
*
*
*
*
* attributes
*
*
* An associative array with the element's attributes.
* The array is empty if the element has no attributes.
* The keys of this array are the attribute names,
* the values are the attribute values.
* Attribute names are
* case-folded
* on the same criteria as element names.
* Attribute values are not case-folded.
*
*
* The order in which attributes is traversed
* is identical to the order in which the attributes were declared.
*
*
*
*
* @param callable $end_handler
* @return bool Always returns TRUE.
*
*/
function xml_set_element_handler(\XMLParser $parser, callable $start_handler, callable $end_handler): bool
{
error_clear_last();
$safeResult = \xml_set_element_handler($parser, $start_handler, $end_handler);
return $safeResult;
}
/**
* Set a handler to be called when leaving the scope of a namespace
* declaration. This will be called, for each namespace declaration, after
* the handler for the end tag of the element in which the namespace was
* declared.
*
* @param \XMLParser $parser The XML parser.
* @param callable $handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* handler
* XMLParserparser
* stringfalseprefix
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
* prefix
*
*
* The prefix is a string used to reference the namespace within an XML object.
* FALSE if no prefix exists.
*
*
*
*
* @return bool Always returns TRUE.
*
*/
function xml_set_end_namespace_decl_handler(\XMLParser $parser, callable $handler): bool
{
error_clear_last();
$safeResult = \xml_set_end_namespace_decl_handler($parser, $handler);
return $safeResult;
}
/**
* Sets the external entity reference handler function for the XML parser
* parser.
*
* @param \XMLParser $parser The XML parser.
* @param callable $handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* boolhandler
* XMLParserparser
* stringopen_entity_names
* stringfalsebase
* stringsystem_id
* stringfalsepublic_id
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
* open_entity_names
*
*
* A space-separated list of the names of the entities that are open for
* the parse of this entity (including the name of the referenced
* entity).
*
*
*
*
* base
*
*
* This is the base for resolving the system identifier
* (system_id) of the external entity.
*
*
*
*
* system_id
*
*
* The system identifier as specified in the entity declaration.
*
*
*
*
* public_id
*
*
* The public identifier as specified in the entity declaration, or
* an empty string if none was specified; the whitespace in the
* public identifier will have been normalized as required by
* the XML spec.
*
*
*
*
*
* The handler should return TRUE if the entity was handled,
* FALSE otherwise.
* When returning FALSE the XML parser will stop parsing and
* xml_get_error_code will return
* XML_ERROR_EXTERNAL_ENTITY_HANDLING.
* @return bool Always returns TRUE.
*
*/
function xml_set_external_entity_ref_handler(\XMLParser $parser, callable $handler): bool
{
error_clear_last();
$safeResult = \xml_set_external_entity_ref_handler($parser, $handler);
return $safeResult;
}
/**
* Sets the notation declaration handler function for the XML parser
* parser.
*
* A notation declaration is part of the document's DTD and has the
* following format:
*
* name
* { systemId | publicId?>
* ]]>
*
* See section 4.7 of the XML 1.0
* spec for the definition of notation declarations.
*
* @param \XMLParser $parser The XML parser.
* @param callable $handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* voidhandler
* XMLParserparser
* stringnotation_name
* stringfalsebase
* stringsystem_id
* stringfalsepublic_id
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
* notation_name
*
*
* This is the notation's name, as per
* the notation format described above.
*
*
*
*
*
* base
*
*
*
* This is the base for resolving the system identifier
* (system_id) of the notation declaration.
*
*
*
*
* system_id
*
*
* System identifier of the external notation declaration.
*
*
*
*
*
* public_id
*
*
*
* Public identifier of the external notation declaration.
*
*
*
*
* @return bool Always returns TRUE.
*
*/
function xml_set_notation_decl_handler(\XMLParser $parser, callable $handler): bool
{
error_clear_last();
$safeResult = \xml_set_notation_decl_handler($parser, $handler);
return $safeResult;
}
/**
* This function allows to use parser inside
* object. All callback functions could be set with
* xml_set_element_handler etc and assumed to be
* methods of object.
*
* @param \XMLParser $parser A reference to the XML parser to use inside the object.
* @param object $object The object where to use the XML parser.
* @return bool Always returns TRUE.
*
*/
function xml_set_object(\XMLParser $parser, object $object): bool
{
error_clear_last();
$safeResult = \xml_set_object($parser, $object);
return $safeResult;
}
/**
* Sets the processing instruction (PI) handler function for the XML parser
* parser.
*
* A processing instruction has the following format:
*
*
* ]]>
*
*
* @param \XMLParser $parser The XML parser.
* @param callable $handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* voidhandler
* XMLParserparser
* stringtarget
* stringdata
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
* target
*
*
* The processing instruction target.
*
*
*
*
* data
*
*
* The processing instruction data.
*
*
*
*
* @return bool Always returns TRUE.
*
*/
function xml_set_processing_instruction_handler(\XMLParser $parser, callable $handler): bool
{
error_clear_last();
$safeResult = \xml_set_processing_instruction_handler($parser, $handler);
return $safeResult;
}
/**
* Set a handler to be called when a namespace is declared. Namespace
* declarations occur inside start tags. But the namespace declaration start
* handler is called before the start tag handler for each namespace declared
* in that start tag.
*
* @param \XMLParser $parser The XML parser.
* @param callable $handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* voidhandler
* XMLParserparser
* stringfalseprefix
* stringuri
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
* prefix
*
*
* The prefix is a string used to reference the namespace within an XML object.
* FALSE if no prefix exists.
*
*
*
*
* uri
*
*
* Uniform Resource Identifier (URI) of namespace.
*
*
*
*
* @return bool Always returns TRUE.
*
*/
function xml_set_start_namespace_decl_handler(\XMLParser $parser, callable $handler): bool
{
error_clear_last();
$safeResult = \xml_set_start_namespace_decl_handler($parser, $handler);
return $safeResult;
}
/**
* Sets the unparsed entity declaration handler function for the XML parser
* parser.
*
* The handler will be called if the XML parser
* encounters an external entity declaration with an NDATA declaration, like
* the following:
*
* name {publicId | systemId}
* NDATA notationName
* ]]>
*
*
* See section 4.2.2 of
* the XML 1.0 spec for the definition of notation declared
* external entities.
*
* @param \XMLParser $parser The XML parser.
* @param callable $handler
* If NULL is passed, the handler is reset to its default state.
*
*
* An empty string will also reset the handler,
* however this is deprecated as of PHP 8.4.0.
*
*
*
*
* If handler is a callable,
* the callable is set as the handler.
*
*
* If handler is a string,
* it can be the name of a method of an object set with
* xml_set_object.
*
*
* This is deprecated as of PHP 8.4.0.
*
*
*
* The signature of the handler must be:
*
* voidhandler
* XMLParserparser
* stringentity_name
* stringfalsebase
* stringsystem_id
* stringfalsepublic_id
* stringfalsenotation_name
*
*
*
* parser
*
*
* The XML parser calling the handler.
*
*
*
*
* entity_name
*
*
* The name of the entity that is about to be defined.
*
*
*
*
* base
*
*
* This is the base for resolving the system identifier
* (systemId) of the external entity.
*
*
*
*
* system_id
*
*
* System identifier for the external entity.
*
*
*
*
* public_id
*
*
* Public identifier for the external entity.
*
*
*
*
* notation_name
*
*
* Name of the notation of this entity (see
* xml_set_notation_decl_handler).
*
*
*
*
* @return bool Always returns TRUE.
*
*/
function xml_set_unparsed_entity_decl_handler(\XMLParser $parser, callable $handler): bool
{
error_clear_last();
$safeResult = \xml_set_unparsed_entity_decl_handler($parser, $handler);
return $safeResult;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Safe;
use Safe\Exceptions\XmlrpcException;
/**
* Sets xmlrpc type, base64 or datetime, for a PHP string value.
*
* @param \DateTime|string $value Value to set the type
* @param string $type 'base64' or 'datetime'
* @throws XmlrpcException
*
*/
function xmlrpc_set_type(&$value, string $type): void
{
error_clear_last();
$safeResult = \xmlrpc_set_type($value, $type);
if ($safeResult === false) {
throw XmlrpcException::createFromPhpError();
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace Safe;
use Safe\Exceptions\YamlException;
/**
* Convert all or part of a YAML document stream read from a file to a PHP variable.
*
* @param string $filename Path to the file.
* @param int $pos Document to extract from stream (-1 for all
* documents, 0 for first document, ...).
* @param int|null $ndocs If ndocs is provided, then it is filled with the
* number of documents found in stream.
* @param array|null $callbacks Content handlers for YAML nodes. Associative array of YAML
* tag =&gt; callable mappings. See
* parse callbacks for more
* details.
* @return mixed Returns the value encoded in filename in appropriate
* PHP type. If pos is -1 an
* array will be returned with one entry for each document found
* in the stream.
* @throws YamlException
*
*/
function yaml_parse_file(string $filename, int $pos = 0, ?int &$ndocs = null, ?array $callbacks = null)
{
error_clear_last();
if ($callbacks !== null) {
$safeResult = \yaml_parse_file($filename, $pos, $ndocs, $callbacks);
} else {
$safeResult = \yaml_parse_file($filename, $pos, $ndocs);
}
if ($safeResult === false) {
throw YamlException::createFromPhpError();
}
return $safeResult;
}
/**
* Convert all or part of a YAML document stream read from a URL to a PHP variable.
*
* @param string $url url should be of the form "scheme://...". PHP
* will search for a protocol handler (also known as a wrapper) for that
* scheme. If no wrappers for that protocol are registered, PHP will emit
* a notice to help you track potential problems in your script and then
* continue as though filename specifies a regular file.
* @param int $pos Document to extract from stream (-1 for all
* documents, 0 for first document, ...).
* @param int|null $ndocs If ndocs is provided, then it is filled with the
* number of documents found in stream.
* @param array|null $callbacks Content handlers for YAML nodes. Associative array of YAML
* tag =&gt; callable mappings. See
* parse callbacks for more details.
* @return mixed Returns the value encoded in url in appropriate
* PHP type. If pos is
* -1 an array will be returned with one entry
* for each document found in the stream.
* @throws YamlException
*
*/
function yaml_parse_url(string $url, int $pos = 0, ?int &$ndocs = null, ?array $callbacks = null)
{
error_clear_last();
if ($callbacks !== null) {
$safeResult = \yaml_parse_url($url, $pos, $ndocs, $callbacks);
} else {
$safeResult = \yaml_parse_url($url, $pos, $ndocs);
}
if ($safeResult === false) {
throw YamlException::createFromPhpError();
}
return $safeResult;
}
/**
* Convert all or part of a YAML document stream to a PHP variable.
*
* @param string $input The string to parse as a YAML document stream.
* @param int $pos Document to extract from stream (-1 for all
* documents, 0 for first document, ...).
* @param int|null $ndocs If ndocs is provided, then it is filled with the
* number of documents found in stream.
* @param array|null $callbacks Content handlers for YAML nodes. Associative array of YAML
* tag =&gt; callable mappings. See
* parse callbacks for more
* details.
* @return mixed Returns the value encoded in input in appropriate
* PHP type. If pos is -1 an
* array will be returned with one entry for each document found
* in the stream.
* @throws YamlException
*
*/
function yaml_parse(string $input, int $pos = 0, ?int &$ndocs = null, ?array $callbacks = null)
{
error_clear_last();
if ($callbacks !== null) {
$safeResult = \yaml_parse($input, $pos, $ndocs, $callbacks);
} else {
$safeResult = \yaml_parse($input, $pos, $ndocs);
}
if ($safeResult === false) {
throw YamlException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,438 @@
<?php
namespace Safe;
use Safe\Exceptions\YazException;
/**
* This function invokes a CCL parser. It converts a given CCL FIND query to
* an RPN query which may be passed to the yaz_search
* function to perform a search.
*
* To define a set of valid CCL fields call yaz_ccl_conf
* prior to this function.
*
* @param resource $id The connection resource returned by yaz_connect.
* @param string $query The CCL FIND query.
* @param array|null $result If the function was executed successfully, this will be an array
* containing the valid RPN query under the key rpn.
*
* Upon failure, three indexes are set in this array to indicate the cause
* of failure:
*
*
*
* errorcode - the CCL error code (integer)
*
*
*
*
* errorstring - the CCL error string
*
*
*
*
* errorpos - approximate position in query of failure
* (integer is character position)
*
*
*
*
* errorcode - the CCL error code (integer)
*
* errorstring - the CCL error string
*
* errorpos - approximate position in query of failure
* (integer is character position)
* @throws YazException
*
*/
function yaz_ccl_parse($id, string $query, ?array &$result): void
{
error_clear_last();
$safeResult = \yaz_ccl_parse($id, $query, $result);
if ($safeResult === false) {
throw YazException::createFromPhpError();
}
}
/**
* Closes the connection given by parameter id.
*
* @param resource $id The connection resource returned by yaz_connect.
* @throws YazException
*
*/
function yaz_close($id): void
{
error_clear_last();
$safeResult = \yaz_close($id);
if ($safeResult === false) {
throw YazException::createFromPhpError();
}
}
/**
* This function returns a connection resource on success, zero on
* failure.
*
* yaz_connect prepares for a connection to a
* Z39.50 server.
* This function is non-blocking and does not attempt to establish
* a connection - it merely prepares a connect to be performed later when
* yaz_wait is called.
*
* @param string $zurl A string that takes the form host[:port][/database].
* If port is omitted, port 210 is used. If database is omitted
* Default is used.
* @param mixed $options If given as a string, it is treated as the Z39.50 V2 authentication
* string (OpenAuth).
*
* If given as an array, the contents of the array serves as options.
*
*
* user
*
*
* Username for authentication.
*
*
*
*
* group
*
*
* Group for authentication.
*
*
*
*
* password
*
*
* Password for authentication.
*
*
*
*
* cookie
*
*
* Cookie for session (YAZ proxy).
*
*
*
*
* proxy
*
*
* Proxy for connection (YAZ proxy).
*
*
*
*
* persistent
*
*
* A boolean. If TRUE the connection is persistent; If FALSE the
* connection is not persistent. By default connections are persistent.
*
*
*
* If you open a persistent connection, you won't be able to close
* it later with yaz_close.
*
*
*
*
*
* piggyback
*
*
* A boolean. If TRUE piggyback is enabled for searches; If FALSE
* piggyback is disabled. By default piggyback is enabled.
*
*
* Enabling piggyback is more efficient and usually saves a
* network-round-trip for first time fetches of records. However, a
* few Z39.50 servers do not support piggyback or they ignore element
* set names. For those, piggyback should be disabled.
*
*
*
*
* charset
*
*
* A string that specifies character set to be used in Z39.50
* language and character set negotiation. Use strings such as:
* ISO-8859-1, UTF-8,
* UTF-16.
*
*
* Most Z39.50 servers do not support this feature (and thus, this is
* ignored). Many servers use the ISO-8859-1 encoding for queries and
* messages. MARC21/USMARC records are not affected by this setting.
*
*
*
*
*
* preferredMessageSize
*
*
* An integer that specifies the maximum byte size of all records
* to be returned by a target during retrieval. See the
* Z39.50 standard for more
* information.
*
*
*
* This option is supported in PECL YAZ 1.0.5 or later.
*
*
*
*
*
*
* maximumRecordSize
*
*
* An integer that specifies the maximum byte size of a single record
* to be returned by a target during retrieval. This
* entity is referred to as Exceptional-record-size in the
* Z39.50 standard.
*
*
*
* This option is supported in PECL YAZ 1.0.5 or later.
*
*
*
*
*
*
*
* Username for authentication.
*
* Group for authentication.
*
* Password for authentication.
*
* Cookie for session (YAZ proxy).
*
* Proxy for connection (YAZ proxy).
*
* A boolean. If TRUE the connection is persistent; If FALSE the
* connection is not persistent. By default connections are persistent.
*
* If you open a persistent connection, you won't be able to close
* it later with yaz_close.
*
* A boolean. If TRUE piggyback is enabled for searches; If FALSE
* piggyback is disabled. By default piggyback is enabled.
*
* Enabling piggyback is more efficient and usually saves a
* network-round-trip for first time fetches of records. However, a
* few Z39.50 servers do not support piggyback or they ignore element
* set names. For those, piggyback should be disabled.
*
* A string that specifies character set to be used in Z39.50
* language and character set negotiation. Use strings such as:
* ISO-8859-1, UTF-8,
* UTF-16.
*
* Most Z39.50 servers do not support this feature (and thus, this is
* ignored). Many servers use the ISO-8859-1 encoding for queries and
* messages. MARC21/USMARC records are not affected by this setting.
*
* An integer that specifies the maximum byte size of all records
* to be returned by a target during retrieval. See the
* Z39.50 standard for more
* information.
*
* This option is supported in PECL YAZ 1.0.5 or later.
*
* An integer that specifies the maximum byte size of a single record
* to be returned by a target during retrieval. This
* entity is referred to as Exceptional-record-size in the
* Z39.50 standard.
*
* This option is supported in PECL YAZ 1.0.5 or later.
* @return mixed A connection resource on success, FALSE on error.
* @throws YazException
*
*/
function yaz_connect(string $zurl, $options = null)
{
error_clear_last();
if ($options !== null) {
$safeResult = \yaz_connect($zurl, $options);
} else {
$safeResult = \yaz_connect($zurl);
}
if ($safeResult === false) {
throw YazException::createFromPhpError();
}
return $safeResult;
}
/**
* This function allows you to change databases within a session by
* specifying one or more databases to be used in search, retrieval, etc.
* - overriding databases specified in call to
* yaz_connect.
*
* @param resource $id The connection resource returned by yaz_connect.
* @param string $databases A string containing one or more databases. Multiple databases are
* separated by a plus sign +.
* @throws YazException
*
*/
function yaz_database($id, string $databases): void
{
error_clear_last();
$safeResult = \yaz_database($id, $databases);
if ($safeResult === false) {
throw YazException::createFromPhpError();
}
}
/**
* This function sets the element set name for retrieval.
*
* Call this function before yaz_search or
* yaz_present to specify the element set name for
* records to be retrieved.
*
* @param resource $id The connection resource returned by yaz_connect.
* @param string $elementset Most servers support F (for full records) and
* B (for brief records).
* @throws YazException
*
*/
function yaz_element($id, string $elementset): void
{
error_clear_last();
$safeResult = \yaz_element($id, $elementset);
if ($safeResult === false) {
throw YazException::createFromPhpError();
}
}
/**
* This function prepares for retrieval of records after a successful search.
*
* The yaz_range function should be called prior to this
* function to specify the range of records to be retrieved.
*
* @param resource $id The connection resource returned by yaz_connect.
* @throws YazException
*
*/
function yaz_present($id): void
{
error_clear_last();
$safeResult = \yaz_present($id);
if ($safeResult === false) {
throw YazException::createFromPhpError();
}
}
/**
* yaz_search prepares for a search on the given
* connection.
*
* Like yaz_connect this function is non-blocking and
* only prepares for a search to be executed later when
* yaz_wait is called.
*
* @param resource $id The connection resource returned by yaz_connect.
* @param string $type This parameter represents the query type - only "rpn"
* is supported now in which case the third argument specifies a Type-1
* query in prefix query notation.
* @param string $query The RPN query is a textual representation of the Type-1 query as
* defined by the Z39.50 standard. However, in the text representation
* as used by YAZ a prefix notation is used, that is the operator
* precedes the operands. The query string is a sequence of tokens where
* white space is ignored unless surrounded by double quotes. Tokens beginning
* with an at-character (@) are considered operators,
* otherwise they are treated as search terms.
*
* You can find information about attributes at the
* Z39.50 Maintenance Agency
* site.
*
* If you would like to use a more friendly notation,
* use the CCL parser - functions yaz_ccl_conf and
* yaz_ccl_parse.
* @throws YazException
*
*/
function yaz_search($id, string $type, string $query): void
{
error_clear_last();
$safeResult = \yaz_search($id, $type, $query);
if ($safeResult === false) {
throw YazException::createFromPhpError();
}
}
/**
* This function carries out networked (blocked) activity for outstanding
* requests which have been prepared by the functions
* yaz_connect, yaz_search,
* yaz_present, yaz_scan and
* yaz_itemorder.
*
* yaz_wait returns when all servers have either
* completed all requests or aborted (in case of errors).
*
* @param array $options An associative array of options:
*
*
* timeout
*
*
* Sets timeout in seconds. If a server has not responded within the
* timeout it is considered dead and yaz_wait
* returns. The default value for timeout is 15 seconds.
*
*
*
*
* event
*
*
* A boolean.
*
*
*
*
*
* Sets timeout in seconds. If a server has not responded within the
* timeout it is considered dead and yaz_wait
* returns. The default value for timeout is 15 seconds.
*
* A boolean.
* @return mixed Returns TRUE on success.
* In event mode, returns resource.
* @throws YazException
*
*/
function yaz_wait(?array &$options = null)
{
error_clear_last();
$safeResult = \yaz_wait($options);
if ($safeResult === false) {
throw YazException::createFromPhpError();
}
return $safeResult;
}

View File

@@ -0,0 +1,144 @@
<?php
namespace Safe;
use Safe\Exceptions\ZipException;
/**
* Closes the specified directory entry.
*
* @param resource $zip_entry A directory entry previously opened zip_entry_open.
* @throws ZipException
*
*/
function zip_entry_close($zip_entry): void
{
error_clear_last();
$safeResult = \zip_entry_close($zip_entry);
if ($safeResult === false) {
throw ZipException::createFromPhpError();
}
}
/**
* Returns the compressed size of the specified directory entry.
*
* @param resource $zip_entry A directory entry returned by zip_read.
* @return int The compressed size.
* @throws ZipException
*
*/
function zip_entry_compressedsize($zip_entry): int
{
error_clear_last();
$safeResult = \zip_entry_compressedsize($zip_entry);
if ($safeResult === false) {
throw ZipException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the compression method of the directory entry specified
* by zip_entry.
*
* @param resource $zip_entry A directory entry returned by zip_read.
* @return string The compression method.
* @throws ZipException
*
*/
function zip_entry_compressionmethod($zip_entry): string
{
error_clear_last();
$safeResult = \zip_entry_compressionmethod($zip_entry);
if ($safeResult === false) {
throw ZipException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the actual size of the specified directory entry.
*
* @param resource $zip_entry A directory entry returned by zip_read.
* @return int The size of the directory entry.
* @throws ZipException
*
*/
function zip_entry_filesize($zip_entry): int
{
error_clear_last();
$safeResult = \zip_entry_filesize($zip_entry);
if ($safeResult === false) {
throw ZipException::createFromPhpError();
}
return $safeResult;
}
/**
* Returns the name of the specified directory entry.
*
* @param resource $zip_entry A directory entry returned by zip_read.
* @return string The name of the directory entry.
* @throws ZipException
*
*/
function zip_entry_name($zip_entry): string
{
error_clear_last();
$safeResult = \zip_entry_name($zip_entry);
if ($safeResult === false) {
throw ZipException::createFromPhpError();
}
return $safeResult;
}
/**
* Opens a directory entry in a zip file for reading.
*
* @param resource $zip_dp A valid resource handle returned by zip_open.
* @param resource $zip_entry A directory entry returned by zip_read.
* @param string $mode Any of the modes specified in the documentation of
* fopen.
*
* Currently, mode is ignored and is always
* "rb". This is due to the fact that zip support
* in PHP is read only access.
* @throws ZipException
*
*/
function zip_entry_open($zip_dp, $zip_entry, string $mode = "rb"): void
{
error_clear_last();
$safeResult = \zip_entry_open($zip_dp, $zip_entry, $mode);
if ($safeResult === false) {
throw ZipException::createFromPhpError();
}
}
/**
* Reads from an open directory entry.
*
* @param resource $zip_entry A directory entry returned by zip_read.
* @param int $len The number of bytes to return.
*
* This should be the uncompressed length you wish to read.
* @return string Returns the data read, empty string on end of a file.
* @throws ZipException
*
*/
function zip_entry_read($zip_entry, int $len = 1024): string
{
error_clear_last();
$safeResult = \zip_entry_read($zip_entry, $len);
if ($safeResult === false) {
throw ZipException::createFromPhpError();
}
return $safeResult;
}

0
vendor/thecodingmachine/safe/generated/8.5/zlib.php vendored Normal file → Executable file
View File