Skip to content

lib/ namespace map

Everything in lib/ is a reusable library class. Controllers in modules/ consume these classes; they never access the database or filesystem directly without going through a lib/ abstraction.


Namespace overview

Namespace / filePathRole
Bdus\Applib/Bdus/App.phpApplication orchestrator
Bdus\Routerlib/Bdus/Router.phpFastRoute dispatcher + privilege map
Controllerlib/Controller.phpAbstract base for all module controllers
autoLoaderlib/autoLoader.phpCustom class resolver
Auth\CurrentUserlib/Auth/CurrentUser.phpRequest-scoped authenticated user
Auth\ApiKeyAuthlib/Auth/ApiKeyAuth.phpAPI key authentication
JWT\JwtManagerlib/JWT/JwtManager.phpJWT issue / verify / peek
Config\Configlib/Config/Config.phpYAML config facade (dot-notation)
Config\Loadlib/Config/Load.phpLoads config from DB
Config\LoadFromDBlib/Config/LoadFromDB.phpDB-backed config reader
Config\ToDBlib/Config/ToDB.phpPersists config changes to DB
Config\ToFileslib/Config/ToFiles.phpConfig → YAML file writer (legacy)
Config\AppSettingslib/Config/AppSettings.phpApp-level settings (status, name…)
Config\GeofaceConfiglib/Config/GeofaceConfig.phpGeoface / map layer config
DB\DBlib/DB/DB.phpPDO wrapper (multi-engine)
DB\DBInterfacelib/DB/DBInterface.phpDB contract
DB\DBExceptionlib/DB/DBException.phpDB exceptions
DB\Inspectlib/DB/Inspect.phpEngine-dispatch for schema introspection
DB\Inspect\Mysqllib/DB/Inspect/Mysql.phpMySQL introspection
DB\Inspect\Postgreslib/DB/Inspect/Postgres.phpPostgreSQL introspection
DB\Inspect\Sqlitelib/DB/Inspect/Sqlite.phpSQLite introspection
DB\Alterlib/DB/Alter.phpEngine-dispatch for schema modification
DB\Alter\Mysqllib/DB/Alter/Mysql.phpMySQL ALTER operations
DB\Alter\Postgreslib/DB/Alter/Postgres.phpPostgreSQL ALTER operations
DB\Alter\Sqlitelib/DB/Alter/Sqlite.phpSQLite ALTER operations
DB\Export\Exportlib/DB/Export/Export.phpExport orchestrator
DB\Export\CSVlib/DB/Export/CSV.phpCSV export
DB\Export\JSONlib/DB/Export/JSON.phpJSON export
DB\Export\XLSXlib/DB/Export/XLSX.phpExcel export
DB\Validate\Validatelib/DB/Validate/Validate.phpValidation runner
DB\Validate\DbCfgAlignlib/DB/Validate/DbCfgAlign.phpDB ↔ config schema alignment
DB\Validate\DumpExistslib/DB/Validate/DumpExists.phpChecks backup files
DB\Validate\Filesystemlib/DB/Validate/Filesystem.phpFilesystem sanity
DB\Validate\Infolib/DB/Validate/Info.phpApp info collector
DB\Validate\Resplib/DB/Validate/Resp.phpValidation response builder
DB\Validate\SystemTableslib/DB/Validate/SystemTables.phpChecks required system tables
DB\System\Managelib/DB/System/Manage.phpCRUD on system/data tables
DB\System\CreateApplib/DB/System/CreateApp.phpNew application wizard
DB\System\Migratelib/DB/System/Migrate.phpSchema migration runner
DB\System\Migrations\Mxxxlib/DB/System/Migrations/22 individual migration classes (M001–M022)
DB\Engines\AvailableEngineslib/DB/Engines/AvailableEngines.phpLists supported DB engines
DB\LogDBHandlerlib/DB/LogDBHandler.phpMonolog handler → bdus_logs table
SQL\QueryObjectlib/SQL/QueryObject.phpSQL query builder
SQL\SafeQuerylib/SQL/SafeQuery.phpPDO-prepared statement executor
SQL\ShortSql\ParseShortSqllib/SQL/ShortSql/ParseShortSql.phpShortSQL → QueryObject
SQL\ShortSql\*lib/SQL/ShortSql/ShortSQL clause parsers (8 classes)
SQL\Validatorlib/SQL/Validator.phpSQL safety checks
Record\Readlib/Record/Read.phpFetches record + plugins + links + files
Record\Editlib/Record/Edit.phpValidates + persists record edits
Record\Persistlib/Record/Persist.phpLow-level persistence layer
UAC\UAClib/UAC/UAC.phpPrivilege enforcement
UAC\Loaderlib/UAC/Loader.phpBuilds per-table UAL from DB
Template\Loaderlib/Template/Loader.phpLoads Twig print templates from DB
Image\Resizerlib/Image/Resizer.phpImage resize / thumbnail (Intervention)
lib/version.phpBDUS_VERSION constant

