Re: [PHP] Simple objective which always seems to make me think I'm doing it wrong.
On 23 May 2013 16:31, Stuart Dallas stu...@3ft9.com wrote: On 23 May 2013, at 15:54, Richard Quadling rquadl...@gmail.com wrote: I'm building an XML file. It is within an OOP structure and is pretty simple. The method is ... /** * Turn an error from the W2GlobalData service into normal document as this will make it easier to integrate downstream. * * @param \SimpleXMLElement $o_XML * @return \SimpleXMLElement * @todo Build document to be a correct request header with the embedded error message. */ public function normaliseError($o_XML) { $s_XML = END_XML ?xml version=1.0 encoding=UTF-8? doc serviceUK Verification (Edited)/service searchtext forename{$this-a_RequestData['forename']}/forename middlename{$this-a_RequestData['middlename']}/middlename surname{$this-a_RequestData['surname']}/surname address1{$this-a_RequestData['address1']}/address1 address2{$this-a_RequestData['address2']}/address2 postcode{$this-a_RequestData['postcode']}/postcode gender{$this-a_RequestData['gender']}/gender dob{$this-a_RequestData['dob']}/dob drivinglicence{$this-a_RequestData['drivinglicence']}/drivinglicence passport{$this-a_RequestData['passport']}/passport mpan{$this-a_RequestData['mpan']}/mpan /searchtext clientreference{$this-a_RequestData['clientreference']}/clientreference resultcount/ searchdate/ expiry/ timetaken/ reportemailsent/ error {$o_XML-error} /error /doc END_XML; return new SimpleXMLElement($s_XML); } Nothing particularly difficult to understand, but I just don't like having the XML embedded this way. Ideally, I want a scope aware include function, so I can say _something_ like ... $s_XML = require_once __CLASS__ . DIRECTORY_SEPARATOR . 'normalisedError.xml'; and have the include be aware of the local scope (so $o_XML and $this are all happy). I know I can write a template parser, but I'm just missing an obvious solution that isn't fat and doesn't require a massive learning for the other devs. Ideas? normalisedError.xml: ?php return END_XML the xml here END_XML; Then in your class your require_once line will work. However, use require instead of require_once otherwise if the function gets called twice it won't work the second time. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ Perfect!!! Thanks -- Richard Quadling Twitter : @RQuadling EE : http://e-e.com/M_248814.html Zend : http://bit.ly/9O8vFY
Re: [PHP] Simple objective which always seems to make me think I'm doing it wrong.
On Thu, May 23, 2013 at 4:54 PM, Richard Quadling rquadl...@gmail.comwrote: Hi. I'm building an XML file. It is within an OOP structure and is pretty simple. The method is ... snip Nothing particularly difficult to understand, but I just don't like having the XML embedded this way. Ideally, I want a scope aware include function, so I can say _something_ like ... $s_XML = require_once __CLASS__ . DIRECTORY_SEPARATOR . 'normalisedError.xml'; and have the include be aware of the local scope (so $o_XML and $this are all happy). I know I can write a template parser, but I'm just missing an obvious solution that isn't fat and doesn't require a massive learning for the other devs. Ideas? Thanks for reading. Richard. What is wrong with the require_once? I don't see why it would not work. - Matijn
Re: [PHP] Simple objective which always seems to make me think I'm doing it wrong.
On 23 May 2013, at 15:54, Richard Quadling rquadl...@gmail.com wrote: I'm building an XML file. It is within an OOP structure and is pretty simple. The method is ... /** * Turn an error from the W2GlobalData service into normal document as this will make it easier to integrate downstream. * * @param \SimpleXMLElement $o_XML * @return \SimpleXMLElement * @todo Build document to be a correct request header with the embedded error message. */ public function normaliseError($o_XML) { $s_XML = END_XML ?xml version=1.0 encoding=UTF-8? doc serviceUK Verification (Edited)/service searchtext forename{$this-a_RequestData['forename']}/forename middlename{$this-a_RequestData['middlename']}/middlename surname{$this-a_RequestData['surname']}/surname address1{$this-a_RequestData['address1']}/address1 address2{$this-a_RequestData['address2']}/address2 postcode{$this-a_RequestData['postcode']}/postcode gender{$this-a_RequestData['gender']}/gender dob{$this-a_RequestData['dob']}/dob drivinglicence{$this-a_RequestData['drivinglicence']}/drivinglicence passport{$this-a_RequestData['passport']}/passport mpan{$this-a_RequestData['mpan']}/mpan /searchtext clientreference{$this-a_RequestData['clientreference']}/clientreference resultcount/ searchdate/ expiry/ timetaken/ reportemailsent/ error {$o_XML-error} /error /doc END_XML; return new SimpleXMLElement($s_XML); } Nothing particularly difficult to understand, but I just don't like having the XML embedded this way. Ideally, I want a scope aware include function, so I can say _something_ like ... $s_XML = require_once __CLASS__ . DIRECTORY_SEPARATOR . 'normalisedError.xml'; and have the include be aware of the local scope (so $o_XML and $this are all happy). I know I can write a template parser, but I'm just missing an obvious solution that isn't fat and doesn't require a massive learning for the other devs. Ideas? normalisedError.xml: ?php return END_XML the xml here END_XML; Then in your class your require_once line will work. However, use require instead of require_once otherwise if the function gets called twice it won't work the second time. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php