Update website

This commit is contained in:
Guilhem Lavaux 2024-11-19 08:02:04 +01:00
parent 4413528994
commit 1d90fbf296
6865 changed files with 1091082 additions and 0 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 TheCodingMachine
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,178 @@
[![Latest Stable Version](https://poser.pugx.org/thecodingmachine/safe/v/stable.svg)](https://packagist.org/packages/thecodingmachine/safe)
[![Total Downloads](https://poser.pugx.org/thecodingmachine/safe/downloads.svg)](https://packagist.org/packages/thecodingmachine/safe)
[![Latest Unstable Version](https://poser.pugx.org/thecodingmachine/safe/v/unstable.svg)](https://packagist.org/packages/thecodingmachine/safe)
[![License](https://poser.pugx.org/thecodingmachine/safe/license.svg)](https://packagist.org/packages/thecodingmachine/safe)
[![Build Status](https://travis-ci.org/thecodingmachine/safe.svg?branch=master)](https://travis-ci.org/thecodingmachine/safe)
[![Continuous Integration](https://github.com/thecodingmachine/safe/workflows/Continuous%20Integration/badge.svg)](https://github.com/thecodingmachine/safe/actions)
[![codecov](https://codecov.io/gh/thecodingmachine/safe/branch/master/graph/badge.svg)](https://codecov.io/gh/thecodingmachine/safe)
Safe PHP
========
**Work in progress**
A set of core PHP functions rewritten to throw exceptions instead of returning `false` when an error is encountered.
## The problem
Most PHP core functions were written before exception handling was added to the language. Therefore, most PHP functions
do not throw exceptions. Instead, they return `false` in case of error.
But most of us are too lazy to check explicitly for every single return of every core PHP function.
```php
// This code is incorrect. Twice.
// "file_get_contents" can return false if the file does not exists
// "json_decode" can return false if the file content is not valid JSON
$content = file_get_contents('foobar.json');
$foobar = json_decode($content);
```
The correct version of this code would be:
```php
$content = file_get_contents('foobar.json');
if ($content === false) {
throw new FileLoadingException('Could not load file foobar.json');
}
$foobar = json_decode($content);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new FileLoadingException('foobar.json does not contain valid JSON: '.json_last_error_msg());
}
```
Obviously, while this snippet is correct, it is less easy to read.
## The solution
Enter *thecodingmachine/safe* aka Safe-PHP.
Safe-PHP redeclares all core PHP functions. The new PHP functions act exactly as the old ones, except they
throw exceptions properly when an error is encountered. The "safe" functions have the same name as the core PHP
functions, except they are in the `Safe` namespace.
```php
use function Safe\file_get_contents;
use function Safe\json_decode;
// This code is both safe and simple!
$content = file_get_contents('foobar.json');
$foobar = json_decode($content);
```
All PHP functions that can return `false` on error are part of Safe.
In addition, Safe also provide 2 'Safe' classes: `Safe\DateTime` and `Safe\DateTimeImmutable` whose methods will throw exceptions instead of returning false.
## PHPStan integration
> Yeah... but I must explicitly think about importing the "safe" variant of the function, for each and every file of my application.
> I'm sure I will forget some "use function" statements!
Fear not! thecodingmachine/safe comes with a PHPStan rule.
Never heard of [PHPStan](https://github.com/phpstan/phpstan) before?
Check it out, it's an amazing code analyzer for PHP.
Simply install the Safe rule in your PHPStan setup (explained in the "Installation" section) and PHPStan will let you know each time you are using an "unsafe" function.
The code below will trigger this warning:
```php
$content = file_get_contents('foobar.json');
```
> Function file_get_contents is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\\file_get_contents;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library.
## Installation
Use composer to install Safe-PHP:
```bash
$ composer require thecodingmachine/safe
```
*Highly recommended*: install PHPStan and PHPStan extension:
```bash
$ composer require --dev thecodingmachine/phpstan-safe-rule
```
Now, edit your `phpstan.neon` file and add these rules:
```yml
includes:
- vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon
```
## Automated refactoring
You have a large legacy codebase and want to use "Safe-PHP" functions throughout your project? PHPStan will help you
find these functions but changing the namespace of the functions one function at a time might be a tedious task.
Fortunately, Safe comes bundled with a "Rector" configuration file. [Rector](https://github.com/rectorphp/rector) is a command-line
tool that performs instant refactoring of your application.
Run
```bash
$ composer require --dev rector/rector:^0.7
```
to install `rector/rector`.
Run
```bash
vendor/bin/rector process src/ --config vendor/thecodingmachine/safe/rector-migrate-0.7.php
```
to run `rector/rector`.
*Note:* do not forget to replace "src/" with the path to your source directory.
**Important:** the refactoring only performs a "dumb" replacement of functions. It will not modify the way
"false" return values are handled. So if your code was already performing error handling, you will have to deal
with it manually.
Especially, you should look for error handling that was already performed, like:
```php
if (!mkdir($dirPath)) {
// Do something on error
}
```
This code will be refactored by Rector to:
```php
if (!\Safe\mkdir($dirPath)) {
// Do something on error
}
```
You should then (manually) refactor it to:
```php
try {
\Safe\mkdir($dirPath));
} catch (\Safe\FilesystemException $e) {
// Do something on error
}
```
## Performance impact
Safe is loading 1000+ functions from ~85 files on each request. Yet, the performance impact of this loading is quite low.
In case you worry, using Safe will "cost" you ~700µs on each request. The [performance section](performance/README.md)
contains more information regarding the way we tested the performance impact of Safe.
## Learn more
Read [the release article on TheCodingMachine's blog](https://thecodingmachine.io/introducing-safe-php) if you want to
learn more about what triggered the development of Safe-PHP.
## Contributing
The files that contain all the functions are auto-generated from the PHP doc.
Read the [CONTRIBUTING.md](CONTRIBUTING.md) file to learn how to regenerate these files and to contribute to this library.

View file

@ -0,0 +1,123 @@
{
"name": "thecodingmachine/safe",
"description": "PHP core functions that throw exceptions instead of returning FALSE on error",
"license": "MIT",
"autoload": {
"psr-4": {
"Safe\\": [
"lib/",
"deprecated/",
"generated/"
]
},
"files": [
"deprecated/apc.php",
"deprecated/libevent.php",
"deprecated/mssql.php",
"deprecated/stats.php",
"lib/special_cases.php",
"generated/apache.php",
"generated/apcu.php",
"generated/array.php",
"generated/bzip2.php",
"generated/calendar.php",
"generated/classobj.php",
"generated/com.php",
"generated/cubrid.php",
"generated/curl.php",
"generated/datetime.php",
"generated/dir.php",
"generated/eio.php",
"generated/errorfunc.php",
"generated/exec.php",
"generated/fileinfo.php",
"generated/filesystem.php",
"generated/filter.php",
"generated/fpm.php",
"generated/ftp.php",
"generated/funchand.php",
"generated/gmp.php",
"generated/gnupg.php",
"generated/hash.php",
"generated/ibase.php",
"generated/ibmDb2.php",
"generated/iconv.php",
"generated/image.php",
"generated/imap.php",
"generated/info.php",
"generated/ingres-ii.php",
"generated/inotify.php",
"generated/json.php",
"generated/ldap.php",
"generated/libxml.php",
"generated/lzf.php",
"generated/mailparse.php",
"generated/mbstring.php",
"generated/misc.php",
"generated/msql.php",
"generated/mysql.php",
"generated/mysqli.php",
"generated/mysqlndMs.php",
"generated/mysqlndQc.php",
"generated/network.php",
"generated/oci8.php",
"generated/opcache.php",
"generated/openssl.php",
"generated/outcontrol.php",
"generated/password.php",
"generated/pcntl.php",
"generated/pcre.php",
"generated/pdf.php",
"generated/pgsql.php",
"generated/posix.php",
"generated/ps.php",
"generated/pspell.php",
"generated/readline.php",
"generated/rpminfo.php",
"generated/rrd.php",
"generated/sem.php",
"generated/session.php",
"generated/shmop.php",
"generated/simplexml.php",
"generated/sockets.php",
"generated/sodium.php",
"generated/solr.php",
"generated/spl.php",
"generated/sqlsrv.php",
"generated/ssdeep.php",
"generated/ssh2.php",
"generated/stream.php",
"generated/strings.php",
"generated/swoole.php",
"generated/uodbc.php",
"generated/uopz.php",
"generated/url.php",
"generated/var.php",
"generated/xdiff.php",
"generated/xml.php",
"generated/xmlrpc.php",
"generated/yaml.php",
"generated/yaz.php",
"generated/zip.php",
"generated/zlib.php"
]
},
"require": {
"php": ">=7.2"
},
"require-dev": {
"phpstan/phpstan": "^0.12",
"thecodingmachine/phpstan-strict-rules": "^0.12",
"squizlabs/php_codesniffer": "^3.2"
},
"scripts": {
"phpstan": "phpstan analyse lib -c phpstan.neon --level=max --no-progress -vvv",
"cs-fix": "phpcbf",
"cs-check": "phpcs"
},
"extra": {
"branch-alias": {
"dev-master": "0.1-dev"
}
}
}

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;
}

View file

@ -0,0 +1,11 @@
<?php
namespace Safe\Exceptions;
class ApacheException 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 ApcuException 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 ArrayException 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 Bzip2Exception 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 CalendarException 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 ClassobjException 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 ComException 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 CubridException 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 DatetimeException 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 DirException 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 EioException 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 ErrorfuncException 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 ExecException 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 FileinfoException 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 FilesystemException 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 FilterException 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 FpmException 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 FtpException 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 FunchandException 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 GmpException 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 GnupgException 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 HashException 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 IbaseException 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 IbmDb2Exception 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 IconvException 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 ImageException 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 ImapException 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 InfoException 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 IngresiiException 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 InotifyException 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 LdapException 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 LibxmlException 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 LzfException 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 MailparseException 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 MbstringException 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 MiscException 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 MsqlException 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 MysqlException 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 MysqliException 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 MysqlndMsException 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 MysqlndQcException 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 NetworkException 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 Oci8Exception 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 OpcacheException 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 OutcontrolException 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 PasswordException 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 PcntlException 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 PdfException 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 PgsqlException 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 PosixException 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 PsException 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 PspellException 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 ReadlineException 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 RpminfoException 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 RrdException 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 SemException 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 SessionException 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 ShmopException 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 SimplexmlException extends \ErrorException implements SafeExceptionInterface
{
public static function createFromPhpError(): self
{
$error = error_get_last();
return new self($error['message'] ?? 'An error occured', 0, $error['type'] ?? 1);
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Safe\Exceptions;
class SocketsException 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 SodiumException 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 SolrException 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 SplException 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 SqlsrvException 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 SsdeepException 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 Ssh2Exception 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 StreamException 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 StringsException 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 SwooleException 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 UodbcException 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 UopzException 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 UrlException 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 VarException 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 XdiffException 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 XmlException 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 XmlrpcException 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 YamlException 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 YazException 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 ZipException 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 ZlibException 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,177 @@
<?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. Works in the
* Apache, FastCGI, CLI, FPM and NSAPI server module
* in Netscape/iPlanet/SunONE webservers.
*
* @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. Works in the
* Apache, FastCGI, CLI, FPM and NSAPI server module
* in Netscape/iPlanet/SunONE webservers.
*
* @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,112 @@
<?php
namespace Safe;
use Safe\Exceptions\ApcuException;
/**
* Retrieves cached information and meta-data from APC's data store.
*
* @param bool $limited If limited is TRUE, the
* return value will exclude the individual list of cache entries. This
* is useful when trying to optimize calls for statistics gathering.
* @return array Array of cached data (and meta-data)
* @throws ApcuException
*
*/
function apcu_cache_info(bool $limited = false): array
{
error_clear_last();
$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|null $success Optionally pass the success or fail boolean value to
* this referenced variable.
* @param int $ttl TTL to use if the operation inserts a new value (rather than decrementing an existing one).
* @return int Returns the current value of key's value on success
* @throws ApcuException
*
*/
function apcu_dec(string $key, int $step = 1, ?bool &$success = null, int $ttl = 0): int
{
error_clear_last();
$result = \apcu_dec($key, $step, $success, $ttl);
if ($result === false) {
throw ApcuException::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|null $success Optionally pass the success or fail boolean value to
* this referenced variable.
* @param int $ttl TTL to use if the operation inserts a new value (rather than incrementing an existing one).
* @return int Returns the current value of key's value on success
* @throws ApcuException
*
*/
function apcu_inc(string $key, int $step = 1, ?bool &$success = null, int $ttl = 0): int
{
error_clear_last();
$result = \apcu_inc($key, $step, $success, $ttl);
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,464 @@
<?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_flip returns an array in flip
* order, i.e. keys from array become values and values
* from array become keys.
*
* Note that the values of array need to be valid
* keys, i.e. they need to be either integer or
* string. A warning will be emitted if a value has the wrong
* type, and the key/value pair in question will not be included
* in the result.
*
* If a value has several occurrences, the latest key will be
* used as its value, and all others will be lost.
*
* @param array $array An array of key/value pairs to be flipped.
* @return array Returns the flipped array on success.
* @throws ArrayException
*
*/
function array_flip(array $array): array
{
error_clear_last();
$result = \array_flip($array);
if ($result === null) {
throw ArrayException::createFromPhpError();
}
return $result;
}
/**
* array_replace_recursive replaces the values of
* array1 with the same values from all the following
* arrays. If a key from the first array exists in the second array, its value
* will be replaced by the value from the second array. If the key exists in the
* second array, and not the first, it will be created in the first array.
* If a key only exists in the first array, it will be left as is.
* If several arrays are passed for replacement, they will be processed
* in order, the later array overwriting the previous values.
*
* array_replace_recursive is recursive : it will recurse into
* arrays and apply the same process to the inner value.
*
* When the value in the first array is scalar, it will be replaced
* by the value in the second array, may it be scalar or array.
* When the value in the first array and the second array
* are both arrays, array_replace_recursive will replace
* their respective value recursively.
*
* @param array $array1 The array in which elements are replaced.
* @param array $params Optional. Arrays from which elements will be extracted.
* @return array Returns an array.
* @throws ArrayException
*
*/
function array_replace_recursive(array $array1, array ...$params): array
{
error_clear_last();
if ($params !== []) {
$result = \array_replace_recursive($array1, ...$params);
} else {
$result = \array_replace_recursive($array1);
}
if ($result === null) {
throw ArrayException::createFromPhpError();
}
return $result;
}
/**
* array_replace replaces the values of
* array1 with values having the same keys in each of the following
* arrays. If a key from the first array exists in the second array, its value
* will be replaced by the value from the second array. If the key exists in the
* second array, and not the first, it will be created in the first array.
* If a key only exists in the first array, it will be left as is.
* If several arrays are passed for replacement, they will be processed
* in order, the later arrays overwriting the previous values.
*
* array_replace is not recursive : it will replace
* values in the first array by whatever type is in the second array.
*
* @param array $array1 The array in which elements are replaced.
* @param array $params Arrays from which elements will be extracted.
* Values from later arrays overwrite the previous values.
* @return array Returns an array.
* @throws ArrayException
*
*/
function array_replace(array $array1, array ...$params): array
{
error_clear_last();
if ($params !== []) {
$result = \array_replace($array1, ...$params);
} else {
$result = \array_replace($array1);
}
if ($result === null) {
throw ArrayException::createFromPhpError();
}
return $result;
}
/**
* 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;
* the details are described in the comparison operators section
*
*
* 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,96 @@
<?php
namespace Safe;
use Safe\Exceptions\Bzip2Exception;
/**
* Closes the given bzip2 file pointer.
*
* @param resource $bz The file pointer. It must be valid and must point to a file
* successfully opened by bzopen.
* @throws Bzip2Exception
*
*/
function bzclose($bz): void
{
error_clear_last();
$result = \bzclose($bz);
if ($result === false) {
throw Bzip2Exception::createFromPhpError();
}
}
/**
* 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.
* @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,27 @@
<?php
namespace Safe;
use Safe\Exceptions\CalendarException;
/**
* This function will return a Unix timestamp corresponding to the
* Julian Day given in jday or FALSE if
* jday is outside of the allowed range. The time returned is
* UTC.
*
* @param int $jday A julian day number between 2440588 and 106751993607888
* on 64bit systems, or between 2440588 and 2465443 on 32bit systems.
* @return int The unix timestamp for the start (midnight, not noon) of the given Julian day.
* @throws CalendarException
*
*/
function jdtounix(int $jday): int
{
error_clear_last();
$result = \jdtounix($jday);
if ($result === false) {
throw CalendarException::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,127 @@
<?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(object $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();
$result = \com_print_typeinfo($comobject, $dispinterface, $wantsink);
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();
}
}

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