Add Safe PHP functions

This commit is contained in:
Alex Cabal 2019-03-07 12:11:50 -06:00
parent 04a956886a
commit 58cc098058
260 changed files with 49458 additions and 45 deletions

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ApacheException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ApcException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ApcuException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ArrayException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class Bzip2Exception extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ClassobjException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ComException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class CubridException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class DatetimeException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class DirException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class EioException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ErrorfuncException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ExecException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class FileinfoException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class FilesystemException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class FilterException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class FpmException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class FtpException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class FunchandException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class GmpException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class GnupgException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class HashException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class IbaseException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class IbmDb2Exception extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class IconvException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ImageException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ImapException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class InfoException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class IngresiiException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class InotifyException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class LdapException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class LibeventException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class LibxmlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class LzfException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MailparseException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MbstringException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MiscException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MsqlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MssqlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MysqlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MysqliException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MysqlndMsException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class MysqlndQcException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class NetworkException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class Oci8Exception extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class OpcacheException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class OpensslException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class OutcontrolException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class PasswordException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class PcntlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class PdfException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class PgsqlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class PosixException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class PsException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class PspellException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ReadlineException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class RrdException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SemException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SessionException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ShmopException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SimplexmlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SocketsException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SodiumException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SolrException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SplException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SqlsrvException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SsdeepException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class Ssh2Exception extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class StatsException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class StreamException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class StringsException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class SwooleException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class UodbcException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class UopzException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class UrlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class VarException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class XdiffException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class XmlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class XmlrpcException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class YamlException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class YazException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ZipException extends AbstractSafeException
{
}

View file

@ -0,0 +1,6 @@
<?php
namespace Safe\Exceptions;
class ZlibException extends AbstractSafeException
{
}

View file

@ -0,0 +1,173 @@
<?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();
$result = \apache_get_version();
if ($result === false) {
throw ApacheException::createFromPhpError();
}
return $result;
}
/**
* Retrieve an Apache environment variable specified by
* variable.
*
* This function requires Apache 2 otherwise it's undefined.
*
* @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();
$result = \apache_getenv($variable, $walk_to_top);
if ($result === false) {
throw ApacheException::createFromPhpError();
}
return $result;
}
/**
* Fetches all HTTP request headers from the current request.
*
* @return array An associative array of all the HTTP headers in the current request.
* @throws ApacheException
*
*/
function apache_request_headers(): array
{
error_clear_last();
$result = \apache_request_headers();
if ($result === false) {
throw ApacheException::createFromPhpError();
}
return $result;
}
/**
* apache_reset_timeout resets the Apache write timer,
* which defaults to 300 seconds. With set_time_limit(0);
* ignore_user_abort(true) and periodic
* apache_reset_timeout calls, Apache can theoretically
* run forever.
*
* This function requires Apache 1.
*
* @throws ApacheException
*
*/
function apache_reset_timeout(): void
{
error_clear_last();
$result = \apache_reset_timeout();
if ($result === false) {
throw ApacheException::createFromPhpError();
}
}
/**
* Fetch all HTTP response headers.
*
* @return array An array of all Apache response headers on success.
* @throws ApacheException
*
*/
function apache_response_headers(): array
{
error_clear_last();
$result = \apache_response_headers();
if ($result === false) {
throw ApacheException::createFromPhpError();
}
return $result;
}
/**
* 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();
$result = \apache_setenv($variable, $value, $walk_to_top);
if ($result === 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.
* @throws ApacheException
*
*/
function getallheaders(): array
{
error_clear_last();
$result = \getallheaders();
if ($result === false) {
throw ApacheException::createFromPhpError();
}
return $result;
}
/**
* 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 $filename The file that the virtual command will be performed on.
* @throws ApacheException
*
*/
function virtual(string $filename): void
{
error_clear_last();
$result = \virtual($filename);
if ($result === false) {
throw ApacheException::createFromPhpError();
}
}

View file