Namespace detail

Auth\ — Request authentication

CurrentUser is a static request-scoped store. Populated once in constants.php from validated JWT claims (or API key record), then read anywhere:

php
Auth\CurrentUser::id()              // int|null
Auth\CurrentUser::privilege()       // int|null  (1=superadmin … 40=readonly)
Auth\CurrentUser::isAuthenticated() // bool
Auth\CurrentUser::isApiKey()        // bool (false for JWT users)

ApiKeyAuth handles Authorization: Bearer {key} / ?api_key= auth. Plain-text keys are never stored — only SHA-256 hashes in bdus_api_keys.


JWT\ — Token management

JwtManager is a thin wrapper around firebase/php-jwt.

MethodPurpose
generate(user, app)Issues a signed JWT (1-day expiry)
decode(token, app)Verifies signature + expiry, returns claims
peekApp(token)Reads app claim without verifying (loads the right secret)
refresh(token, app)Issues a new token from a still-valid one

Per-app secrets live at projects/{app}/cfg/.jwt_secret (mode 0600), generated on first use if absent.


Config\ — Application configuration

Config provides dot-notation access to the merged config:

php
$cfg->get('main.status')           // app status string, e.g. 'on'
$cfg->get('tables.0.name')         // first table name
$cfg->get('geoface.layers.0.url')  // first map layer URL

Config is stored in DB (since M011) in bdus_cfg_* tables. Config\Load reads from DB; Config\ToDB / Config\ToFiles persist changes.

See Config & UAC for the full schema.


DB\ — Database abstraction

DB\DB wraps PDO and dispatches schema operations to engine-specific implementations. Key method:

php
$db->query($sql, $params, 'read')      // returns rows array
$db->query($sql, $params, 'boolean')   // returns true|false
$db->query($sql, $params, 'id')        // returns last insert id

DB\Inspect introspects the live schema (column list, indexes, …). DB\Alter modifies the schema (add/rename/drop columns and tables). Both dispatch to engine-specific Mysql, Postgres, or Sqlite classes.

DB\System\Manage is the high-level CRUD layer for system and data tables:

php
$mgr = new Manage($db);
$mgr->getBySQL('bdus_users', 'email = ?', [$email]);
$mgr->editRow('bdus_users', $id, ['oauth_sub' => $sub]);

DB\System\CreateApp orchestrates new-application creation: creates the DB, installs system tables, seeds initial config.

DB\System\Migrate runs pending migrations. See DB migrations.

See Database layer for the full reference.


SQL\ — Query building

SQL\QueryObject is the safe SQL builder. All data queries go through it.

SQL\ShortSql\ParseShortSql parses the ShortSQL DSL used by the public REST API into a QueryObject. See SQL layer.

SQL\SafeQuery is the low-level PDO executor used by DB\DB.


Record\ — Record lifecycle

Record\Read assembles a complete record response: fields + plugin rows + manual links + files.

Record\Edit validates incoming data and delegates to Record\Persist.

Record\Persist writes a single atomic change: INSERT / UPDATE / DELETE.

See Record lifecycle.


UAC\ — Access control

UAC\UAC enforces privilege levels per-table. Privilege levels:

LevelConstantMeaning
1UAC::SUPERADMSuper admin — full access including schema changes
10UAC::ADMAdmin — user management, backups, logs
25UAC::CREATEEditor — read + write records
30UAC::READReader — read-only
40UAC::READONLYStrict read-only (also public API keys)

UAC\Loader builds the per-user, per-table privilege list (UAL) from bdus_user_table_privileges. See Config & UAC.


Template\ — Print templates

Template\Loader reads Twig template source from bdus_cfg_templates (DB-backed since M011). Provides compiled templates for print / preview.


Image\ — Image handling

Image\Resizer uses intervention/image to resize uploads to thumbnails and to serve resized versions on demand from cache/img/.