PureMVC Architects Lounge

PureMVC Manifold => Standard Version => Topic started by: toby869 on August 29, 2011, 11:22:47



Title: writing to xml config files in a proxy
Post by: toby869 on August 29, 2011, 11:22:47
I have several proxies that interact with their own corresponding xml file.  The xml is then used as the proxy data to manipulate.  I am stumped as to how to change the xml data....or better yet, I am stumped because "getData()" does not return a reference (like AS3 does).  It seems in my setter functions, I would have to pull the entire contents of the xml in to a variable, do the necessary changes, then "setData()" with the updated xml data.  OR, I override the getData() to return a reference.  OR, I use a delegate to do the xml manipulation and use the delegate as the proxy data.  No matter which way I try to implement it, I get the feeling I'm doing it wrong.  Any advice or suggestions?

Thanks


Title: Re: writing to xml config files in a proxy
Post by: puremvc on August 29, 2011, 12:06:17
How about having the Proxy pull the XML into a variable, send it off in a notification and have a Command parse it and then do a setData on the Proxy. When that setData happens send off the note that says it's available.

-=Cliff>


Title: Re: writing to xml config files in a proxy
Post by: SasaT on August 30, 2011, 06:51:39
I'm confused. You are setting XML, type regular string, as Proxy data? Why not set DOMDocument instance or SimpleXMLElement instance as Proxy data?


Title: Re: writing to xml config files in a proxy
Post by: puremvc on August 30, 2011, 11:36:48
Caveat: I don't know anything about PHP's data types. I assumed it needed to be parsed.

-=Cliff>


Title: Re: writing to xml config files in a proxy
Post by: toby869 on September 08, 2011, 10:36:23
I'm confused. You are setting XML, type regular string, as Proxy data? Why not set DOMDocument instance or SimpleXMLElement instance as Proxy data?

No, I am wanting to use the DOMDocument or SimpleXMLElement instance as the proxy data.  My question was more related to how to implement either of them.  For example, if I have this...

:
<?php
class FooBarProxy extends Proxy implements IProxy
{
    public function 
loadXML($filename)
    {
        
$xml simplexml_load_file($filename);
        
$this->setData($xml);
    }

    public function 
getNodeValue($nodeName)
    {
        return 
$this->getData()->$nodeName;
    }
    
    public function 
setNodeValue($nodeName$value)
    {
        
$xml $this->getData();
        
$xml->$nodeName $value;

        
$this->setData($xml);
    }
}
Whenever I call setNodeValue, I am basically creating a second copy of the xml data in order to update with the new value.  In AS3, getData returns a reference to the actual data so in terms of PHP it would something like this...

:
public function setNodeValue($nodeName, $value)
    {
        $this->getData()->$nodeName = $value;
    }


My overall question is..would my original setNodeValue function from the first code snippet be considered "correct"?  Ie.  make a local copy of the xml instance, manipulate it, then setData. 
To me, making that second local copy just seems inefficient.  I would think it would be better to use the proxy to somehow manipulate the data directly...not make copies, manipulate, then setData.


Title: Re: writing to xml config files in a proxy
Post by: puremvc on September 08, 2011, 12:04:51
No logical reason to copy the data in the proxy before modification. Your shortcut to setting the node on the data itself seems correct.

-=Cliff>