@ -0,0 +1,239 @@
<?php
namespace Safe;
use Safe\Exceptions\ApcException;
/**
* Retrieves cached information and meta-data from APC's data store.
*
* @param string $cache_type If cache_type is "user",
* information about the user cache will be returned.
*
* If cache_type is "filehits",
* information about which files have been served from the bytecode cache
* for the current request will be returned. This feature must be enabled at
* compile time using --enable-filehits.
*
* If an invalid or no cache_type is specified, information about
* the system cache (cached files) will be returned.
* @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 ApcException
*
*/
function apc_cache_info(string $cache_type = '', bool $limited = false): array
{
error_clear_last();
$result = \apc_cache_info($cache_type, $limited);
if ($result === false) {
throw ApcException::createFromPhpError();
}
return $result;
}
/**
* apc_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 ApcException
*
*/
function apc_cas(string $key, int $old, int $new): void
{
error_clear_last();
$result = \apc_cas($key, $old, $new);
if ($result === false) {
throw ApcException::createFromPhpError();
}
}
/**
* Stores a file in the bytecode cache, bypassing all filters.
*
* @param string $filename Full or relative path to a PHP file that will be compiled and stored in
* the bytecode cache.
* @param bool $atomic
* @return mixed Returns TRUE on success.
* @throws ApcException
*
*/
function apc_compile_file(string $filename, bool $atomic = true)
{
error_clear_last();
$result = \apc_compile_file($filename, $atomic);
if ($result === false) {
throw ApcException::createFromPhpError();
}
return $result;
}
/**
* 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 $success Optionally pass the success or fail boolean value to
* this referenced variable.
* @return int Returns the current value of key's value on success
* @throws ApcException
*
*/
function apc_dec(string $key, int $step = 1, ?bool &$success = null): int
{
error_clear_last();
$result = \apc_dec($key, $step, $success);
if ($result === false) {
throw ApcException::createFromPhpError();
}
return $result;
}
/**
* define is notoriously slow. Since the main benefit of
* APC is to increase the performance of scripts/applications, this mechanism
* is provided to streamline the process of mass constant definition. However,
* this function does not perform as well as anticipated.
*
* For a better-performing solution, try the
* hidef extension from PECL.
*
* @param string $key The key serves as the name of the constant set
* being stored. This key is used to retrieve the
* stored constants in apc_load_constants.
* @param array $constants An associative array of constant_name =&gt; value
* pairs. The constant_name must follow the normal
* constant naming rules.
* value must evaluate to a scalar value.
* @param bool $case_sensitive The default behaviour for constants is to be declared case-sensitive;
* i.e. CONSTANT and Constant
* represent different values. If this parameter evaluates to FALSE the
* constants will be declared as case-insensitive symbols.
* @throws ApcException
*
*/
function apc_define_constants(string $key, array $constants, bool $case_sensitive = true): void
{
error_clear_last();
$result = \apc_define_constants($key, $constants, $case_sensitive);
if ($result === false) {
throw ApcException::createFromPhpError();
}
}
/**
* Deletes the given files from the opcode cache.
*
* @param mixed $keys The files to be deleted. Accepts a string,
* array of strings, or an APCIterator
* object.
* @return mixed Returns TRUE on success.
* Or if keys is an array, then
* an empty array is returned on success, or an array of failed files
* is returned.
* @throws ApcException
*
*/
function apc_delete_file($keys)
{
error_clear_last();
$result = \apc_delete_file($keys);
if ($result === false) {
throw ApcException::createFromPhpError();
}
return $result;
}
/**
* Removes a stored variable from the cache.
*
* @param string|string[]|APCIterator $key The key used to store the value (with
* apc_store).
* @throws ApcException
*
*/
function apc_delete(string $key)
{
error_clear_last();
$result = \apc_delete($key);
if ($result === false) {
throw ApcException::createFromPhpError();
}
return $result;
}
/**
* 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 $success Optionally pass the success or fail boolean value to
* this referenced variable.
* @return int Returns the current value of key's value on success
* @throws ApcException
*
*/
function apc_inc(string $key, int $step = 1, ?bool &$success = null): int
{
error_clear_last();
$result = \apc_inc($key, $step, $success);
if ($result === false) {
throw ApcException::createFromPhpError();
}
return $result;
}
/**
* Loads a set of constants from the cache.
*
* @param string $key The name of the constant set (that was stored with
* apc_define_constants) to be retrieved.
* @param bool $case_sensitive The default behaviour for constants is to be declared case-sensitive;
* i.e. CONSTANT and Constant
* represent different values. If this parameter evaluates to FALSE the
* constants will be declared as case-insensitive symbols.
* @throws ApcException
*
*/
function apc_load_constants(string $key, bool $case_sensitive = true): void
{
error_clear_last();
$result = \apc_load_constants($key, $case_sensitive);
if ($result === false) {
throw ApcException::createFromPhpError();
}
}
/**
* Retrieves APC's Shared Memory Allocation information.
*
* @param bool $limited When set to FALSE (default) apc_sma_info will
* return a detailed information about each segment.
* @return array Array of Shared Memory Allocation data; FALSE on failure.
* @throws ApcException
*
*/
function apc_sma_info(bool $limited = false): array
{
error_clear_last();
$result = \apc_sma_info($limited);
if ($result === false) {
throw ApcException::createFromPhpError();
}
return $result;
}

View file

