Each client generator should be based on the following functionality:
- Copy the template to a temp folder.
- Generate code based on the template and the service information.
It must be a class contained within a folder dropped in the ‘BackOffice/ClientGenerator/Generators’ folder. For example the generator for Flash Creative Suite is defined in the AmfphpFlashClientGenerator class in the AmfphpFlashClientGenerator.php file in the AmfphpFlashClientGenerator folder.
The code generation works with generation directives in the template. The idea is to put as much intelligence as possible in the template vs putting intelligence in the php code.
Template code files contain directives. These take the form of comments that the generator can recognize. The idea here is that the template should compile, though not be usable as such.
Each code file contains blocks of code that need to be duplicated for each service, method, and parameter. These directives simply indicate the delimitations of these blocks.
For example considering that there are two services, Service1 and Service2. The following block will be replaced by the code below. The generator recognizes the ACG_SERVICE directives, and therefore knows that it must duplicate the code between as many times as there are services, and replace the string ‘_SERVICE_’ by the respective service name.
public var show_SERVICE_UiBtn:ShowServiceButton;
This code in a template would be converted to this :
public var showService1UiBtn:ShowServiceButton;
public var showService2UiBtn:ShowServiceButton;
Furthermore, blocks can contain subblocks.
This code generates code for each method and each parameter.
public var _METHOD___PARAM__Input:TextField;
public var _METHOD__callButton:Sprite;
If there were two methods, method 1 and method 2, each with parameters param1 and param2, this would be replaced by:
public var method1_param1_Input:TextField;
public var method1_param2_Input:TextField;
public var method1_callButton:Sprite;
public var method2_param1_Input:TextField;
public var method2_param2_Input:TextField;
public var method2_callButton:Sprite;
Available directives are :
- ACG_SERVICE. Indicates the limits of a service list block. Block within is multiplied for as many times as there are services. The keyword _SERVICE_ is replaced by the service name.
- ACG_METHOD. Indicates the limits of a method list block. Can only be within a service list block. Block within is multiplied for as many times as there are methods in the service. The keyword _METHOD_ is replaced by the method name.
- ACG_PARAMETER. Indicates the limits of a parameter list block. Can only be within a method list block. Block within is multiplied for as many times as the method has parameters. The keyword _PARAMETER_ is replaced by the parameter name.
- ACG_PARAMETER_COMMA. Similar to ACG_PARAMETER, but adds commas in between each parameter.
- ACG_AMFPHP_ENTRY_POINT_URL. Replaced by the amfPHP entry point url.
Furthermore, if a file name contains ‘_SERVICE_’, the whole file is considered a service block, and as many files as there are services will be generated.