Download the PHP package greatcode/controller-global without Composer
On this page you can find all versions of the php package greatcode/controller-global. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download greatcode/controller-global
More information about greatcode/controller-global
Files in greatcode/controller-global
Package controller-global
Short Description Base Library Controller Global for GC
License MIT
Informations about the package controller-global
controller-global
Base Library Controller Global for GC — a PHP utility library providing a PDO wrapper, generic DML/SELECT helpers, AES-256-CBC encoding, and a POS-group integrator client.
Requirements: PHP >= 8.2, ext-pdo, ext-pdo_sqlite, ext-openssl, ext-curl, guzzlehttp/guzzle ^7.10
Installation
CtrlGlobal
General-purpose controller with DML helpers, SELECT wrappers, HTTP client wrappers, and AES-256-CBC encode/decode. Resolves its Connection automatically.
Instantiation
When constructed with null (default), it checks for a global $cfg['db'] array first, then falls back to Connection::fromEnv().
The encryption key is resolved in this order:
- Explicit
$encryption_keyconstructor argument ENCRYPTION_KEYenvironment variable- Fallback value
'secret'
DML
insert()
insertAll()
Insert multiple rows in a single statement.
update()
delete()
deleteAll()
Delete multiple rows, each matched by its own condition set (conditions within a row are AND-joined; rows are OR-joined).
SELECT
GetGlobalFilter()
Execute a SELECT and return all rows as associative arrays. Supports both positional (?) and named (:key) bindings.
runSql()
Same behaviour as GetGlobalFilter — execute SQL and return all rows.
getName()
Return the name column of the first result row, or an empty string if no rows match.
Encoding
AES-256-CBC encode/decode. The key is determined by the constructor (see Instantiation above).
Two instances using different keys will produce different ciphertext for the same input and cannot decode each other's output.
HTTP client
Thin wrappers around a shared GuzzleHttp\Client singleton. All methods return a PSR-7 ResponseInterface.
The underlying GuzzleHttp\Client instance is a static singleton shared across all CtrlGlobal instances:
Connection
Connection extends PDO with safe defaults and convenience factory methods.
Default PDO attributes set on every connection:
| Attribute | Value |
|---|---|
ATTR_ERRMODE |
ERRMODE_EXCEPTION |
ATTR_DEFAULT_FETCH_MODE |
FETCH_ASSOC |
ATTR_EMULATE_PREPARES |
false |
ATTR_PERSISTENT |
false |
Direct constructor
Override any default attribute:
fromConfig()
Build a connection from an associative array. Supported drivers: mysql, pgsql, sqlite.
fromEnv()
Reads connection parameters from environment variables.
| Env var | Default |
|---|---|
DB_DRIVER |
mysql |
DB_HOST |
127.0.0.1 |
DB_PORT |
3306 |
DB_NAME |
(empty) |
DB_CHARSET |
utf8mb4 |
DB_USER |
(empty) |
DB_PASSWORD |
(empty) |
getInstance() — singleton
Returns the same Connection instance across calls. Useful for sharing a single connection throughout a request lifecycle.
transaction()
Wraps a callable in a database transaction. Commits on success, rolls back and re-throws on any exception.
CtrlGroupPos
HTTP client for a remote POS-group integrator service.
Methods
| Method | Description |
|---|---|
getGroupPos(array $params) |
Query POS user data. Required keys: group_pos, browser, waktu. |
updateLoginProcess($id, $status) |
Update the login status of a POS session. |
updateLastDate($id, $last_data) |
Update the last-data timestamp for a POS entry. |
updatePOSLastDate(array $datas) |
Bulk-update POS last dates via JSON POST. Each item needs status and data. |
updatePosToken($token, $id, $status) |
Update the token associated with a POS session. |
updateBranchId($branchID, $id) |
Update the branch ID for a POS entry. |
saveToLocal($table, $arFieldValues) |
Insert rows into a local table via CtrlGlobal::insertAll(). Returns bool. |
Logger
Logger is a facade for Monolog. It is initialized in CtrlGlobal::initialize().
| Method | Description |
|---|---|
Log::initialize($name, $config) |
Initialize the logger. See Logger::__construct() for $config details. |
Log::getInstance() |
Get the logger instance. |
Log::debug($message) |
Log debug. |
Log::info($message) |
Log info. |
Log::warning($message) |
Log warning. |
Log::error($message) |
Log error. |
Log::fatal($message) |
Log fatal. |
Running tests
The test suite is split into two suites: Unit (SQLite, no external services) and Integration (real MySQL).
Unit tests
Integration tests (MySQL)
Requires ext-pdo_mysql. Set DB_NAME at minimum; all 23 tests skip automatically when it is absent.
Integration tests (PostgreSQL)
Requires ext-pdo_pgsql. Set PGSQL_NAME at minimum; all 23 tests skip automatically when it is absent.
Run all suites
CI
GitHub Actions runs three jobs in parallel:
| Job | Matrix | Services |
|---|---|---|
unit |
PHP 8.2 / 8.3 / 8.4 | — |
integration |
PHP 8.2 / 8.3 / 8.4 × MySQL 8.0 / 8.4 | MySQL service container |
integration-pgsql |
PHP 8.2 / 8.3 / 8.4 × PostgreSQL 15 / 17 | PostgreSQL service container |
Coverage (Xdebug) is collected on the Unit job for PHP 8.3 and uploaded as a workflow artifact.
All versions of controller-global with dependencies
ext-pdo Version *
ext-pdo_sqlite Version *
ext-openssl Version *
ext-curl Version *
guzzlehttp/guzzle Version ^7.10
monolog/monolog Version ^3.10