WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
426 stars 73 forks source link

Multiple pattern is not validated properly. #215

Closed PitBeast closed 3 years ago

PitBeast commented 4 years ago

In WDSL included XSD i have such definition:

<xs:element name="extPaymentType" minOccurs="0">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:pattern value=""/>
            <xs:pattern value="CASH"/>
            <xs:pattern value="DEBIT"/>
            <xs:pattern value="CC"/>
            <xs:pattern value="FULL_CREDIT"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

PHP code is:

public function setExtPaymentType($extPaymentType = null)
{
    // validation for constraint: string
    if (!is_null($extPaymentType) && !is_string($extPaymentType)) {
        throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($extPaymentType, true), gettype($extPaymentType)), __LINE__);
    }
    // validation for constraint: pattern(FULL_CREDIT)
    if (!is_null($extPaymentType) && !preg_match('/FULL_CREDIT/', $extPaymentType)) {
        throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a literal that is among the set of character sequences denoted by the regular expression FULL_CREDIT', var_export($extPaymentType, true)), __LINE__);
    }
    $this->extPaymentType = $extPaymentType;
    return $this;
}

Only last pattern is checked instead any one from restriction.

mikaelcom commented 4 years ago

Can you try using the feature/issue-215 branch code?

Or using the phar from either http://phar.wsdltophp.com/wsdltophp-feature-issue-215-php7.phar or http://phar.wsdltophp.com/wsdltophp-feature-issue-215-php5.phar?

Let me know how it goes :)

mikaelcom commented 3 years ago

Fixed in 3.3.0 and 2.12.0