Skip to content

lib/ namespace map

Everything in lib/ is a reusable library class. Controllers in controllers/ 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
Bdus\Dispatcherlib/Bdus/Dispatcher.phpAuth gate + DI + controller invocation
Bdus\Controllerlib/Bdus/Controller.phpAbstract base for all controllers
Bdus\Utilslib/Bdus/Utils.phpStatic utility helpers
Auth\CurrentUserlib/Auth/CurrentUser.phpRequest-scoped authenticated user
Auth\ApiKeyAuthlib/Auth/ApiKeyAuth.phpAPI key authentication
Auth\Authorizationlib/Auth/Authorization.phpPrivilege check helpers
Auth\Passwordlib/Auth/Password.phpbcrypt hash / verify
JWT\JwtManagerlib/JWT/JwtManager.phpJWT issue / verify / peek
Config\Configlib/Config/Config.phpConfig facade (dot-notation access)
Config\Loadlib/Config/Load.phpConfig bootstrap — picks DB or file loader
Config\LoadFromDBlib/Config/LoadFromDB.phpDB-backed config reader
Config\ToDBlib/Config/ToDB.phpPersists config changes to DB
Config\ToFileslib/Config/ToFiles.phpConfig → JSON file writer (legacy fallback)
Config\AppSettingslib/Config/AppSettings.phpApp-level settings reader
Config\GeofaceConfiglib/Config/GeofaceConfig.phpGeoFace / map layer config
Config\ConfigExceptionlib/Config/ConfigException.phpConfig-specific exception
DB\DBlib/DB/DB.phpPDO wrapper (SQLite / MySQL / PostgreSQL)
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 tool availability
DB\Validate\Filesystemlib/DB/Validate/Filesystem.php.htaccess / filesystem 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/24 migration classes (M001–M024)
DB\Engines\AvailableEngineslib/DB/Engines/AvailableEngines.phpLists supported DB engines
DB\LogDBHandlerlib/DB/LogDBHandler.phpMonolog handler → bdus_log table
SQL\QueryFromRequestlib/SQL/QueryFromRequest.phpMain query builder — converts $request array to SQL
SQL\QueryObjectlib/SQL/QueryObject.phpLow-level fluent query builder (internal)
SQL\Filter\JsonFilterlib/SQL/Filter/JsonFilter.phpDirectus-style filter → SQL WHERE
SQL\Filter\FilterExceptionlib/SQL/Filter/FilterException.phpFilter-specific exception
SQL\Validatorlib/SQL/Validator.phpField / operator allow-list checks
SQL\SqlExceptionlib/SQL/SqlException.phpSQL-layer exception
Record\Readlib/Record/Read.phpFetches record + plugins + links + files
Record\Editlib/Record/Edit.phpValidates + prepares record edits
Record\Persistlib/Record/Persist.phpLow-level persistence (INSERT/UPDATE/DELETE)
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)
Zotero\Clientlib/Zotero/Client.phpZotero API HTTP client
Zotero\ZoteroExceptionlib/Zotero/ZoteroException.phpZotero-specific exception
lib/bootstrap.phpConstants, DB connection, auth setup
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}/.jwt_secret (mode 0600), generated on first use if absent. The legacy location projects/{app}/cfg/.jwt_secret is probed for backwards compatibility.


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\QueryFromRequest is the main entry point for all data queries. It converts a structured $request PHP array (with a type key: all, fast, sqlExpert, or filter) into a PDO-prepared SELECT statement. See SQL layer.

SQL\Filter\JsonFilter parses Directus-style filter arrays (['field' => ['_eq' => 'value']]) into SQL WHERE clauses.

SQL\QueryObject is the low-level fluent builder used internally by QueryFromRequest. Not called directly by controllers.


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

UAC\Loader builds the per-user, per-table privilege list (UAL) from bdus_user_table_privs. 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/.