Repository navigation
Office Framework & Rules
As a framework Office imposes relatively few rules.
The configuration file config.php lives at the root of fannie. All settings are stored in this file and all scripts can include it as needed
This is mentioned in Coding Standards but bears repeating: files may be included at any point and in any order due to testing and/or class autoloading. This must not result in code execution or errors relating to repeat class/function definitions. Using class_exists() or function_exists() calls around include statements helps in the latter case. FannieDispatch is the preferred method for controlling execution.
This is the hard part. Ideally, we'd all keep the same schema. With a little caution, I think we can at least have scripts that degrade gracefully when the underlying structure changes. These are not meant as permanent solutions; there practices should merely streamline schema changes and make them less disruptive. Ideas:
- Grab row values by column name instead of numeric index. As long as the column exists, you'll get the right value, regardless of actual layout
- Use the SQLManager class instead of database-specific functions (e.g., mysqli_connect). I know most people are using MySQL, but I don't see any downside to keeping the system fairly open. If someone wants to run IS4C on top of Postgres, it's a much easier port down the line. There are also a couple bits of handy functionality:
- Use prepared statements for any query involving a variable. The only exception is with code-generators that create snippets of SQL at runtime such as DTransactionsModel::selectDlog (calculate appropriate archive table name) or SQLManager::now (get database-specific datetime function). Anything the database considers data and can be substituted using placeholders and prepared statements should use placeholders and prepared statements. Question mark placeholders are preferred.
- Use the BasicModel classes where feasible. In particular in the case of INSERTs and UPDATEs models will cope with missing or extra columns without crashing. For simple queries models may lead to shorter code compared to manual prepared statements.
- Don't drop and recreate tables that already exist; deleting someone else's data is impolite.
- Publish schema updates via models. Before adding a column to a table and committing the change, ensure that queries involving the table will not break if the new column is missing. Again models can help with INSERTs and UPDATEs. If the column has a default value, which is usually a good idea, models can also help smooth over SELECTs with and without the column. If models do not fit the situation, SQLManager::tableDefinition will provide a list of columns that currently exist in a given table.
Coding Standards and Common Architecture provide additional information about SQL best practices, the SQLManager class, and the BasicModel class.