This was build for PHP5. But, I suppose you could use it a base for other languages as well.
Not a lot to it, just enter a comma-separated list of variables which you want to be included in the output. The output was written with the intention that the methods would be used in a "data object". This is a common way to make sure that you have a sanitized, standard set of variables that you can pass into other methods. You can build on this to add custom functionality - but I have found this to be a huge timesaver. Examples follow.
project_id, project_name, is_active, date_created
When you click the button below, you will see the generated properties & methods.
For the purposes of this sample, assume you have used the results of this generator to create a data object which represents a project. Luckily, we have used project-related terms in the variable samples above. So, you have a class that contains getters and setters for a project data object.
$new_project = new ProjectDataObj();
$new_project->set_project_name('Test Project');
$new_project->set_is_active(true);
// Now, let's use the standardized project data object to create a new project.
// Let's assume you have a Project class that handles all your Project data CrUD
try {
$projects = new Projects();
$projects->create_new( $new_project );
}
catch (Exception $e) {
echo "Failed to create project: ".$e->getMessage();
}
To understand this a bit better, you would want to see the details behind the create_new() method. It would require that the argument it takes is an object - specifically an object of type ProjectDataObj - which we created using the get/set methods generated here.
// Snippet of the create_new() method out of context from the Projects class
function create_new( ProjectDataObj $data ) {
// do something to create the project
try {
$this->_validate_data($data);
$id = $this->_create_project_record($data);
$manager_id = $this->_get_available_project_mgr();
$this->_assign_project_manager($id, $manager_id );
// done!
}
catch (Exception $e) {
throw new Exception("Failed to create project.");
}
return true;
}