Subscribe: Posts / Comments / Email


RSS

CodeGen 1.0

Sun, Mar 15, 2009

Projects

Don’t you just hate having to create all of the Amfphp server database files, and then all of the value objects, then mirror that on the client side with the same things but in Flex builder?

Well I did, so I have decided to create a little generator that will create all of the following from an XML file.

  1. Cairngorm Folder Structure
  2. Cairngorm Service Locator – ( service per-table )
  3. Cairngorm Service Delegate ( per-table )
  4. Cairngorm Commands ( per-table; save, remove, get )
  5. Cairngorm Events ( per-table; save, remove, get )
  6. Cairngorm Value Objects – ( per-table )
  7. Cairngorm Model Locator – ( per-application )
  8. Cairngorm Controller – ( per-application )
  9. Table Main – ( per-table )
  10. PHP Service files – ( per-table )
  11. PHP Value Objects – ( per-table )

And that’s not all.

Every file is generated from a template which is included in the download, you can change the templates, just be sure to look over the template key at the top of the file.

Also I guarantee this to be a full CRUD application on your MySQL database using Amfphp.

Most generators aren’t reliable or either working out of the box right from being generated, so I was just like screw that, I am going to make this, just because I hate copy and pasting my old scripts time and time again just to do the same thing.

The features that it generates:

  1. Flex validation on all table columns that are required.
  2. Flex Data Grid listing all of the records in the database.
  3. Flex Form that lets you view the details of the selected record, and/or editing/creating of a new record.

Here is how to use this CodeGen

1. Require the php script inside of your file. ( just use the one included )

require_once 'CodeGen.php';

2. There is a config.xml file that is in the output folder, open it up and fill in your info.

(<)config>
	 	(<)host>localhost
	 	(<)user>root
	 	(<)pass>pass
	 	(<)schema>test
		(<)endpoint>http://localhost/amfphp/gateway.php
		(<)namespace>com.namespace.project
(<)/config>

3. Create a new instance of the CodeGen specifying the config.xml file as a constructor argument

4. Use this to write a copy of your database schema in the output folder.

$codegen->writeSchema();

5. After you have your schema, you this below to generate the code.

$codegen->generateCode( $schema );

6. Just drop inside the services folder of your Amfphp installation, and your ready to roll.

  • Server side gets generated into the output/server folder – You place this inside of the Amfphp/services folder, starting with the namespace root folder, ie. com/namespace/project
  • Client side get generated into the output/client folder – You place this inside of your src folder of your Flex builder project, also make sure you have the Cairngorm.swc inside of your libs folder of your Flex project.

7. Here is a full example of how to use it.

require_once 'CodeGen.php';

$schema = 'output/TestSchema.xml';
$config = 'output/config.xml';

$codegen = new CodeGen ( $config );
//$codegen->writeSchema();
$codegen->generateCode ( $schema );

If you have any trouble please just send me an email and I will help you in full

Download it here.
CodeGen_1_0 (54)

Tags: ,

Leave a Reply