@ -0,0 +1,131 @@
<?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();
$result = \apcu_cache_info($limited);
if ($result === false) {
throw ApcuException::createFromPhpError();
}
return $result;
}
/**
* 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();
$result = \apcu_cas($key, $old, $new);
if ($result === 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 $success Optionally pass the success or fail boolean value to
* this referenced variable.
* @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
{
error_clear_last();
$result = \apcu_dec($key, $step, $success);
if ($result === false) {
throw ApcuException::createFromPhpError();
}
return $result;
}
/**
* Removes a stored variable from the cache.
*
* @param string|string[]|APCUIterator $key A key used to store the value as a
* string for a single key,
* or as an array of strings for several keys,
* or as an APCUIterator object.
* @return bool|array Returns TRUE on success.
* @throws ApcuException
*
*/
function apcu_delete($key): void
{
error_clear_last();
$result = \apcu_delete($key);
if ($result === false) {
throw ApcuException::createFromPhpError();
}
}
/**
* 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 $success Optionally pass the success or fail boolean value to
* this referenced variable.
* @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
{
error_clear_last();
$result = \apcu_inc($key, $step, $success);
if ($result === false) {
throw ApcuException::createFromPhpError();
}
return $result;
}
/**
* 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();
$result = \apcu_sma_info($limited);
if ($result === false) {
throw ApcuException::createFromPhpError();
}
return $result;
}

View file

@ -0,0 +1,433 @@
<?php
namespace Safe;
use Safe\Exceptions\ArrayException;
/**
* 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, FALSE if the number of elements
* for each array isn't equal.
* @throws ArrayException
*
*/
function array_combine(array $keys, array $values): array
{
error_clear_last();
$result = \array_combine($keys, $values);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
return $result;
}
/**
* array_multisort can be used to sort several
* arrays at once, or a multi-dimensional array by one or more
* dimensions.
*
* Associative (string) keys will be maintained, but numeric
* keys will be re-indexed.
*
* @param array $array1 An array being sorted.
* @param array|int $array1_sort_order The order used to sort the previous array argument. Either
* SORT_ASC to sort ascendingly or SORT_DESC
* to sort descendingly.
*
* This argument can be swapped with array1_sort_flags
* or omitted entirely, in which case SORT_ASC is assumed.
* @param array|int $array1_sort_flags Sort options for the previous array argument:
*
* Sorting type flags:
*
*
* SORT_REGULAR - compare items normally
* (don't change types)
*
*
* SORT_NUMERIC - compare items numerically
*
*
* SORT_STRING - compare items as strings
*
*
*
* SORT_LOCALE_STRING - compare items as
* strings, based on the current locale. It uses the locale,
* which can be changed using setlocale
*
*
*
*
* SORT_NATURAL - compare items as strings
* using "natural ordering" like natsort
*
*
*
*
* SORT_FLAG_CASE - can be combined
* (bitwise OR) with
* SORT_STRING or
* SORT_NATURAL to sort strings case-insensitively
*
*
*
*
* This argument can be swapped with array1_sort_order
* or omitted entirely, in which case SORT_REGULAR is assumed.
* @param mixed $params More arrays, optionally followed by sort order and flags. Only elements
* corresponding to equivalent elements in previous arrays are compared.
* In other words, the sort is lexicographical.
* @throws ArrayException
*
*/
function array_multisort(array &$array1, $array1_sort_order = SORT_ASC, $array1_sort_flags = SORT_REGULAR, ...$params): void
{
error_clear_last();
if ($params !== []) {
$result = \array_multisort($array1, $array1_sort_order, $array1_sort_flags, ...$params);
} else {
$result = \array_multisort($array1, $array1_sort_order, $array1_sort_flags);
}
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* Applies the user-defined callback function to each
* element of the array. This function will recurse
* into deeper arrays.
*
* @param array $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 $userdata If the optional userdata parameter is supplied,
* it will be passed as the third parameter to the
* callback.
* @throws ArrayException
*
*/
function array_walk_recursive(array &$array, callable $callback, $userdata = null): void
{
error_clear_last();
$result = \array_walk_recursive($array, $callback, $userdata);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* This function sorts an array such that array indices maintain their
* correlation with the array elements they are associated with.
*
* This is used mainly when sorting associative arrays where the actual
* element order is significant.
*
* @param array $array The input array.
* @param int $sort_flags You may modify the behavior of the sort using the optional parameter
* sort_flags, for details see
* sort.
* @throws ArrayException
*
*/
function arsort(array &$array, int $sort_flags = SORT_REGULAR): void
{
error_clear_last();
$result = \arsort($array, $sort_flags);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* This function sorts an array such that array indices maintain
* their correlation with the array elements they are associated
* with. This is used mainly when sorting associative arrays where
* the actual element order is significant.
*
* @param array $array The input array.
* @param int $sort_flags You may modify the behavior of the sort using the optional
* parameter sort_flags, for details
* see sort.
* @throws ArrayException
*
*/
function asort(array &$array, int $sort_flags = SORT_REGULAR): void
{
error_clear_last();
$result = \asort($array, $sort_flags);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* Sorts an array by key in reverse order, maintaining key to data
* correlations. This is useful mainly for associative arrays.
*
* @param array $array The input array.
* @param int $sort_flags You may modify the behavior of the sort using the optional parameter
* sort_flags, for details see
* sort.
* @throws ArrayException
*
*/
function krsort(array &$array, int $sort_flags = SORT_REGULAR): void
{
error_clear_last();
$result = \krsort($array, $sort_flags);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* Sorts an array by key, maintaining key to data correlations. This is
* useful mainly for associative arrays.
*
* @param array $array The input array.
* @param int $sort_flags You may modify the behavior of the sort using the optional
* parameter sort_flags, for details
* see sort.
* @throws ArrayException
*
*/
function ksort(array &$array, int $sort_flags = SORT_REGULAR): void
{
error_clear_last();
$result = \ksort($array, $sort_flags);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* natcasesort is a case insensitive version of
* natsort.
*
* This function implements a sort algorithm that orders
* alphanumeric strings in the way a human being would while maintaining
* key/value associations. This is described as a "natural ordering".
*
* @param array $array The input array.
* @throws ArrayException
*
*/
function natcasesort(array &$array): void
{
error_clear_last();
$result = \natcasesort($array);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* This function implements a sort algorithm that orders alphanumeric strings
* in the way a human being would while maintaining key/value associations.
* This is described as a "natural ordering". An example of the difference
* between this algorithm and the regular computer string sorting algorithms
* (used in sort) can be seen in the example below.
*
* @param array $array The input array.
* @throws ArrayException
*
*/
function natsort(array &$array): void
{
error_clear_last();
$result = \natsort($array);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* This function sorts an array in reverse order (highest to lowest).
*
* @param array $array The input array.
* @param int $sort_flags You may modify the behavior of the sort using the optional
* parameter sort_flags, for details see
* sort.
* @throws ArrayException
*
*/
function rsort(array &$array, int $sort_flags = SORT_REGULAR): void
{
error_clear_last();
$result = \rsort($array, $sort_flags);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* This function shuffles (randomizes the order of the elements in) an array.
* It uses a pseudo random number generator that is not suitable for
* cryptographic purposes.
*
* @param array $array The array.
* @throws ArrayException
*
*/
function shuffle(array &$array): void
{
error_clear_last();
$result = \shuffle($array);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* This function sorts an array. Elements will be arranged from
* lowest to highest when this function has completed.
*
* @param array $array The input array.
* @param int $sort_flags The optional second parameter sort_flags
* may be used to modify the sorting behavior using these values:
*
* Sorting type flags:
*
*
* SORT_REGULAR - compare items normally
* (don't change types)
*
*
* SORT_NUMERIC - compare items numerically
*
*
* SORT_STRING - compare items as strings
*
*
*
* SORT_LOCALE_STRING - compare items as
* strings, based on the current locale. It uses the locale,
* which can be changed using setlocale
*
*
*
*
* SORT_NATURAL - compare items as strings
* using "natural ordering" like natsort
*
*
*
*
* SORT_FLAG_CASE - can be combined
* (bitwise OR) with
* SORT_STRING or
* SORT_NATURAL to sort strings case-insensitively
*
*
*
* @throws ArrayException
*
*/
function sort(array &$array, int $sort_flags = SORT_REGULAR): void
{
error_clear_last();
$result = \sort($array, $sort_flags);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* This function sorts an array such that array indices maintain their
* correlation with the array elements they are associated with, using a
* user-defined comparison function.
*
* This is used mainly when sorting associative arrays where the actual
* element order is significant.
*
* @param array $array The input array.
* @param callable $value_compare_func See usort and uksort for
* examples of user-defined comparison functions.
* @throws ArrayException
*
*/
function uasort(array &$array, callable $value_compare_func): void
{
error_clear_last();
$result = \uasort($array, $value_compare_func);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* uksort will sort the keys of an array using a
* user-supplied comparison function. If the array you wish to sort
* needs to be sorted by some non-trivial criteria, you should use
* this function.
*
* @param array $array The input array.
* @param callable $key_compare_func The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
* Note that before PHP 7.0.0 this integer had to be in the range from -2147483648 to 2147483647.
* @throws ArrayException
*
*/
function uksort(array &$array, callable $key_compare_func): void
{
error_clear_last();
$result = \uksort($array, $key_compare_func);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}
/**
* This function will sort an array by its values using a user-supplied
* comparison function. If the array you wish to sort needs to be sorted by
* some non-trivial criteria, you should use this function.
*
* @param array $array The input array.
* @param callable $value_compare_func The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
* Note that before PHP 7.0.0 this integer had to be in the range from -2147483648 to 2147483647.
*
* Returning non-integer values from the comparison
* function, such as float, will result in an internal cast to
* integer of the callback's return value. So values such as
* 0.99 and 0.1 will both be cast to an integer value of 0, which will
* compare such values as equal.
* @throws ArrayException
*
*/
function usort(array &$array, callable $value_compare_func): void
{
error_clear_last();
$result = \usort($array, $value_compare_func);
if ($result === false) {
throw ArrayException::createFromPhpError();
}
}

View file

@ -0,0 +1,99 @@
<?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.
* @return int Returns TRUE on success.
* @throws Bzip2Exception
*
*/
function bzclose($bz): int
{
error_clear_last();
$result = \bzclose($bz);
if ($result === false) {
throw Bzip2Exception::createFromPhpError();
}
return $result;
}
/**
* Forces a write of all buffered bzip2 data for the file pointer
* bz.
*
* @param resource $bz The file pointer. It must be valid and must point to a file
* successfully opened by bzopen.
* @return int Returns TRUE on success.
* @throws Bzip2Exception
*
*/
function bzflush($bz): void
{
error_clear_last();
$result = \bzflush($bz);
if ($result === false) {
throw Bzip2Exception::createFromPhpError();
}
}
/**
* 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();
$result = \bzread($bz, $length);
if ($result === false) {
throw Bzip2Exception::createFromPhpError();
}
return $result;
}
/**
* 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 $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) {
$result = \bzwrite($bz, $data, $length);
} else {
$result = \bzwrite($bz, $data);
}
if ($result === false) {
throw Bzip2Exception::createFromPhpError();
}
return $result;
}

View file

@ -0,0 +1,25 @@
<?php
namespace Safe;
use Safe\Exceptions\ClassobjException;
/**
* Creates an alias named alias
* based on the user defined class original.
* The aliased class is exactly the same as the original class.
*
* @param string $original 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 $original, string $alias, bool $autoload = true): void
{
error_clear_last();
$result = \class_alias($original, $alias, $autoload);
if ($result === false) {
throw ClassobjException::createFromPhpError();
}
}

View file

@ -0,0 +1,133 @@
<?php
namespace Safe;
use Safe\Exceptions\ComException;
/**
* Instructs COM to sink events generated by
* comobject into the PHP object
* sinkobject.
*
* 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 $comobject
* @param object $sinkobject sinkobject 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 $sinkinterface PHP will attempt to use the default dispinterface type specified by
* the typelibrary associated with comobject, but
* you may override this choice by setting
* sinkinterface to the name of the dispinterface
* that you want to use.
* @throws ComException
*
*/
function com_event_sink(variant $comobject, object $sinkobject, $sinkinterface = null): void
{
error_clear_last();
if ($sinkinterface !== null) {
$result = \com_event_sink($comobject, $sinkobject, $sinkinterface);
} else {
$result = \com_event_sink($comobject, $sinkobject);
}
if ($result === 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 configuration setting to pre-load and
* register the constants, although not so flexible.
*
* If you have 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_name typelib_name 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_sensitive The case_sensitive behaves inversely to
* the parameter $case_insensitive in the define
* function.
* @throws ComException
*
*/
function com_load_typelib(string $typelib_name, bool $case_sensitive = true): void
{
error_clear_last();
$result = \com_load_typelib($typelib_name, $case_sensitive);
if ($result === 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 $comobject comobject 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 string $dispinterface The name of an IDispatch descendant interface that you want to display.
* @param bool $wantsink If set to TRUE, the corresponding sink interface will be displayed
* instead.
* @throws ComException
*
*/
function com_print_typeinfo(object $comobject, string $dispinterface = null, bool $wantsink = false): void
{
error_clear_last();
if ($wantsink !== false) {
$result = \com_print_typeinfo($comobject, $dispinterface, $wantsink);
} elseif ($dispinterface !== null) {
$result = \com_print_typeinfo($comobject, $dispinterface);
} else {
$result = \com_print_typeinfo($comobject);
}
if ($result === false) {
throw ComException::createFromPhpError();
}
}

View file

@ -0,0 +1,395 @@
<?php
namespace Safe;
use Safe\Exceptions\CubridException;
/**
* This function frees the memory occupied by the result data. It returns
* TRUE on success. Note that it can only frees the
* client fetch buffer now, and if you want free all memory, use function
* cubrid_close_request.
*
* @param resource $req_identifier This is the request identifier.
* @throws CubridException
*
*/
function cubrid_free_result($req_identifier): void
{
error_clear_last();
$result = \cubrid_free_result($req_identifier);
if ($result === false) {
throw CubridException::createFromPhpError();
}
}
/**
* This function returns the current CUBRID connection charset and is similar
* to the CUBRID MySQL compatible function
* cubrid_client_encoding.
*
* @param resource $conn_identifier The CUBRID connection.
* @return string A string that represents the CUBRID connection charset; on success.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_get_charset($conn_identifier): string
{
error_clear_last();
$result = \cubrid_get_charset($conn_identifier);
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* This function returns a string that represents the client library version.
*
* @return string A string that represents the client library version; on success.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_get_client_info(): string
{
error_clear_last();
$result = \cubrid_get_client_info();
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* This function returns the CUBRID database parameters or it returns FALSE on
* failure. It returns an associative array with the values for the following
* parameters:
*
*
* PARAM_ISOLATION_LEVEL
* PARAM_LOCK_TIMEOUT
* PARAM_MAX_STRING_LENGTH
* PARAM_AUTO_COMMIT
*
*
*
* Database parameters
*
*
*
* Parameter
* Description
*
*
*
*
* PARAM_ISOLATION_LEVEL
* The transaction isolation level.
*
*
* LOCK_TIMEOUT
* CUBRID provides the lock timeout feature, which sets the waiting
* time (in seconds) for the lock until the transaction lock setting is
* allowed. The default value of the lock_timeout_in_secs parameter is
* -1, which means the application client will wait indefinitely until
* the transaction lock is allowed.
*
*
*
* PARAM_AUTO_COMMIT
* In CUBRID PHP, auto-commit mode is disabled by default for
* transaction management. It can be set by using
* cubrid_set_autocommit.
*
*
*
*
*
*
* The following table shows the isolation levels from 1 to 6. It consists of
* table schema (row) and isolation level:
*
* Levels of Isolation Supported by CUBRID
*
*
*
* Name
* Description
*
*
*
*
* SERIALIZABLE (6)
* In this isolation level, problems concerning concurrency (e.g.
* dirty read, non-repeatable read, phantom read, etc.) do not
* occur.
*
*
* REPEATABLE READ CLASS with REPEATABLE READ INSTANCES (5)
* Another transaction T2 cannot update the schema of table A while
* transaction T1 is viewing table A.
* Transaction T1 may experience phantom read for the record R that was
* inserted by another transaction T2 when it is repeatedly retrieving a
* specific record.
*
*
* REPEATABLE READ CLASS with READ COMMITTED INSTANCES (or CURSOR STABILITY) (4)
* Another transaction T2 cannot update the schema of table A while
* transaction T1 is viewing table A.
* Transaction T1 may experience R read (non-repeatable read) that was
* updated and committed by another transaction T2 when it is repeatedly
* retrieving the record R.
*
*
* REPEATABLE READ CLASS with READ UNCOMMITTED INSTANCES (3)
* Default isolation level. Another transaction T2 cannot update
* the schema of table A while transaction T1 is viewing table A.
* Transaction T1 may experience R' read (dirty read) for the record that
* was updated but not committed by another transaction T2.
*
*
* READ COMMITTED CLASS with READ COMMITTED INSTANCES (2)
* Transaction T1 may experience A' read (non-repeatable read) for
* the table that was updated and committed by another transaction T2
* while it is viewing table A repeatedly. Transaction T1 may experience
* R' read (non-repeatable read) for the record that was updated and
* committed by another transaction T2 while it is retrieving the record
* R repeatedly.
*
*
* READ COMMITTED CLASS with READ UNCOMMITTED INSTANCES (1)
* Transaction T1 may experience A' read (non-repeatable read) for
* the table that was updated and committed by another transaction T2
* while it is repeatedly viewing table A. Transaction T1 may experience
* R' read (dirty read) for the record that was updated but not committed
* by another transaction T2.
*
*
*
*
*
* @param resource $conn_identifier The CUBRID connection. If the connection identifier is not specified,
* the last link opened by cubrid_connect is assumed.
* @return array An associative array with CUBRID database parameters; on success.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_get_db_parameter($conn_identifier): array
{
error_clear_last();
$result = \cubrid_get_db_parameter($conn_identifier);
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* This function returns a string that represents the CUBRID server version.
*
* @param resource $conn_identifier The CUBRID connection.
* @return string A string that represents the CUBRID server version; on success.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_get_server_info($conn_identifier): string
{
error_clear_last();
$result = \cubrid_get_server_info($conn_identifier);
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* The cubrid_insert_id function retrieves the ID
* generated for the AUTO_INCREMENT column which is updated by the previous
* INSERT query. It returns 0 if the previous query does not generate new
* rows.
*
* @param resource $conn_identifier The connection identifier previously obtained by a call to
* cubrid_connect.
* @return string A string representing the ID generated for an AUTO_INCREMENT column by the
* previous query, on success.
*
* 0, if the previous query does not generate new rows.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_insert_id($conn_identifier = null): string
{
error_clear_last();
if ($conn_identifier !== null) {
$result = \cubrid_insert_id($conn_identifier);
} else {
$result = \cubrid_insert_id();
}
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* The cubrid_lob2_new function is used to create a lob object (both BLOB and CLOB).
* This function should be used before you bind a lob object.
*
* @param resource $conn_identifier Connection identifier. If the connection identifier is not specified,
* the last connection opened by cubrid_connect or
* cubrid_connect_with_url is assumed.
* @param string $type It may be "BLOB" or "CLOB", it won't be case-sensitive. The default value is "BLOB".
* @return resource Lob identifier when it is successful.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_lob2_new($conn_identifier = null, string $type = "BLOB")
{
error_clear_last();
if ($type !== "BLOB") {
$result = \cubrid_lob2_new($conn_identifier, $type);
} elseif ($conn_identifier !== null) {
$result = \cubrid_lob2_new($conn_identifier);
} else {
$result = \cubrid_lob2_new();
}
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* The cubrid_lob2_size function is used to get the size of a lob object.
*
* @param resource $lob_identifier Lob identifier as a result of cubrid_lob2_new or get from the result set.
* @return int It will return the size of the LOB object when it processes successfully.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_lob2_size($lob_identifier): int
{
error_clear_last();
$result = \cubrid_lob2_size($lob_identifier);
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* The cubrid_lob2_size64 function is used to get the
* size of a lob object. If the size of a lob object is larger than an
* integer data can be stored, you can use this function and it will return
* the size as a string.
*
* @param resource $lob_identifier Lob identifier as a result of cubrid_lob2_new or get from the result set.
* @return string It will return the size of the LOB object as a string when it processes successfully.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_lob2_size64($lob_identifier): string
{
error_clear_last();
$result = \cubrid_lob2_size64($lob_identifier);
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* The cubrid_lob2_tell function is used to tell the cursor position of the LOB object.
*
* @param resource $lob_identifier Lob identifier as a result of cubrid_lob2_new or get from the result set.
* @return int It will return the cursor position on the LOB object when it processes successfully.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_lob2_tell($lob_identifier): int
{
error_clear_last();
$result = \cubrid_lob2_tell($lob_identifier);
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* The cubrid_lob2_tell64 function is used to tell the
* cursor position of the LOB object. If the size of a lob object is larger
* than an integer data can be stored, you can use this function and it will
* return the position information as a string.
*
* @param resource $lob_identifier Lob identifier as a result of cubrid_lob2_new or get from the result set.
* @return string It will return the cursor position on the LOB object as a string when it processes successfully.
*
* FALSE on failure.
* @throws CubridException
*
*/
function cubrid_lob2_tell64($lob_identifier): string
{
error_clear_last();
$result = \cubrid_lob2_tell64($lob_identifier);
if ($result === false) {
throw CubridException::createFromPhpError();
}
return $result;
}
/**
* The cubrid_set_db_parameter function is used to set
* the CUBRID database parameters. It can set the following CUBRID database
* parameters:
*
*
* PARAM_ISOLATION_LEVEL
* PARAM_LOCK_TIMEOUT
*
*
* @param resource $conn_identifier The CUBRID connection. If the connection identifier is not specified,
* the last link opened by cubrid_connect is assumed.
* @param int $param_type Database parameter type.
* @param int $param_value Isolation level value (1-6) or lock timeout (in seconds) value.
* @throws CubridException
*
*/
function cubrid_set_db_parameter($conn_identifier, int $param_type, int $param_value): void
{
error_clear_last();
$result = \cubrid_set_db_parameter($conn_identifier, $param_type, $param_value);
if ($result === false) {
throw CubridException::createFromPhpError();
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,567 @@
<?php
namespace Safe;
use Safe\Exceptions\DatetimeException;
/**
* Returns associative array with detailed info about given date.
*
* @param string $format Format accepted by DateTime::createFromFormat.
* @param string $date String representing the date.
* @return array Returns associative array with detailed info about given date.
* @throws DatetimeException
*
*/
function date_parse_from_format(string $format, string $date): array
{
error_clear_last();
$result = \date_parse_from_format($format, $date);
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}
/**
*
*
* @param string $date Date in format accepted by strtotime.
* @return array Returns array with information about the parsed date
* on success.
* @throws DatetimeException
*
*/
function date_parse(string $date): array
{
error_clear_last();
$result = \date_parse($date);
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}
/**
*
*
* @param int $time Timestamp.
* @param float $latitude Latitude in degrees.
* @param float $longitude Longitude in degrees.
* @return array Returns array on success.
* The structure of the array is detailed in the following list:
*
*
*
* sunrise
*
*
* The time of the sunrise (zenith angle = 90°35').
*
*
*
*
* sunset
*
*
* The time of the sunset (zenith angle = 90°35').
*
*
*
*
* transit
*
*
* The time when the sun is at its zenith, i.e. has reached its topmost
* point.
*
*
*
*
* civil_twilight_begin
*
*
* The start of the civil dawn (zenith angle = 96°). It ends at sunrise.
*
*
*
*
* civil_twilight_end
*
*
* The end of the civil dusk (zenith angle = 96°). It starts at sunset.
*
*
*
*
* nautical_twilight_begin
*
*
* The start of the nautical dawn (zenith angle = 102°). It ends at
* civil_twilight_begin.
*
*
*
*
* nautical_twilight_end
*
*
* The end of the nautical dusk (zenith angle = 102°). It starts at
* civil_twilight_end.
*
*
*
*
* astronomical_twilight_begin
*
*
* The start of the astronomical dawn (zenith angle = 108°). It ends at
* nautical_twilight_begin.
*
*
*
*
* astronomical_twilight_end
*
*
* The end of the astronomical dusk (zenith angle = 108°). It starts at
* nautical_twilight_end.
*
*
*
*
*
* The values of the array elements are either UNIX timestamps, FALSE if the
* sun is below the respective zenith for the whole day, or TRUE if the sun is
* above the respective zenith for the whole day.
* @throws DatetimeException
*
*/
function date_sun_info(int $time, float $latitude, float $longitude): array
{
error_clear_last();
$result = \date_sun_info($time, $latitude, $longitude);
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}
/**
* date_sunrise returns the sunrise time for a given
* day (specified as a timestamp) and location.
*
* @param int $timestamp The timestamp of the day from which the sunrise
* time is taken.
* @param int $format
* format constants
*
*
*
* constant
* description
* example
*
*
*
*
* SUNFUNCS_RET_STRING
* returns the result as string
* 16:46
*
*
* SUNFUNCS_RET_DOUBLE
* returns the result as float
* 16.78243132
*
*
* SUNFUNCS_RET_TIMESTAMP
* returns the result as integer (timestamp)
* 1095034606
*
*
*
*
* @param float $latitude Defaults to North, pass in a negative value for South.
* See also: date.default_latitude
* @param float $longitude Defaults to East, pass in a negative value for West.
* See also: date.default_longitude
* @param float $zenith zenith is the angle between the center of the sun
* and a line perpendicular to earth's surface. It defaults to
* date.sunrise_zenith
*
* Common zenith angles
*
*
*
* Angle
* Description
*
*
*
*
* 90°50'
* Sunrise: the point where the sun becomes visible.
*
*
* 96°
* Civil twilight: conventionally used to signify the start of dawn.
*
*
* 102°
* Nautical twilight: the point at which the horizon starts being visible at sea.
*
*
* 108°
* Astronomical twilight: the point at which the sun starts being the source of any illumination.
*
*
*
*
* @param float $gmt_offset Specified in hours.
* The gmtoffset is ignored, if
* format is
* SUNFUNCS_RET_TIMESTAMP.
* @return mixed Returns the sunrise time in a specified format on
* success. One potential reason for failure is that the
* sun does not rise at all, which happens inside the polar circles for part of
* the year.
* @throws DatetimeException
*
*/
function date_sunrise(int $timestamp, int $format = SUNFUNCS_RET_STRING, float $latitude = null, float $longitude = null, float $zenith = null, float $gmt_offset = 0)
{
error_clear_last();
if ($gmt_offset !== 0) {
$result = \date_sunrise($timestamp, $format, $latitude, $longitude, $zenith, $gmt_offset);
} elseif ($zenith !== null) {
$result = \date_sunrise($timestamp, $format, $latitude, $longitude, $zenith);
} elseif ($longitude !== null) {
$result = \date_sunrise($timestamp, $format, $latitude, $longitude);
} elseif ($latitude !== null) {
$result = \date_sunrise($timestamp, $format, $latitude);
} else {
$result = \date_sunrise($timestamp, $format);
}
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}
/**
* date_sunset returns the sunset time for a given
* day (specified as a timestamp) and location.
*
* @param int $timestamp The timestamp of the day from which the sunset
* time is taken.
* @param int $format
* format constants
*
*
*
* constant
* description
* example
*
*
*
*
* SUNFUNCS_RET_STRING
* returns the result as string
* 16:46
*
*
* SUNFUNCS_RET_DOUBLE
* returns the result as float
* 16.78243132
*
*
* SUNFUNCS_RET_TIMESTAMP
* returns the result as integer (timestamp)
* 1095034606
*
*
*
*
* @param float $latitude Defaults to North, pass in a negative value for South.
* See also: date.default_latitude
* @param float $longitude Defaults to East, pass in a negative value for West.
* See also: date.default_longitude
* @param float $zenith zenith is the angle between the center of the sun
* and a line perpendicular to earth's surface. It defaults to
* date.sunset_zenith
*
* Common zenith angles
*
*
*
* Angle
* Description
*
*
*
*
* 90°50'
* Sunset: the point where the sun becomes invisible.
*
*
* 96°
* Civil twilight: conventionally used to signify the end of dusk.
*
*
* 102°
* Nautical twilight: the point at which the horizon ends being visible at sea.
*
*
* 108°
* Astronomical twilight: the point at which the sun ends being the source of any illumination.
*
*
*
*
* @param float $gmt_offset Specified in hours.
* The gmtoffset is ignored, if
* format is
* SUNFUNCS_RET_TIMESTAMP.
* @return mixed Returns the sunset time in a specified format on
* success. One potential reason for failure is that the
* sun does not set at all, which happens inside the polar circles for part of
* the year.
* @throws DatetimeException
*
*/
function date_sunset(int $timestamp, int $format = SUNFUNCS_RET_STRING, float $latitude = null, float $longitude = null, float $zenith = null, float $gmt_offset = 0)
{
error_clear_last();
if ($gmt_offset !== 0) {
$result = \date_sunset($timestamp, $format, $latitude, $longitude, $zenith, $gmt_offset);
} elseif ($zenith !== null) {
$result = \date_sunset($timestamp, $format, $latitude, $longitude, $zenith);
} elseif ($longitude !== null) {
$result = \date_sunset($timestamp, $format, $latitude, $longitude);
} elseif ($latitude !== null) {
$result = \date_sunset($timestamp, $format, $latitude);
} else {
$result = \date_sunset($timestamp, $format);
}
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}
/**
* Returns the Unix timestamp corresponding to the arguments
* given. This timestamp is a long integer containing the number of
* seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time
* specified.
*
* Arguments may be left out in order from right to left; any
* arguments thus omitted will be set to the current value according
* to the local date and time.
*
* @param int $hour The number of the hour relative to the start of the day determined by
* month, day and year.
* Negative values reference the hour before midnight of the day in question.
* Values greater than 23 reference the appropriate hour in the following day(s).
* @param int $minute The number of the minute relative to the start of the hour.
* Negative values reference the minute in the previous hour.
* Values greater than 59 reference the appropriate minute in the following hour(s).
* @param int $second The number of seconds relative to the start of the minute.
* Negative values reference the second in the previous minute.
* Values greater than 59 reference the appropriate second in the following minute(s).
* @param int $month The number of the month relative to the end of the previous year.
* Values 1 to 12 reference the normal calendar months of the year in question.
* Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc.
* Values greater than 12 reference the appropriate month in the following year(s).
* @param int $day The number of the day relative to the end of the previous month.
* Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month.
* Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc.
* Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).
* @param int $year The number of the year, may be a two or four digit value,
* with values between 0-69 mapping to 2000-2069 and 70-100 to
* 1970-2000. On systems where time_t is a 32bit signed integer, as
* most common today, the valid range for year
* is somewhere between 1901 and 2038. However, before PHP 5.1.0 this
* range was limited from 1970 to 2038 on some systems (e.g. Windows).
* @return int mktime returns the Unix timestamp of the arguments
* given.
* If the arguments are invalid, the function returns FALSE (before PHP 5.1
* it returned -1).
* @throws DatetimeException
*
*/
function mktime(int $hour = null, int $minute = null, int $second = null, int $month = null, int $day = null, int $year = null): int
{
error_clear_last();
if ($year !== null) {
$result = \mktime($hour, $minute, $second, $month, $day, $year);
} elseif ($day !== null) {
$result = \mktime($hour, $minute, $second, $month, $day);
} elseif ($month !== null) {
$result = \mktime($hour, $minute, $second, $month);
} elseif ($second !== null) {
$result = \mktime($hour, $minute, $second);
} elseif ($minute !== null) {
$result = \mktime($hour, $minute);
} elseif ($hour !== null) {
$result = \mktime($hour);
} else {
$result = \mktime();
}
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}
/**
* strptime returns an array with the
* date parsed.
*
* Month and weekday names and other language dependent strings respect the
* current locale set with setlocale (LC_TIME).
*
* @param string $date The string to parse (e.g. returned from strftime).
* @param string $format The format used in date (e.g. the same as
* used in strftime). Note that some of the format
* options available to strftime may not have any
* effect within strptime; the exact subset that are
* supported will vary based on the operating system and C library in
* use.
*
* For more information about the format options, read the
* strftime page.
* @return array Returns an array.
*
*
* The following parameters are returned in the array
*
*
*
* parameters
* Description
*
*
*
*
* "tm_sec"
* Seconds after the minute (0-61)
*
*
* "tm_min"
* Minutes after the hour (0-59)
*
*
* "tm_hour"
* Hour since midnight (0-23)
*
*
* "tm_mday"
* Day of the month (1-31)
*
*
* "tm_mon"
* Months since January (0-11)
*
*
* "tm_year"
* Years since 1900
*
*
* "tm_wday"
* Days since Sunday (0-6)
*
*
* "tm_yday"
* Days since January 1 (0-365)
*
*
* "unparsed"
* the date part which was not
* recognized using the specified format
*
*
*
*
* @throws DatetimeException
*
*/
function strptime(string $date, string $format): array
{
error_clear_last();
$result = \strptime($date, $format);
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}
/**
* Each parameter of this function uses the default time zone unless a
* time zone is specified in that parameter. Be careful not to use
* different time zones in each parameter unless that is intended.
* See date_default_timezone_get on the various
* ways to define the default time zone.
*
* @param string $time A date/time string. Valid formats are explained in Date and Time Formats.
* @param int $now The timestamp which is used as a base for the calculation of relative
* dates.
* @return int Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0,
* this function would return -1 on failure.
* @throws DatetimeException
*
*/
function strtotime(string $time, int $now = null): int
{
error_clear_last();
if ($now !== null) {
$result = \strtotime($time, $now);
} else {
$result = \strtotime($time);
}
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}
/**
*
*
* @param string $abbr Time zone abbreviation.
* @param int $gmtOffset Offset from GMT in seconds. Defaults to -1 which means that first found
* time zone corresponding to abbr is returned.
* Otherwise exact offset is searched and only if not found then the first
* time zone with any offset is returned.
* @param int $isdst Daylight saving time indicator. Defaults to -1, which means that
* whether the time zone has daylight saving or not is not taken into
* consideration when searching. If this is set to 1, then the
* gmtOffset is assumed to be an offset with
* daylight saving in effect; if 0, then gmtOffset
* is assumed to be an offset without daylight saving in effect. If
* abbr doesn't exist then the time zone is
* searched solely by the gmtOffset and
* isdst.
* @return string Returns time zone name on success.
* @throws DatetimeException
*
*/
function timezone_name_from_abbr(string $abbr, int $gmtOffset = -1, int $isdst = -1): string
{
error_clear_last();
$result = \timezone_name_from_abbr($abbr, $gmtOffset, $isdst);
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}

View file

@ -0,0 +1,194 @@
<?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();
$result = \chdir($directory);
if ($result === 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.
*
* @param string $directory The path to change the root directory to.
* @throws DirException
*
*/
function chroot(string $directory): void
{
error_clear_last();
$result = \chroot($directory);
if ($result === false) {
throw DirException::createFromPhpError();
}
}
/**
* Gets the current working directory.
*
* @return 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();
$result = \getcwd();
if ($result === false) {
throw DirException::createFromPhpError();
}
return $result;
}
/**
* Opens up a directory handle to be used in subsequent
* closedir, readdir, and
* rewinddir calls.
*
* @param string $path The directory path that is to be opened
* @param 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.
*
* If path is not a valid directory or the
* directory can not be opened due to permission restrictions or
* filesystem errors, opendir returns FALSE and
* generates a PHP error of level
* E_WARNING. You can suppress the error output of
* opendir by prepending
* '@' to the
* front of the function name.
* @throws DirException
*
*/
function opendir(string $path, $context = null)
{
error_clear_last();
if ($context !== null) {
$result = \opendir($path, $context);
} else {
$result = \opendir($path);
}
if ($result === false) {
throw DirException::createFromPhpError();
}
return $result;
}
/**
* Returns the name of the next entry in the directory. The
* entries are returned in the order in which they are stored by
* the filesystem.
*
* @param resource $dir_handle The directory handle resource previously opened
* with opendir. If the directory handle is
* not specified, the last link opened by opendir
* is assumed.
* @return string Returns the entry name on success.
* @throws DirException
*
*/
function readdir($dir_handle = null): string
{
error_clear_last();
if ($dir_handle !== null) {
$result = \readdir($dir_handle);
} else {
$result = \readdir();
}
if ($result === false) {
throw DirException::createFromPhpError();
}
return $result;
}
/**
* Resets the directory stream indicated by
* dir_handle to the beginning of the
* directory.
*
* @param resource $dir_handle The directory handle resource previously opened
* with opendir. If the directory handle is
* not specified, the last link opened by opendir
* is assumed.
* @throws DirException
*
*/
function rewinddir($dir_handle = null): void
{
error_clear_last();
if ($dir_handle !== null) {
$result = \rewinddir($dir_handle);
} else {
$result = \rewinddir();
}
if ($result === false) {
throw DirException::createFromPhpError();
}
}
/**
* Returns an array of files and directories from the
* directory.
*
* @param string $directory The directory that will be scanned.
* @param int $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 resource $context For a description of the context parameter,
* refer to the streams section of
* the manual.
* @return array 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) {
$result = \scandir($directory, $sorting_order, $context);
} else {
$result = \scandir($directory, $sorting_order);
}
if ($result === false) {
throw DirException::createFromPhpError();
}
return $result;
}

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 int $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,
* extra_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 string $destination The destination. Its meaning depends on the
* message_type parameter as described above.
* @param string $extra_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 $extra_headers = null): void
{
error_clear_last();
if ($extra_headers !== null) {
$result = \error_log($message, $message_type, $destination, $extra_headers);
} elseif ($destination !== null) {
$result = \error_log($message, $message_type, $destination);
} else {
$result = \error_log($message, $message_type);
}
if ($result === false) {
throw ErrorfuncException::createFromPhpError();
}
}

View file

@ -0,0 +1,159 @@
<?php
namespace Safe;
use Safe\Exceptions\ExecException;
/**
* proc_get_status fetches data about a
* process opened using proc_open.
*
* @param resource $process The proc_open resource that will
* be evaluated.
* @return array An array of collected information on success. The returned array contains the following elements:
*
*
*
*
* elementtypedescription
*
*
*
* command
* string
*
* The command string that was passed to proc_open.
*
*
*
* pid
* int
* process id
*
*
* running
* bool
*
* TRUE if the process is still running, FALSE if it has
* terminated.
*
*
*
* signaled
* bool
*
* TRUE if the child process has been terminated by
* an uncaught signal. Always set to FALSE on Windows.
*
*
*
* stopped
* bool
*
* TRUE if the child process has been stopped by a
* signal. Always set to FALSE on Windows.
*
*
*
* exitcode
* int
*
* The exit code returned by the process (which is only
* meaningful if running is FALSE).
* Only first call of this function return real value, next calls return
* -1.
*
*
*
* termsig
* int
*
* The number of the signal that caused the child process to terminate
* its execution (only meaningful if signaled is TRUE).
*
*
*
* stopsig
* int
*
* The number of the signal that caused the child process to stop its
* execution (only meaningful if stopped is TRUE).
*
*
*
*
*
* @throws ExecException
*
*/
function proc_get_status($process): array
{
error_clear_last();
$result = \proc_get_status($process);
if ($result === false) {
throw ExecException::createFromPhpError();
}
return $result;
}
/**
* proc_nice changes the priority of the current
* process by the amount specified in increment. A
* positive increment will lower the priority of the
* current process, whereas a negative increment
* will raise the priority.
*
* proc_nice is not related to
* proc_open and its associated functions in any way.
*
* @param int $increment The new priority value, the value of this may differ on platforms.
*
* On Unix, a low value, such as -20 means high priority
* wheras a positive value have a lower priority.
*
* For Windows the increment parameter have the
* following meanings:
* @throws ExecException
*
*/
function proc_nice(int $increment): void
{
error_clear_last();
$result = \proc_nice($increment);
if ($result === false) {
throw ExecException::createFromPhpError();
}
}
/**
* 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 $return_var If the return_var 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 &$return_var = null): string
{
error_clear_last();
$result = \system($command, $return_var);
if ($result === false) {
throw ExecException::createFromPhpError();
}
return $result;
}

View file

@ -0,0 +1,75 @@
<?php
namespace Safe;
use Safe\Exceptions\FileinfoException;
/**
* This function closes the resource opened by finfo_open.
*
* @param resource $finfo Fileinfo resource returned by finfo_open.
* @throws FileinfoException
*
*/
function finfo_close($finfo): void
{
error_clear_last();
$result = \finfo_close($finfo);
if ($result === false) {
throw FileinfoException::createFromPhpError();
}
}
/**
* Procedural style
*
* Object oriented style (constructor):
*
* This function opens a magic database and returns its resource.
*
* @param int $options One or disjunction of more Fileinfo
* constants.
* @param string $magic_file 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 resource (Procedural style only)
* Returns a magic database resource on success.
* @throws FileinfoException
*
*/
function finfo_open(int $options = FILEINFO_NONE, ?string $magic_file = null)
{
error_clear_last();
$result = \finfo_open($options, $magic_file);
if ($result === false) {
throw FileinfoException::createFromPhpError();
}
return $result;
}
/**
* Returns the MIME content type for a file as determined by using
* information from the magic.mime file.
*
* @param 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(string $filename): string
{
error_clear_last();
$result = \mime_content_type($filename);
if ($result === false) {
throw FileinfoException::createFromPhpError();
}
return $result;
}

File diff suppressed because it is too large Load diff

Some files were not shown because too many files have changed in this diff Show more