PHPackages                             net-tools/core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. net-tools/core

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

net-tools/core
==============

Composer library providing core functionalities

1.3.10(3mo ago)21.2k6MITPHPPHP &gt;= 7.2

Since Nov 30Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/net-tools/core)[ Packagist](https://packagist.org/packages/net-tools/core)[ RSS](/packages/net-tools-core/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (98)Used By (6)

net-tools/core
==============

[](#net-toolscore)

Composer library to provide PHP core functionalities
----------------------------------------------------

[](#composer-library-to-provide-php-core-functionalities)

The package contains classes for :

- containers (cache, pool)
- formatters (export data to CSV of any other format - currently only CSV export is implemented)
- helpers (to help processing data in requests, to sanitize user data, to encode/decode data, etc.)

Setup instructions
------------------

[](#setup-instructions)

To install net-tools/core package, just require it through composer : `require net-tools/core:^1.0.0`

How to use ?
------------

[](#how-to-use-)

The classes provided in the helpers are rather self-explanatory, each class and method dealing with only one purpose. All helper classes are not meant to be instantiated (all methods are static), **except PdoHelper which MUST be instantiated**. The Containers and Formatters class must also be instantiated.

NamespaceClassDescriptionHelpersDataHelperMiscellaneous functions to deal with string, dates, and arraysHelpersEncodingHelperEncode/decode accented characters to/from html entities or remove any accented characterHelpersFileHelperGuess the file type (image, video, etc...) or the Mime type of a file by looking at it's nameHelpersImagingHelperResize an image to a given with and/or height (aspect ratio preserved)HelpersNetworkingHelperSend XMLHttp response headers (no cache allowed) ; add parameters to an url ; get relative folder (to webroot) for a file ; get feedback about an file upload error codeHelpersSecurityHelperCreate tokens, token with an expiration delay, sanitize stringsHelpersPdoHelperProvide convenient functions to make queries with PDO. Deals with foreign keys (database schema with foreign keys must be supplied within an array). Can be used as any Pdo instance, as PdoHelper is a subclass of PHP Pdo class.ContainersPoolManage a pool of objects (refer to 'Pool' design pattern)ContainersCacheManage a cache of objectsContainersPersistentCacheManage a cache of objects which is meant to be serialized (to disk) ; provide one of the `CachePersistentProvider` subclass as a strategy pattern to handle persistence.ExceptionHandlersExceptionHandlerAbstract class to handle exceptions and output some nicely formatted exception traceExceptionHandlersSimpleExceptionHandlerConcrete implementation providing default CSS and exception formattingExceptionHandlersPublicExceptionHandlerConcrete implementation providing minimum exception details (suitable for public application) ; full details are sent to the webmaster ()FormattersFormatterBase class to handle a tabular output (rows and columns)FormattersCsvFormatterHandle CSV output (subclass of `Formatter`)FormattersFormatterOutputStrategyStrategy pattern to implement concrete output (to a file or a string) ; provide one of the `FormatterOutputStrategy` subclass.When the package is mentionned in your composer.json, it will automatically require `Includes/Init.php` which will perform some initialization stuff, such as the default charset, locale and timezones. Currently, if not specified, the errors are displayed in the standard output, and the `mb_xxx` functions default encoding is set to UTF\_8, as this is the most easy way to deal with foreign characters.

You may set other values, by defining the following constants BEFORE including your vendor/autoload.php :

Constantdefault value setDescriptionK\_NETTOOLS\_DISPLAY\_ERRORS`'stdout'`Provide `'stderr'` string to redirect errors to the error logK\_NETTOOLS\_INIT\_TIMEZONENone (PHP config used)Provide the timezone string, such as `'Europe/Paris'` if PHP default timezone is not set correctly by the server config.K\_NETTOOLS\_INIT\_MB\_INTERNAL\_ENCODING`'utf-8'`Provide the encoding to user with mb\_xxx functionsK\_NETTOOLS\_INIT\_LOCALENone (PHP uses US locale by default)Set the right locale, such as `'fr_FR.utf8'`K\_NETTOOLS\_POSTMASTERDefines the email address of webmaster to send exception details to (when using `PublicExceptionHandler` class)Samples
-------

[](#samples)

For most classes, the function names and their parameters are self-explanatory, please refer to the API reference link below.

### Sample : CsvFormatter

[](#sample--csvformatter)

The Formatters namespace has some classes to help export tabular data.

Currently, only CSV export is implemented, but we could also implement HTML Table export rather simply by subclassing the `Formatter` class and providing code to it's abstract methods (those methods define how to print lines, rows, separate columns, etc.). For `CsvFormatter` subclass, the only implementation needed is how to separate columns (in CSV, this is done with ';' character). New rows are written with a newline character.

```
// we create a file at $PATH
$fhandle = fopen($path, 'w');

// we create the formatter along with an output strategy, here to a file handle
$csv = new CsvFormatter(new FormatterFileOutputStrategy($fhandle));

// beginning export
$csv->newRow();
$csv->row(array('column1 header', 'column2 header', 'column3 header'));
$csv->closeRow();
$csv->newRow();
$csv->row(array('line2_column1_value', 'line3_column2_value', ''));
$csv->closeRow(true);   // true = this is the last row

// closing file handle
fclose($fhandle);
```

### Sample : PdoHelper

[](#sample--pdohelper)

PdoHelper is a subclass of PHP Pdo class (instantiation needed, use the same constructor parameters as the Pdo constructor). So you may use any usual method of Pdo (such as `prepare` and `execute`).

There are simple functions such as `pdo_query` or `pdo_query_select` which prepare AND then execute the request with a single call.

There is a `pdo_dbexists` method you may use to test whether a value exists for a SQL Select statement, with only one PHP code line (the value is returned) :

```
if ( $name = $pdoh->pdo_dbexists('SELECT name FROM Client WHERE id=?', array(123456)) )
    echo "found client ; its name is '$name' !";
```

The main benefit of PdoHelper is it's foreign key querying system. If you define your relationnal schema (just the tables having foreign keys, other tables are useless), you may ask the question "is there a table which has a line with a column referencing a particular foreign key ?". In other words, may I delete safely a row in a table X without breaking a table Y with a column referencing table X and the row deleted ?

To build the schema of tables/foreign keys, you just call `addForeignKey` method for all tables whoses rows may be referenced (tables being foreign keys to other). For example, in a Town and Client schema, Town is the table being referenced by a idTown column in the Client table.

```
// defining a schema with 2 tables referencing the Town table through it's idTown column
$pdoh->addForeignKey('Town', 'idTown', ['Client', 'Merchants']);
```

To safely delete a row in Town table, we need to check that no row in Client or Merchants has a reference to the town being deleted :

```
$test = $pdoh->pdo_foreignkeys('Town', 1234);
if ( $test['statut'] )
   // no foreign key detected, we may delete safely the town
   echo "deletion is safe";
else
   echo "deletion is not safe : " . $test['cause']['message'];
```

### Sample : SimpleExceptionHandler

[](#sample--simpleexceptionhandler)

If you encounter an exception, you may catch it and call a `ExceptionHandler` class to format it and send the output to stdout :

```
try
{
   // some bad code here
}
catch (\Exception $e)
{
   (new \Nettools\Core\ExceptionHandlers\SimpleExceptionHandler())->handleException($e);
   // the script is halted here
}
```

PHPUnit
-------

[](#phpunit)

To test with PHPUnit, point the -c configuration option to the /phpunit.xml configuration file.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance79

Regular maintenance activity

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~35 days

Recently: every ~0 days

Total

97

Last Release

113d ago

PHP version history (3 changes)1.0.0PHP &gt;= 5.4.0

1.0.25PHP &gt;= 7.0

1.0.52PHP &gt;= 7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/2cb0c1d404c8ae72b0a731246130079c2f440d6ea079815ca8c153aa361b1f28?d=identicon)[nettools.ovh](/maintainers/nettools.ovh)

---

Top Contributors

[![net-tools](https://avatars.githubusercontent.com/u/6818724?v=4)](https://github.com/net-tools "net-tools (70 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/net-tools-core/health.svg)

```
[![Health](https://phpackages.com/badges/net-tools-core/health.svg)](https://phpackages.com/packages/net-tools-core)
```

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[firefly-iii/data-importer

Firefly III Data Import Tool.

7545.8k](/packages/firefly-iii-data-importer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
