Update website

This commit is contained in:
Guilhem Lavaux 2024-11-23 20:45:29 +01:00
parent 41ce1aa076
commit ea0eb1c6e0
4222 changed files with 721797 additions and 14 deletions

View file

@ -0,0 +1,11 @@
<?php
namespace Safe\Exceptions;
class ApcException extends \ErrorException implements SafeExceptionInterface
{
public static function createFromPhpError(): self
{
$error = error_get_last();
return new self($error['message'] ?? 'An error occured', 0, $error['type'] ?? 1);
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Safe\Exceptions;
class LibeventException extends \ErrorException implements SafeExceptionInterface
{
public static function createFromPhpError(): self
{
$error = error_get_last();
return new self($error['message'] ?? 'An error occured', 0, $error['type'] ?? 1);
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Safe\Exceptions;
class MssqlException extends \ErrorException implements SafeExceptionInterface
{
public static function createFromPhpError(): self
{
$error = error_get_last();
return new self($error['message'] ?? 'An error occured', 0, $error['type'] ?? 1);
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Safe\Exceptions;
class StatsException extends \ErrorException implements SafeExceptionInterface
{
public static function createFromPhpError(): self
{
$error = error_get_last();
return new self($error['message'] ?? 'An error occured', 0, $error['type'] ?? 1);
}
}

View file

@ -0,0 +1,238 @@
<?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|null $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($key): void
{
error_clear_last();
$result = \apc_delete($key);
if ($result === false) {
throw ApcException::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|null $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,56 @@
<?php
return [
'apc_cache_info',
'apc_cas',
'apc_compile_file',
'apc_dec',
'apc_define_constants',
'apc_delete',
'apc_delete_file',
'apc_inc',
'apc_load_constants',
'apc_sma_info',
'event_add',
'event_base_loopbreak',
'event_base_loopexit',
'event_base_new',
'event_base_priority_init',
'event_base_reinit',
'event_base_set',
'event_buffer_base_set',
'event_buffer_disable',
'event_buffer_enable',
'event_buffer_new',
'event_buffer_priority_set',
'event_buffer_set_callback',
'event_buffer_write',
'event_del',
'event_new',
'event_priority_set',
'event_set',
'event_timer_set',
'imagepsencodefont',
'imagepsextendfont',
'imagepsfreefont',
'imagepsslantfont',
'mssql_bind',
'mssql_close',
'mssql_connect',
'mssql_data_seek',
'mssql_field_length',
'mssql_field_name',
'mssql_field_seek',
'mssql_field_type',
'mssql_free_result',
'mssql_free_statement',
'mssql_init',
'mssql_pconnect',
'mssql_query',
'mssql_select_db',
'stats_covariance',
'stats_standard_deviation',
'stats_stat_correlation',
'stats_stat_innerproduct',
'stats_variance',
];

View file

@ -0,0 +1,496 @@
<?php
namespace Safe;
use Safe\Exceptions\LibeventException;
/**
* event_add schedules the execution of the event
* when the event specified in event_set occurs or in at least the time
* specified by the timeout argument. If
* timeout was not specified, not timeout is set. The
* event must be already initalized by event_set
* and event_base_set functions. If the
* event already has a timeout set, it is replaced by
* the new one.
*
* @param resource $event Valid event resource.
* @param int $timeout Optional timeout (in microseconds).
* @throws LibeventException
*
*/
function event_add($event, int $timeout = -1): void
{
error_clear_last();
$result = \event_add($event, $timeout);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Abort the active event loop immediately. The behaviour is similar to
* break statement.
*
* @param resource $event_base Valid event base resource.
* @throws LibeventException
*
*/
function event_base_loopbreak($event_base): void
{
error_clear_last();
$result = \event_base_loopbreak($event_base);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* The next event loop iteration after the given timer expires will complete
* normally, then exit without blocking for events again.
*
* @param resource $event_base Valid event base resource.
* @param int $timeout Optional timeout parameter (in microseconds).
* @throws LibeventException
*
*/
function event_base_loopexit($event_base, int $timeout = -1): void
{
error_clear_last();
$result = \event_base_loopexit($event_base, $timeout);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Returns new event base, which can be used later in event_base_set,
* event_base_loop and other functions.
*
* @return resource event_base_new returns valid event base resource on
* success.
* @throws LibeventException
*
*/
function event_base_new()
{
error_clear_last();
$result = \event_base_new();
if ($result === false) {
throw LibeventException::createFromPhpError();
}
return $result;
}
/**
* Sets the number of different event priority levels.
*
* By default all events are scheduled with the same priority
* (npriorities/2).
* Using event_base_priority_init you can change the number
* of event priority levels and then set a desired priority for each event.
*
* @param resource $event_base Valid event base resource.
* @param int $npriorities The number of event priority levels.
* @throws LibeventException
*
*/
function event_base_priority_init($event_base, int $npriorities): void
{
error_clear_last();
$result = \event_base_priority_init($event_base, $npriorities);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Some event mechanisms do not survive across fork. The
* event_base needs to be reinitialized with this
* function.
*
* @param resource $event_base Valid event base resource that needs to be re-initialized.
* @throws LibeventException
*
*/
function event_base_reinit($event_base): void
{
error_clear_last();
$result = \event_base_reinit($event_base);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Associates the event_base with the
* event.
*
* @param resource $event Valid event resource.
* @param resource $event_base Valid event base resource.
* @throws LibeventException
*
*/
function event_base_set($event, $event_base): void
{
error_clear_last();
$result = \event_base_set($event, $event_base);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Assign the specified bevent to the
* event_base.
*
* @param resource $bevent Valid buffered event resource.
* @param resource $event_base Valid event base resource.
* @throws LibeventException
*
*/
function event_buffer_base_set($bevent, $event_base): void
{
error_clear_last();
$result = \event_buffer_base_set($bevent, $event_base);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Disables the specified buffered event.
*
* @param resource $bevent Valid buffered event resource.
* @param int $events Any combination of EV_READ and
* EV_WRITE.
* @throws LibeventException
*
*/
function event_buffer_disable($bevent, int $events): void
{
error_clear_last();
$result = \event_buffer_disable($bevent, $events);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Enables the specified buffered event.
*
* @param resource $bevent Valid buffered event resource.
* @param int $events Any combination of EV_READ and
* EV_WRITE.
* @throws LibeventException
*
*/
function event_buffer_enable($bevent, int $events): void
{
error_clear_last();
$result = \event_buffer_enable($bevent, $events);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Libevent provides an abstraction layer on top of the regular event API.
* Using buffered event you don't need to deal with the I/O manually, instead
* it provides input and output buffers that get filled and drained
* automatically.
*
* @param resource $stream Valid PHP stream resource. Must be castable to file descriptor.
* @param mixed $readcb Callback to invoke where there is data to read, or NULL if
* no callback is desired.
* @param mixed $writecb Callback to invoke where the descriptor is ready for writing,
* or NULL if no callback is desired.
* @param mixed $errorcb Callback to invoke where there is an error on the descriptor, cannot be
* NULL.
* @param mixed $arg An argument that will be passed to each of the callbacks (optional).
* @return resource event_buffer_new returns new buffered event resource
* on success.
* @throws LibeventException
*
*/
function event_buffer_new($stream, $readcb, $writecb, $errorcb, $arg = null)
{
error_clear_last();
if ($arg !== null) {
$result = \event_buffer_new($stream, $readcb, $writecb, $errorcb, $arg);
} else {
$result = \event_buffer_new($stream, $readcb, $writecb, $errorcb);
}
if ($result === false) {
throw LibeventException::createFromPhpError();
}
return $result;
}
/**
* Assign a priority to the bevent.
*
* @param resource $bevent Valid buffered event resource.
* @param int $priority Priority level. Cannot be less than zero and cannot exceed maximum
* priority level of the event base (see event_base_priority_init).
* @throws LibeventException
*
*/
function event_buffer_priority_set($bevent, int $priority): void
{
error_clear_last();
$result = \event_buffer_priority_set($bevent, $priority);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Sets or changes existing callbacks for the buffered event.
*
* @param resource $event Valid buffered event resource.
* @param mixed $readcb Callback to invoke where there is data to read, or NULL if
* no callback is desired.
* @param mixed $writecb Callback to invoke where the descriptor is ready for writing,
* or NULL if no callback is desired.
* @param mixed $errorcb Callback to invoke where there is an error on the descriptor, cannot be
* NULL.
* @param mixed $arg An argument that will be passed to each of the callbacks (optional).
* @throws LibeventException
*
*/
function event_buffer_set_callback($event, $readcb, $writecb, $errorcb, $arg = null): void
{
error_clear_last();
if ($arg !== null) {
$result = \event_buffer_set_callback($event, $readcb, $writecb, $errorcb, $arg);
} else {
$result = \event_buffer_set_callback($event, $readcb, $writecb, $errorcb);
}
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Writes data to the specified buffered event. The data is appended to the
* output buffer and written to the descriptor when it becomes available for
* writing.
*
* @param resource $bevent Valid buffered event resource.
* @param string $data The data to be written.
* @param int $data_size Optional size parameter. event_buffer_write writes
* all the data by default.
* @throws LibeventException
*
*/
function event_buffer_write($bevent, string $data, int $data_size = -1): void
{
error_clear_last();
$result = \event_buffer_write($bevent, $data, $data_size);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Cancels the event.
*
* @param resource $event Valid event resource.
* @throws LibeventException
*
*/
function event_del($event): void
{
error_clear_last();
$result = \event_del($event);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Creates and returns a new event resource.
*
* @return resource event_new returns a new event resource on success.
* @throws LibeventException
*
*/
function event_new()
{
error_clear_last();
$result = \event_new();
if ($result === false) {
throw LibeventException::createFromPhpError();
}
return $result;
}
/**
* Assign a priority to the event.
*
* @param resource $event Valid event resource.
* @param int $priority Priority level. Cannot be less than zero and cannot exceed maximum
* priority level of the event base (see
* event_base_priority_init).
* @throws LibeventException
*
*/
function event_priority_set($event, int $priority): void
{
error_clear_last();
$result = \event_priority_set($event, $priority);
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Prepares the event to be used in event_add. The event
* is prepared to call the function specified by the callback
* on the events specified in parameter events, which
* is a set of the following flags: EV_TIMEOUT,
* EV_SIGNAL, EV_READ,
* EV_WRITE and EV_PERSIST.
*
* If EV_SIGNAL bit is set in parameter events,
* the fd is interpreted as signal number.
*
* After initializing the event, use event_base_set to
* associate the event with its event base.
*
* In case of matching event, these three arguments are passed to the
* callback function:
*
*
* fd
*
*
* Signal number or resource indicating the stream.
*
*
*
*
* events
*
*
* A flag indicating the event. Consists of the following flags:
* EV_TIMEOUT, EV_SIGNAL,
* EV_READ, EV_WRITE
* and EV_PERSIST.
*
*
*
*
* arg
*
*
* Optional parameter, previously passed to event_set
* as arg.
*
*
*
*
*
* @param resource $event Valid event resource.
* @param mixed $fd Valid PHP stream resource. The stream must be castable to file
* descriptor, so you most likely won't be able to use any of filtered
* streams.
* @param int $events A set of flags indicating the desired event, can be
* EV_READ and/or EV_WRITE.
* The additional flag EV_PERSIST makes the event
* to persist until event_del is called, otherwise
* the callback is invoked only once.
* @param mixed $callback Callback function to be called when the matching event occurs.
* @param mixed $arg Optional callback parameter.
* @throws LibeventException
*
*/
function event_set($event, $fd, int $events, $callback, $arg = null): void
{
error_clear_last();
if ($arg !== null) {
$result = \event_set($event, $fd, $events, $callback, $arg);
} else {
$result = \event_set($event, $fd, $events, $callback);
}
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}
/**
* Prepares the timer event to be used in event_add. The
* event is prepared to call the function specified by the
* callback when the event timeout elapses.
*
* After initializing the event, use event_base_set to
* associate the event with its event base.
*
* In case of matching event, these three arguments are passed to the
* callback function:
*
*
* fd
*
*
* Signal number or resource indicating the stream.
*
*
*
*
* events
*
*
* A flag indicating the event. This will always be
* EV_TIMEOUT for timer events.
*
*
*
*
* arg
*
*
* Optional parameter, previously passed to
* event_timer_set as arg.
*
*
*
*
*
* @param resource $event Valid event resource.
* @param callable $callback Callback function to be called when the matching event occurs.
* @param mixed $arg Optional callback parameter.
* @throws LibeventException
*
*/
function event_timer_set($event, callable $callback, $arg = null): void
{
error_clear_last();
if ($arg !== null) {
$result = \event_timer_set($event, $callback, $arg);
} else {
$result = \event_timer_set($event, $callback);
}
if ($result === false) {
throw LibeventException::createFromPhpError();
}
}

View file

@ -0,0 +1,426 @@
<?php
namespace Safe;
use Safe\Exceptions\MssqlException;
/**
* Binds a parameter to a stored procedure or a remote stored procedure.
*
* @param resource $stmt Statement resource, obtained with mssql_init.
* @param string $param_name The parameter name, as a string.
*
* You have to include the @ character, like in the
* T-SQL syntax. See the explanation included in
* mssql_execute.
* @param mixed $var The PHP variable you'll bind the MSSQL parameter to. It is passed by
* reference, to retrieve OUTPUT and RETVAL values after
* the procedure execution.
* @param int $type One of: SQLTEXT,
* SQLVARCHAR, SQLCHAR,
* SQLINT1, SQLINT2,
* SQLINT4, SQLBIT,
* SQLFLT4, SQLFLT8,
* SQLFLTN.
* @param bool $is_output Whether the value is an OUTPUT parameter or not. If it's an OUTPUT
* parameter and you don't mention it, it will be treated as a normal
* input parameter and no error will be thrown.
* @param bool $is_null Whether the parameter is NULL or not. Passing the NULL value as
* var will not do the job.
* @param int $maxlen Used with char/varchar values. You have to indicate the length of the
* data so if the parameter is a varchar(50), the type must be
* SQLVARCHAR and this value 50.
* @throws MssqlException
*
*/
function mssql_bind($stmt, string $param_name, &$var, int $type, bool $is_output = false, bool $is_null = false, int $maxlen = -1): void
{
error_clear_last();
$result = \mssql_bind($stmt, $param_name, $var, $type, $is_output, $is_null, $maxlen);
if ($result === false) {
throw MssqlException::createFromPhpError();
}
}
/**
* Closes the link to a MS SQL Server database that's associated with the
* specified link identifier. If the link identifier isn't specified, the
* last opened link is assumed.
*
* Note that this isn't usually necessary, as non-persistent open
* links are automatically closed at the end of the script's
* execution.
*
* @param resource $link_identifier A MS SQL link identifier, returned by
* mssql_connect.
*
* This function will not close persistent links generated by
* mssql_pconnect.
* @throws MssqlException
*
*/
function mssql_close($link_identifier = null): void
{
error_clear_last();
if ($link_identifier !== null) {
$result = \mssql_close($link_identifier);
} else {
$result = \mssql_close();
}
if ($result === false) {
throw MssqlException::createFromPhpError();
}
}
/**
* mssql_connect establishes a connection to a
* MS SQL server.
*
* 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
* mssql_close.
*
* @param string $servername The MS SQL server. It can also include a port number, e.g.
* hostname:port (Linux), or
* hostname,port (Windows).
* @param string $username The username.
* @param string $password The password.
* @param bool $new_link If a second call is made to mssql_connect with the
* same arguments, no new link will be established, but instead, the link
* identifier of the already opened link will be returned. This parameter
* modifies this behavior and makes mssql_connect
* always open a new link, even if mssql_connect was
* called before with the same parameters.
* @return resource Returns a MS SQL link identifier on success.
* @throws MssqlException
*
*/
function mssql_connect(string $servername = null, string $username = null, string $password = null, bool $new_link = false)
{
error_clear_last();
if ($new_link !== false) {
$result = \mssql_connect($servername, $username, $password, $new_link);
} elseif ($password !== null) {
$result = \mssql_connect($servername, $username, $password);
} elseif ($username !== null) {
$result = \mssql_connect($servername, $username);
} elseif ($servername !== null) {
$result = \mssql_connect($servername);
} else {
$result = \mssql_connect();
}
if ($result === false) {
throw MssqlException::createFromPhpError();
}
return $result;
}
/**
* mssql_data_seek moves the internal row
* pointer of the MS SQL result associated with the specified result
* identifier to point to the specified row number, first row being
* number 0. The next call to mssql_fetch_row
* would return that row.
*
* @param resource $result_identifier The result resource that is being evaluated.
* @param int $row_number The desired row number of the new result pointer.
* @throws MssqlException
*
*/
function mssql_data_seek($result_identifier, int $row_number): void
{
error_clear_last();
$result = \mssql_data_seek($result_identifier, $row_number);
if ($result === false) {
throw MssqlException::createFromPhpError();
}
}
/**
* Returns the length of field no. offset in
* result.
*
* @param resource $result The result resource that is being evaluated. This result comes from a
* call to mssql_query.
* @param int $offset The field offset, starts at 0. If omitted, the current field is used.
* @return int The length of the specified field index on success.
* @throws MssqlException
*
*/
function mssql_field_length($result, int $offset = -1): int
{
error_clear_last();
$result = \mssql_field_length($result, $offset);
if ($result === false) {
throw MssqlException::createFromPhpError();
}
return $result;
}
/**
* Returns the name of field no. offset in
* result.
*
* @param resource $result The result resource that is being evaluated. This result comes from a
* call to mssql_query.
* @param int $offset The field offset, starts at 0. If omitted, the current field is used.
* @return string The name of the specified field index on success.
* @throws MssqlException
*
*/
function mssql_field_name($result, int $offset = -1): string
{
error_clear_last();
$result = \mssql_field_name($result, $offset);
if ($result === false) {
throw MssqlException::createFromPhpError();
}
return $result;
}
/**
* Seeks to the specified field offset. If the next call to
* mssql_fetch_field won't include a field
* offset, this field would be returned.
*
* @param resource $result The result resource that is being evaluated. This result comes from a
* call to mssql_query.
* @param int $field_offset The field offset, starts at 0.
* @throws MssqlException
*
*/
function mssql_field_seek($result, int $field_offset): void
{
error_clear_last();
$result = \mssql_field_seek($result, $field_offset);
if ($result === false) {
throw MssqlException::createFromPhpError();
}
}
/**
* Returns the type of field no. offset in
* result.
*
* @param resource $result The result resource that is being evaluated. This result comes from a
* call to mssql_query.
* @param int $offset The field offset, starts at 0. If omitted, the current field is used.
* @return string The type of the specified field index on success.
* @throws MssqlException
*
*/
function mssql_field_type($result, int $offset = -1): string
{
error_clear_last();
$result = \mssql_field_type($result, $offset);
if ($result === false) {
throw MssqlException::createFromPhpError();
}
return $result;
}
/**
* mssql_free_result only needs to be called
* if you are worried about using too much memory while your script
* is running. All result memory will automatically be freed when
* the script ends. You may call mssql_free_result
* with the result identifier as an argument and the associated
* result memory will be freed.
*
* @param resource $result The result resource that is being freed. This result comes from a
* call to mssql_query.
* @throws MssqlException
*
*/
function mssql_free_result($result): void
{
error_clear_last();
$result = \mssql_free_result($result);
if ($result === false) {
throw MssqlException::createFromPhpError();
}
}
/**
* mssql_free_statement only needs to be called
* if you are worried about using too much memory while your script
* is running. All statement memory will automatically be freed when
* the script ends. You may call mssql_free_statement
* with the statement identifier as an argument and the associated
* statement memory will be freed.
*
* @param resource $stmt Statement resource, obtained with mssql_init.
* @throws MssqlException
*
*/
function mssql_free_statement($stmt): void
{
error_clear_last();
$result = \mssql_free_statement($stmt);
if ($result === false) {
throw MssqlException::createFromPhpError();
}
}
/**
* Initializes a stored procedure or a remote stored procedure.
*
* @param string $sp_name Stored procedure name, like ownew.sp_name or
* otherdb.owner.sp_name.
* @param resource $link_identifier A MS SQL link identifier, returned by
* mssql_connect.
* @return resource Returns a resource identifier "statement", used in subsequent calls to
* mssql_bind and mssql_executes.
* @throws MssqlException
*
*/
function mssql_init(string $sp_name, $link_identifier = null)
{
error_clear_last();
if ($link_identifier !== null) {
$result = \mssql_init($sp_name, $link_identifier);
} else {
$result = \mssql_init($sp_name);
}
if ($result === false) {
throw MssqlException::createFromPhpError();
}
return $result;
}
/**
* mssql_pconnect acts very much like
* mssql_connect with two major differences.
*
* First, when connecting, the function would first try to find a
* (persistent) link that's already open with the same host,
* username and password. If one is found, an identifier for it
* will be returned instead of opening a new connection.
*
* Second, the connection to the SQL server will not be closed when
* the execution of the script ends. Instead, the link will remain
* open for future use (mssql_close will not
* close links established by mssql_pconnect).
*
* This type of links is therefore called 'persistent'.
*
* @param string $servername The MS SQL server. It can also include a port number. e.g.
* hostname:port.
* @param string $username The username.
* @param string $password The password.
* @param bool $new_link If a second call is made to mssql_pconnect with
* the same arguments, no new link will be established, but instead, the
* link identifier of the already opened link will be returned. This
* parameter modifies this behavior and makes
* mssql_pconnect always open a new link, even if
* mssql_pconnect was called before with the same
* parameters.
* @return resource Returns a positive MS SQL persistent link identifier on success.
* @throws MssqlException
*
*/
function mssql_pconnect(string $servername = null, string $username = null, string $password = null, bool $new_link = false)
{
error_clear_last();
if ($new_link !== false) {
$result = \mssql_pconnect($servername, $username, $password, $new_link);
} elseif ($password !== null) {
$result = \mssql_pconnect($servername, $username, $password);
} elseif ($username !== null) {
$result = \mssql_pconnect($servername, $username);
} elseif ($servername !== null) {
$result = \mssql_pconnect($servername);
} else {
$result = \mssql_pconnect();
}
if ($result === false) {
throw MssqlException::createFromPhpError();
}
return $result;
}
/**
* mssql_query sends a query to the currently active
* database on the server that's associated with the specified link
* identifier.
*
* @param string $query An SQL query.
* @param resource $link_identifier A MS SQL link identifier, returned by
* mssql_connect or
* mssql_pconnect.
*
* If the link identifier isn't specified, the last opened link is
* assumed. If no link is open, the function tries to establish a link
* as if mssql_connect was called, and use it.
* @param int $batch_size The number of records to batch in the buffer.
* @return mixed Returns a MS SQL result resource on success, TRUE if no rows were
* returned.
* @throws MssqlException
*
*/
function mssql_query(string $query, $link_identifier = null, int $batch_size = 0)
{
error_clear_last();
if ($batch_size !== 0) {
$result = \mssql_query($query, $link_identifier, $batch_size);
} elseif ($link_identifier !== null) {
$result = \mssql_query($query, $link_identifier);
} else {
$result = \mssql_query($query);
}
if ($result === false) {
throw MssqlException::createFromPhpError();
}
return $result;
}
/**
* mssql_select_db sets the current active
* database on the server that's associated with the specified link
* identifier.
*
* Every subsequent call to mssql_query will be
* made on the active database.
*
* @param string $database_name The database name.
*
* To escape the name of a database that contains spaces, hyphens ("-"),
* or any other exceptional characters, the database name must be
* enclosed in brackets, as is shown in the example, below. This
* technique must also be applied when selecting a database name that is
* also a reserved word (such as primary).
* @param resource $link_identifier A MS SQL link identifier, returned by
* mssql_connect or
* mssql_pconnect.
*
* If no link identifier is specified, the last opened link is assumed.
* If no link is open, the function will try to establish a link as if
* mssql_connect was called, and use it.
* @throws MssqlException
*
*/
function mssql_select_db(string $database_name, $link_identifier = null): void
{
error_clear_last();
if ($link_identifier !== null) {
$result = \mssql_select_db($database_name, $link_identifier);
} else {
$result = \mssql_select_db($database_name);
}
if ($result === false) {
throw MssqlException::createFromPhpError();
}
}

View file

@ -0,0 +1,108 @@
<?php
namespace Safe;
use Safe\Exceptions\StatsException;
/**
* Returns the covariance of a and b.
*
* @param array $a The first array
* @param array $b The second array
* @return float Returns the covariance of a and b.
* @throws StatsException
*
*/
function stats_covariance(array $a, array $b): float
{
error_clear_last();
$result = \stats_covariance($a, $b);
if ($result === false) {
throw StatsException::createFromPhpError();
}
return $result;
}
/**
* Returns the standard deviation of the values in a.
*
* @param array $a The array of data to find the standard deviation for. Note that all
* values of the array will be cast to float.
* @param bool $sample Indicates if a represents a sample of the
* population; defaults to FALSE.
* @return float Returns the standard deviation on success; FALSE on failure.
* @throws StatsException
*
*/
function stats_standard_deviation(array $a, bool $sample = false): float
{
error_clear_last();
$result = \stats_standard_deviation($a, $sample);
if ($result === false) {
throw StatsException::createFromPhpError();
}
return $result;
}
/**
* Returns the Pearson correlation coefficient between arr1 and arr2.
*
* @param array $arr1 The first array
* @param array $arr2 The second array
* @return float Returns the Pearson correlation coefficient between arr1 and arr2.
* @throws StatsException
*
*/
function stats_stat_correlation(array $arr1, array $arr2): float
{
error_clear_last();
$result = \stats_stat_correlation($arr1, $arr2);
if ($result === false) {
throw StatsException::createFromPhpError();
}
return $result;
}
/**
* Returns the inner product of arr1 and arr2.
*
* @param array $arr1 The first array
* @param array $arr2 The second array
* @return float Returns the inner product of arr1 and arr2.
* @throws StatsException
*
*/
function stats_stat_innerproduct(array $arr1, array $arr2): float
{
error_clear_last();
$result = \stats_stat_innerproduct($arr1, $arr2);
if ($result === false) {
throw StatsException::createFromPhpError();
}
return $result;
}
/**
* Returns the variance of the values in a.
*
* @param array $a The array of data to find the standard deviation for. Note that all
* values of the array will be cast to float.
* @param bool $sample Indicates if a represents a sample of the
* population; defaults to FALSE.
* @return float Returns the variance on success; FALSE on failure.
* @throws StatsException
*
*/
function stats_variance(array $a, bool $sample = false): float
{
error_clear_last();
$result = \stats_variance($a, $sample);
if ($result === false) {
throw StatsException::createFromPhpError();
}
return $result;
}