Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert minOccurs and restriction into Doctrine annotation Require and Enum #70

Closed
wants to merge 1 commit into from

Conversation

kernio
Copy link

@kernio kernio commented Oct 27, 2018

  • Adding new fields into PHPProperty class (required and enum)
  • Based on parsing adding require or enum data into generated class
  • Add unit test

Example xsd:

            <xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
                <xs:element name = "Tshirt">
                   <xs:complexType>
                      <xs:sequence>
                         <xs:element name = "Color" type = "clothesColorType" minOccurs="0"/>
                         <xs:element name = "Size" type = "clothesSizeType"  minOccurs="1"/>
                      </xs:sequence>
                   </xs:complexType>
                </xs:element>
                   
                <xs:simpleType name="clothesSizeType">
                   <xs:restriction base="xs:string">
                      <xs:enumeration value="S" />
                      <xs:enumeration value="M" />
                      <xs:enumeration value="L" />
                      <xs:enumeration value="XL" />
                   </xs:restriction>
                </xs:simpleType>
                   
                <xs:simpleType name="clothesColorType">
                   <xs:restriction base="xs:string">
                      <xs:enumeration value="Black" />
                      <xs:enumeration value="White" />
                      <xs:enumeration value="Green" />
                      <xs:enumeration value="Blue" />
                   </xs:restriction>
                </xs:simpleType>
            </xs:schema>

Generated Result:

namespace Example;

use Doctrine\Common\Annotations\Annotation\Enum;
use Doctrine\Common\Annotations\Annotation\Required;

/**
 * Class representing Tshirt
 */
class Tshirt
{

    /**
     * @Enum({"Black","White","Green","Blue"})
     *
     * @property string $color
     */
    private $color = null;

    /**
     * @Required
     * @Enum({"S","M","L","XL"})
     *
     * @property string $size
     */
    private $size = null;

    /**
     * Gets as color
     *
     * @return string
     */
    public function getColor()
    {
        return $this->color;
    }

    /**
     * Sets a new color
     *
     * @param string $color
     * @return self
     */
    public function setColor($color)
    {
        $this->color = $color;
        return $this;
    }

    /**
     * Gets as size
     *
     * @return string
     */
    public function getSize()
    {
        return $this->size;
    }

    /**
     * Sets a new size
     *
     * @param string $size
     * @return self
     */
    public function setSize($size)
    {
        $this->size = $size;
        return $this;
    }
}

…d Enum

- Adding new fields into PHPProperty class (required and enum)
- Based on parsing adding require or enum data into generated class
- Add unit test
@goetas
Copy link
Member

goetas commented Oct 28, 2018

Thanks for your PR. Unfortunately I can not accept it as it is.

This project aims to generate always plain PHP objects.
Eventual metadata for serialization, validation, persistence should be in separate files and the generation for each of them should be an opt-in process.
That is the reason why this project generates separate YAML files for serialization and this tries to generate YAML metadata for validation.

Will be happy to accept the PR if it generates separate doctrine metadata in YAML or XML format.

@goetas goetas closed this Oct 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants