Extension internal classes division of labor
The aim of the whole collection is to speed up somewhat an already fast set of classes in PHP script, of about 30-40 common request processing classes of a function found in recent recommended frameworks, plus an over-ambitious database access extension project.
nm --demangle modules/wcc.so | grep FTAB
00000000001650a0 B zpp::FTAB
PHP extensions share their memory and callable addresses with each other. So I split up a large collection of objects that used zpp arbitrarily into 5 extensions. The first wccz.so extension a dependency for the others. To make this division explicit, a name_extn.cxx exists for each extension, which pulls in required C++ class files and includes a registration function to register them if they are included. All the files are in the projects /src folder.
CXXFLAGS="$CXXFLAGS -Wall -O2 --std=c++23 -I./include -I../src"
It is only neccessary to include the header files for zpp , and source files for the classes, in the extension source, and only the "z" extension contains the source files for zpp. The principle is that a binary version of a callable function only needs to exist in one loaded extension and should be then callable from the others.
Initially these were in seperate git repositories, then merged to one big one, which makes moving a class to one extension instead of another an easier task. Below is a list are the extension - class name details as of the time of typing this.
wccz (wcc-zero.git)
Files included in wcc/zero_extn.cxx. Classes below are in the root php namespace path of Wcc. | Class | File | Description | |-------|------|-------------| | zpp::* | zpp/base.cpp | All low level classes in zpp namespace | | dump_info | zpp/show_zpp.cpp | Dump explict interiors of Zend structures | | Assets | wcc/assets.cpp | Insert links, css, javascript, html blobs into views | | Config | wcc/config.cpp | Store dynamic property values | | DebugLog | wcc/debuglog.cpp | Minimal logging facility with access to dump_info | | Dos | wcc/dos.cpp | File system directory list, create, delete | | Module | wcc/module.cpp | Module settings, assets, file paths, dependency | | ReflectCache | wcc/reflect_cache.cpp | Create objects from their reflection class | | Replace | wcc/replace.cpp | Replace variable names in a string with properties in object, using pcre | | SearchList | wcc/search_list.cpp | Ordered list of directory paths | | Services | wcc/services.cpp | Store and retrieve callable dynamic properties and objects | | ServiceAccess | wcc/service_access.cpp | Cached Services values locally by magic __get | | Str | wcc/strfns | Str class with static functions |
wccr (wcc-route.git)
Files included in wcc/routes_extn.cxx. These wcc classes also use some of the wcc classes in wccz, as well as zpp, by including their header files.
| Class | File | Description |
|---|---|---|
| ICache | wcc/icache.cpp | Base class for access to data/file cache |
| ICacheData | wcc/icachedata.cpp | A managed package of serialized cached data |
| DirCache | wcc/dircache.cpp | Specialized ICache that stores data as files with hashed names in directory |
| CacheMgr | wcc/cachemgr.cpp | Managed mamed caches with different properties |
| Dispatch | wcc/dispatch.cpp | |
| FileUpload | wcc/file_upload.cpp | Stores data to manage file uploads |
| Finder | wcc/finder.cpp | Search namespace name indexed paths for class source files |
| Hmap | wcc/hmap.cpp | Store indexed values in an array. Mediates global PHP request data |
| ISession | wcc/issession.cpp | Mediates between UserSession and PHP session array and functions |
| Loader | wcc/loader.cpp | Implements custom PHP autoloader via spl_autoload_register() function |
| Pair | wcc/pair.cpp | Hold two property values named "one" and "two" |
| RequestGlobals | wcc/request_globals.cpp | Access to the "SuperGlobals" data for HTML |
| Response | wcc/global_response.cpp | Interface to setup HTML response and send |
| Route | wcc/route.cpp | A URL, verb, and target object - method details |
| RouteMatch | wcc/route_match.cpp | One of these to hold reorganised route details for dispatch |
| RouteSet | wcc/routeset.cpp | A collection of Route objects, divided into fixed URL and Regular expression routes to match |
| SysCache | wcc/syscache.cpp | Mediator of Session cache and selectively adjusts session expiry time |
| Target | A simple 3-tuple of Class name, method name, and module name for a route | |
| UserData | userdata.cpp | Class to save users session details |
| UserSession | usersession.cpp | Class to hold session management data |
wcch (wcc-html.git)
Files included in html_extn.cxx. Generally classes for organising execution of template html views, which have PHP code, and functions to generate common html elements.
| Class | File | Description |
|---|---|---|
| HtmlGem | wcc/htmlgem.cpp | Generate various Html elements from array parameters |
| HtmlPlates | wcc/htmlplates.cpp | Help organise templates as onion layers, from inside to out |
| MarkToHtml | md2html | Adoption of C-coded project md4c-html, to generate html from markdown |
| MoneyFmt | wcc/money_fmt.cpp | Simple interface to PHP currency formats. |
| Plate | wcc/plate.cpp | Short for template. Hold location and data for a template |
| PlateEngine | wcc/plate_engine.cpp | Manage templates, their data and cache outputs |
| SearchList | wcc/search_list.cpp | Ordered list of folders and search for files |
wccm (wcc-more.git)
Files included in more_extn.cxx.
| Class | File | Description |
|---|---|---|
| XmlRead | wcc/xmlread.cpp | Read xml format specifying PHP data, objects and arrays |
| Toml | toml/toml_php.cpp | A fast toml format reader in C code by https://github.com/cktan/tomlcpp |
The toml read implementation uses source from https://github.com/cktan/tomlc99 - Copyright (c) CK Tan. It was found to be well organised C source code, and enabled the C memory allocator function pointers to be using PHP functions emalloc and efree. This ensured memory C allocations made request memory.
wccd (wcc-database.git)
Extension includes assembled in database_extn.cxx. These classes are all in the root namespace path of Wcd. This is a little complex to layout. A series of classes handle different parts of putting together a SQL query for a generator for different SQL dialects. The division of labor between the various classes might change in future, meaning that its not perfect.
Classes from sqlipart.stub.php. Namespace is Wcd\Sql. Classes which implement interface IfSqlPart. | Class | File | Description | |--------|------|-------------| | SqlPartId | wcd/sql_ipart.cpp | Has an identification id which helps assemble a SQL query | | Expr | | Just a simple raw string "expression" that may be needed as is, in a SQL query | | JoinExpr | | Formal expression with left part, and right part, with an operator between, and connect boolean operator | | TableAttr | | Formal name of table, or alias, and a column name, seperated by a dot | | Param | | Stores a value that meant as a SQL query parameter value | | Literal | | Stores a value meant as direct literal value in a SQL query | | IColumns | | Holds a collection of column names associated with table name or alias | | TColumns | | A IColumns with a table name |
More classes from sqlipart.stub.php. Namespace is Wcd\Sql. | Class | File | Description | |--------|------|-------------| | JoinInfo | wcd/sql_isql.cpp | Holds a single join type, left, right objects, and list of join conditions | | JoinTables | wcd/sql_isql.cpp | Potential recursive list of Joins |
Sql generation
| Class | File | Description |
|---|---|---|
| ISql | wcd/isql.cpp | Root class of SQL generator. Default dialect is Mysql. Implements interface IfSql |
| Postgres | wcd/postgres.cpp | Override ISql virtual functions for postgresql dialect |
| Bindings | wcd/bindings.cpp | Stores under a integer constant key, various parts of assembled query |
| Delete | wcd/delete.cpp | Class to simplify doing a Delete row sql operation |
| Insert | wcd/insert.cpp | Class to simplify doing an Insert row sql operation |
| Operation | wcd/operation.cpp | Base class of building a SQL operation |
| Select | wcd/select.cpp | Doing a Select sql operation |
| Simple | wcd/simple.cpp | Prepare low level sql text and parameters |
| Runsql | wcd/runsql.cpp | Do interaction with database object for SQL operation |
| Update | wcd/update.cpp | Do an Update sql operation |
| IParams | wcd/iparams.cpp | Keeps track of ordered SQL parameters |
| NamedParams | wcd/namedparams.cpp | Keeps track of named SQL parameters |
Database interaction classes
| Class | File | Description |
|---|---|---|
| IConfig | wcd/iconfig.cpp | Configure database connection parameters, drivers and class names |
| IDriver | wcd/idriver | Base database connect class. |
Database drivers in namespace Wcd\Ext, stub/pdo_drivers.stub.php. Database access is through various php extensions.
| Class | File | Description |
|---|---|---|
| PdoDriver | wcd/pdodriver.cpp | IDriver base class for PDO drivers |
| PdoMysql | wcd/pdo_mysql.cpp | Pdo for mysql database |
| PdoPgsql | wcd/pdo_pgsql.cpp | Pdo for postgres database |
| Pgsqlfn | wcd/pgsqlfn.cpp | Using PHP pgsql extension, not PDO |
| Mysqlfn | wcd/mysqlfn.cpp | Using PHP mysql extension, not PDO |
Generic "Active record" support.
| Class | File | Description |
|---|---|---|
| Model | wcd/model.cpp | One model class instance per database table |
| IRow | wcd/irow.cpp | A simple 2 arrays, one for current values, one for any updates, and Model object reference |
| IBuild | wcd/ibuild.cpp | A mediator class object to manage Model operations. |