dmitrirussu / php-sepa-xml-generator

SEPA SDD XML Generator recommended to see. PHP SEPA XML Generator, (Single Euro Payments Area ISO20022 SDD V1_0 20122009) (SEPA)(PHP5)
https://github.com/dmitrirussu/PHP-SEPA-XML-GENERATOR
MIT License
53 stars 36 forks source link

Message->createMessage(): switch always evaluates default #24

Closed hdcos closed 8 years ago

hdcos commented 8 years ago

when using XmlGeneratorFactory in your example we can not create a transfert credit since $this->getDocumentPainMode() returns null also be aware that getDocumentPainMode will never match the cases since it is set in setDocumentPainMode as a string representing the xml root element:

public function setDocumentPainMode($documentPainMode) {
    $this->documentPainMode = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Document
xmlns=\"urn:iso:std:iso:20022:tech:xsd:$documentPainMode\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"urn:iso:std:iso:20022:tech:xsd:$documentPainMode     $documentPainMode.xsd\"></Document>"; return $this; }

public function getDocumentPainMode() {

    return $this->documentPainMode;
}

 switch($this->getDocumentPainMode()) { // impossible to match the case
        case self::PAIN_001_001_02: {
            $documentMessage = "<CstmrCdtTrfInitn></CstmrCdtTrfInitn>";
            break;
        }
        default: {
            $documentMessage = "<CstmrDrctDbtInitn></CstmrDrctDbtInitn>";
            break;
        }
    }

I quick fixed this by adding another enum

protected static $documentPainModeEnum;
public function setDocumentPainMode($documentPainMode) {
    self::$documentPainModeEnum = $documentPainMode;
    $this->documentPainMode = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>

then I switch like that:

 switch(self::$documentPainModeEnum) {
dmitrirussu commented 8 years ago

Hi, I have fixed this bug. Thanks