Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
June 27, 2017, 03:36:04 AM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Print
Author Topic: writing to xml config files in a proxy  (Read 4676 times)
toby869
Newbie
*
Posts: 8


View Profile
« on: August 29, 2011, 11:22:47 AM »

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
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #1 on: August 29, 2011, 12:06:17 PM »

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>
Logged
SasaT
Newbie
*
Posts: 7


View Profile
« Reply #2 on: August 30, 2011, 06:51:39 AM »

I'm confused. You are setting XML, type regular string, as Proxy data? Why not set DOMDocument instance or SimpleXMLElement instance as Proxy data?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #3 on: August 30, 2011, 11:36:48 AM »

Caveat: I don't know anything about PHP's data types. I assumed it needed to be parsed.

-=Cliff>
Logged
toby869
Newbie
*
Posts: 8


View Profile
« Reply #4 on: September 08, 2011, 10:36:23 AM »

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...

Code:
<?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...

Code:
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.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #5 on: September 08, 2011, 12:04:51 PM »

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>
Logged
Pages: [1]
Print
Jump to: