-
Notifications
You must be signed in to change notification settings - Fork 62
Implement add-prefix option for convert:php #77
base: master
Are you sure you want to change the base?
Conversation
I like this PR. Here you can find the reason behind the "addTo" prefix. Is your idea still valid? |
Hmm, I don't know. The example given there is correct in my opinion, but the generate code actually generates something else. I think it has something to do with the plural/singular form of the method. The following example will make things more clear. <xs:complexType name="accommodation">
<xs:sequence>
...
</xs:sequence>
</xs:complexType>
<xs:element name="accommodations">
<xs:complexType>
<xs:sequence>
<xs:element name="accommodation" type="accommodation" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element> This produces the following classes: class Accommodations
{
/**
* @property AccommodationType[] $accommodation
*/
private $accommodation = null;
/**
* Adds as accommodation
*
* @return self
* @param AccommodationType $accommodation
*/
public function addToAccommodation(AccommodationType $accommodation)
{
$this->accommodation[] = $accommodation;
return $this;
}
/**
* isset accommodation
*
* @param scalar $index
* @return boolean
*/
public function issetAccommodation($index)
{
return isset($this->accommodation[$index]);
}
/**
* unset accommodation
*
* @param scalar $index
* @return void
*/
public function unsetAccommodation($index)
{
unset($this->accommodation[$index]);
}
/**
* Gets as accommodation
*
* @return AccommodationType[]
*/
public function getAccommodation()
{
return $this->accommodation;
}
/**
* Sets a new accommodation
*
* @param AccommodationType[] $accommodation
* @return self
*/
public function setAccommodation(array $accommodation)
{
$this->accommodation = $accommodation;
return $this;
}
}
class AccommodationType
{
//...
} I would expect one of the following add-methods:
But the generator produces addToAccommodation which to me sound really strange... Or am I missing something else here? :-) |
Hmm... most probably because of the If you consider this example: <xs:element name="city">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xsd:string"/>
<xs:element name="accommodations" type="accommodations"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="accommodations">
<xs:sequence>
<xs:element name="accommodation" type="accommodation" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="accommodation">
<xs:sequence>
...
</xs:sequence>
</xs:complexType> This will generate only a class Accommodation {
// ...
}
class City {
protected $name;
protected $accomodations = array();
public function addToAccomodations(Accomodation $accomodation) {
$this->accomodations[] = $accomodation;
}
// ....
} In this case, IMO, |
An "array" type is a different thing compared to an "array" element... most probably they should be handled differently... |
Of course, the case exposed by you ("array elements") having just |
Can you check if this (https://github.com/goetas/xsd2php/tree/adder-name) branch works for you? |
No, that branch still does not work for me. In PhpConverter.php line 169, a ComplexType is passed to the isArrayElement method for accommodations which causes the isArray to be null since it is not an instance of ElementSimple. I'll try to do some debugging as well in the next few days. |
Hello
When converting an XSD to PHP classes, you are using the addTo... notation to add multiple elements. I'm not a huge fan of this notation so I've made this configurable.
It is now possible to do this...
...which will result in for example "addElement" instead of "addToElement".
If a developer does not provide the option, nothing will change and "addTo" will still be used.