Re: [PHP] Simple objective which always seems to make me think I'm doing it wrong.

[email protected] (Richard Quadling)
Newsgroups php.general
Message-ID <CAKUjMCXpm2+P_=QWSOW04eMGQ-mQ7-4zPrm3SM+7a3ue1SQP4A@mail.gmail.com>
On 23 May 2013 16:31, Stuart Dallas <[email protected]> wrote:

> On 23 May 2013, at 15:54, Richard Quadling <[email protected]> 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>
> >    <service>UK 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.