Book a Demo

Author Topic: PHP property implementation code generation  (Read 3352 times)

riyono

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
PHP property implementation code generation
« on: July 19, 2005, 01:21:35 am »
Hi,
I am a newcomer in OO world. I used to work with PHP and its class and object features, but I never use UML before. I am currently learning about OOA/D, UML, and its implementation on PHP. I heard from a friend of mine that EA can do Forward Engineering to generate PHP code, so I choose to try EA. When I try the code generation feature, I found something fishy on generated PHP code.
I created a simple class called SimpleData with two properties, name and address. I try to generate both Java and PHP code. Here are the results:

Java code:

package Logical Model;

/**
* @version 1.0
* @created 19-Jul-2005 10:05:50 AM
*/
public class SimpleData {

private int name;
private int address;

public SimpleData(){

}

public void finalize() throws Throwable {

}

public int getName(){
return name;
}

/**
*
* @param newVal
*/
public void setName(int newVal){
name = newVal;
}

public int getAddress(){
return address;
}

/**
*
* @param newVal
*/
public void setAddress(int newVal){
address = newVal;
}

}

PHP Code:

<?php


/**
* @version 1.0
* @created 19-Jul-2005 10:06:25 AM
*/
class SimpleData
{

var $name;
var $address;

function SimpleData()
{
}



function getName()
{
}

/**
*
* @param newVal
*/
function setName($newVal)
{
}

function getAddress()
{
}

/**
*
* @param newVal
*/
function setAddress($newVal)
{
}

}
?>

The unexpected results are:
Java code does includes return code on Get, and also value assignment on Set, while PHP Code does not have any of them.
       
       EA generated Java Code:
       ---zapped---
       public int getName(){
return name;
}

/**
*
* @param newVal
*/
public void setName(int newVal){
name = newVal;
}
       ---zapped---
       
       EA generated PHP Code:
       ---zapped---
       function getName()
{
}

/**
*
* @param newVal
*/
function setName($newVal)
{
}
---zapped---

Expected PHP Code:
---zapped---
function getName()
{
   return $this->name;
}

/**
*
* @param newVal
*/
function setName($newVal) // preferably: function SetName($name)
{
   $this->name = $newVal;
}
---zapped--

Can I customize somewhere on EA to make the generated PHP Code includes the return and value assignment on Get and Set? Thanks.
       
Regards,
Riyono.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: PHP property implementation code generation
« Reply #1 on: July 19, 2005, 03:17:47 pm »
Sure, you can modify the code templates to do it.  The easiest way is to use stereotype overrides.

Go to Configuration | UML | Stereotypes.

Add "property get" and "property set" as stereotypes.

Go to Configuration | Code Generation Templates.

Select PHP, and then the Operation Body template.

Add two stereotype overrides where the feature stereotypes are the stereotypes created before.

Fill in each template with what the code should look like.  (Use the Java templates as an example.)

Simon