Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Find a way to document 'enumerations' imposed by some SimpeTypes #35

Open
goetas opened this issue Nov 6, 2014 · 21 comments
Open

Find a way to document 'enumerations' imposed by some SimpeTypes #35

goetas opened this issue Nov 6, 2014 · 21 comments
Labels

Comments

@goetas
Copy link
Owner

goetas commented Nov 6, 2014

Find a way to document 'enumerations' imposed by some SimpeTypes.

A possible way can be:

/**
 * Set the code doc...
 * @param string $code ... Possible values: 'A', 'B', 'C'
 */
public function setCode($code){
}

or

/**
 * Set the code doc...
 * Possible values: 'A', 'B', 'C'
 * @param string $code ...
 */
public function setCode($code){
}
@goetas
Copy link
Owner Author

goetas commented Nov 6, 2014

Related to #34

@rtek
Copy link

rtek commented Nov 6, 2014

Id go with option 2 as the list can get very long.
May I request that $code is validated against possible values as well?

@goetas
Copy link
Owner Author

goetas commented Nov 6, 2014

@rtek I have in mind to generate Symfony validation xml rules and validate the object against these definitions.

@goetas
Copy link
Owner Author

goetas commented Nov 6, 2014

The option 2 will be used just as suggestions

@rtek
Copy link

rtek commented Nov 6, 2014

In the case of named xs:simpleType, you may want to keep the empty class that contains the constants. It's convenient to have them during development.

<xs:simpleType name="typeOfMeter">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Coal"/>
            <xs:enumeration value="Oil"/>
    </xs:restriction>
</xs:simpleType>
class TypeOfMeter
{
    const COAL = 'Coal';
    const OIL = 'Oil';
}

In the case of anonymous xs:simpleType, I agree that documentation would be sufficient.

<xs:element name="unitOfMeasure">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:enumeration value="ccf (hundred cubic feet)"/>
            <xs:enumeration value="cf (cubic feet)"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

@goetas
Copy link
Owner Author

goetas commented Nov 6, 2014

@rtek this will cause to have a lot of empty classes... (and useful just as code suggestion)

  • OTA XML has around 15% of empty classes.
  • www.irs.gov has around 1000/4000 of empty classes.

@goetas goetas added the question label Nov 7, 2014
@RSully
Copy link
Contributor

RSully commented Nov 26, 2014

Right now it looks like these enums aren't being handled at all (other than getters/setters - I don't even see any suggestions in the docblocks). I do agree that having constants is very helpful - maybe a necessity.

@ramittal
Copy link

There were classes generated for Enums prior to closing the issue#33 and they seems to work well. Why was this regressed? Will it be possible to bring that back so that I do not have to hardcode the strings? I would really like to see the Enums being handled as first class objects so that I do not have to deal with string casings and spelling errors.

@goetas
Copy link
Owner Author

goetas commented Dec 12, 2014

At the beginning there was enums... but after #34 i've removed them. later, with 21b6d09 i have simplified the generated classes (less extensions when extending a base type).

I would really like to see the Enums being handled as first class objects so that I do not have to deal with string casings and spelling errors.

But looking the issue form a different perspective, enums can be useful even for code suggestion. The drawback is that big XSDs will have a lot of classes... but I think that I should re-implement it somehow.

Unfortunately at the moment I'm changing home, town and country, so I can get into this most probably in mid-January.

This project is still in "dev" just because I do not have a clear idea of how to make things in the right way. Thanks to yours issues and contributions I'm trying to find the most convenient way to handle XSD serialization-deserialization (things already solved in Java on .NET... )

I have a dream :-) : implement a suite of tools that allows to consume/produce webservices i a "Mucrosoft Visual Studio" way... just one click to import a WSDL, and use it in a object oriented way. I want to forget all XML stuff that works behind the scene.

@rtek
Copy link

rtek commented Dec 13, 2014

Have you considered making enum class generation optional via flag and also doing the doc-block route? Everyone gets covered that way.

@goetas
Copy link
Owner Author

goetas commented Dec 13, 2014

The option for enum classes is a good idea!

Doc block route? What you mean?

@rtek
Copy link

rtek commented Dec 14, 2014

I would also include the list of possible values in the generated comments / doc block too. That way people still have access via IDE if they disable generated enum classes.

@davispeixoto
Copy link

I think this project can be used as dependency

"myclabs/php-enum" : "1.3.2"

Also, generate support for IDE auto-completion would be simples as

use MyCLabs\Enum\Enum;

/**
 * @method static Action VIEW()
 * @method static Action EDIT()
 */
class Action extends Enum
{
    const VIEW = 'view';
    const EDIT = 'edit';
}

@RSully
Copy link
Contributor

RSully commented May 12, 2015

@davispeixoto not a fan of using a subclass like this personally - maybe if it were implemented as a trait

@demonkoryu
Copy link

+1 for enums. ATM enumerations are just discarded. :(

@demonkoryu
Copy link

I've hacked something together that is enough for me ATM:

rtsde/xsd2php@0468ebe

I'll issue a PR when I've cleaned it up and there's interest.

@discordier
Copy link
Contributor

Could you change the commit so that you don't use auto reformatting which changes the whole file but only commit changes in the relevant lines?

I can not determine what you have changed.

@apropos
Copy link

apropos commented Jan 15, 2016

with XML as follow

<xsd:element name="Type">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="ISBN"/>
            <xsd:enumeration value="UPC"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

is it possible to do something like following while removing invalid chars from method name?

public function withTypeISBN()
{
    $this->type = 'ISBN';
    return $this;
}
public function withTypeUPC()
{
    $this->type = 'UPC';
    return $this;
}

@zarubaj
Copy link

zarubaj commented Apr 2, 2019

What do you say about https://github.com/consistence/consistence ?

@goetas
Copy link
Owner Author

goetas commented Apr 2, 2019

How this lib should help?

@zarubaj
Copy link

zarubaj commented Apr 2, 2019

It's like a library "myclabs/php-enum" by @davispeixoto . The advantage is JMS Serializer integration

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

9 participants