Code details

The code is namespaced ; main namespace name is g5.
Code is PSR-4 (namespace hierarchy corresponds to directory hierarchy, like in java).
Top-level namespace (g5) is located in src/.

All transformations on data are done in package g5\commands.

Association CLI - executed code

The command line interface (CLI) is handled by run-g5.php. To interpret the parameters typed by the user, a convention is used.
The program uses the notions of
  • data set (like cura for, newalch for,
  • data file within a data set (like file A2),
  • action (like raw2tmp, which means "convert raw file to csv file").

Each data set corresponds to a sub-package of g5\commands.
Each datafile corresponds to a sub-package of dataset's package.
Each action corresponds to a class located in this sub-package.
For example, code operating on file 3a_sports.txt from is located in package g5\commands\newalch\ertel4391.

When the user types a command, the CLI checks, in this order :
  • Does this dataset have a class implementing interface g5\patterns\Command ? If yes, the parameters are passed to the execute() method of this class.
    Dataset's command takes the control and can re-interpret parameters and makes a custom dispatch to command(s) of sub-packages.
    cura and g5 datasets use this mechanism.
  • If not, CLI tries to find a class g5\commands\dataset\datafile\action and call its method execute().
    This is the default mechanism which permits to add new datasets and new datafiles automatically handled by the system, if no class implementing Command is present in the dataset's namespace.

In both cases, the CLI doesn't know anything else about the class that will execute. It only selects the right code to call and passes the parameters (a Command design pattern is used).

Examples :
  • php run-g5.php cura A raw2tmp : the code sees that there is a class g5\commands\cura\CuraCommand, so this class is called.
  • php run-g5.php ertel sport look profession : there is no class implementing Command in package g5\commands\newalch, so class g5\commands\newalch\ertel4391\look will be called, and one parameter, profession will be passed to the method execute().
Implementation of this convention can be found in the package hierarchy, and in the code of class g5\Run