Best practices for class-mapping with SoapClient

Posted by Foofy on Stack Overflow See other posts from Stack Overflow or by Foofy
Published on 2010-06-16T01:06:48Z Indexed on 2010/06/16 1:12 UTC
Read the original article Hit count: 515

Using SoapClient's class mapping feature and it's pretty sweet. Unfortunately the SOAP service we're using has a bunch of read-only properties on some of the objects and will throw faults if the properties are passed back as anything but null.

Need to filter out the properties before they're used in the SOAP call and am looking for advice on the best way to do it.

So far the options are:

  1. Stick to a convention where I use getter and setter functions to manipulate the properties, and use property overloading to filter method access since only SoapClient would be doing that.

    E.g. developers would access properties like this:

        $obj->getAccountNumber()  
    

    SoapClient would access properties like this:

        $obj->accountNumber   
    

    I don't like this because the properties are still exposed and things could go wrong if developers don't stick to convention.

  2. Have a wrapper for SoapClient that sets a public property the mapped objects can check to see if the property is being accessed by SoapClient. I already have a wrapper that assigns a reference to itself to all the mapped objects.

    class SoapClientWrapper {
        public function __soapCall($method, $args) {
            $this->setSoapMode(true);
            $this->_soapClient->__soapCall($method, $args); 
            $this->setSoapMode(false); 
        }
    }
    
    
    class Invoice {
            function __get($val) {
                    if($this->_soapClient->getSoapMode()) {
                            return null; 
                    } else {
                            return $this->$val;
                    }
            }
    }
    

    This works but it doesn't feel right and seems a bit clunky.

  3. Do the mapping manually, and don't use SoapClient's mapping features. I'd just have a function on all the mapped objects that returns the safe-to-send properties. Also, nobody would have access to properties they shouldn't since I could enforce getters and setters. A lot more work, though.

© Stack Overflow or respective owner

Related posts about php

Related posts about best-practices