metaregistrar / php-epp-client

Object-oriented PHP EPP Client
https://www.metaregistrar.com/docs/
MIT License
210 stars 154 forks source link

Is there a way to just send an XML string as request & receive the result? #212

Closed MrBMT closed 4 years ago

MrBMT commented 4 years ago

Hey there,

I'm currently working on throwing something together to use with Nominet's EPP system.

I've got most things working so far, but Nominet use a non-standard "unrenew" command that I want to be able to use.

All I really want to do is be able to pass XML in a string such as:

$unrenew = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
    epp-1.0.xsd">
    <command>
        <update>
            <u:unrenew
            xmlns:u="http://www.nominet.org.uk/epp/xml/std-unrenew-1.0"
            xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/std-unrenew-1.0
            std-unrenew-1.0.xsd">
                <u:domainName>'.$domainname.'</u:domainName>
            </u:unrenew>
        </update>
        <clTRID>ABC-12345</clTRID>
    </command>
</epp>';

Is this possible?

I've tried passing it thorough $response = $conn->request($unrenew); as you commented should work here which results in a Laravel ErrorException saying get_class() expects parameter 1 to be object, string given

Then tried $response = $conn->writeandread($unrenew); which results in Call to a member function getSessionId() on string

Then:

$unrenewReqObj = new \DOMDocument();
$unrenewReqObj->loadXML($unrenew);
$response = $conn->request($unrenewReqObj);

Then passing it through request, which results in Call to undefined method DOMDocument::getSessionId().

Then extending Metaregistrar\EPP\eppRequest, which then results in ERROR: No valid response class found for request class App\eppUnrenewRequest

etc. etc.

I'm sure there's probably something simple I'm overlooking here, so any help would be appreciated!

metaregistrar commented 4 years ago

I really have not tried sending a string through the readandwrite() function, but i see that the routine expects $content to be a domDocument object, so that indeed would not work.

What you might try is this snippet from the readandwrite() function:

if ($this->write($contentstring)) {
            $readcounter = 0;
            $xml = $this->read();
            // When no data is present on the stream, retry reading several times
            while ((strlen($xml)==0) && ($readcounter < $this->retry)) {
                $xml = $this->read();
                $readcounter++;
            }
}

That will send your information through the connection and give you the response back in the $xml variable. But the function writeandread() performs a lot of other stuff, and that is not done then

Anyway it is always recommended to use the proper epp extensions and create Procotols/EPP/eppExtensions/std-unrenew-1.0
If you go that route, other people can also make use of the functions you have provided.
MrBMT commented 4 years ago

Thanks for reply, I gave it a try and then got:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/epp-1.0 epp-1.0.xsd">
  <response>
    <result code="2001">
      <msg>Command syntax error</msg>
      <extValue>
        <value>
          <clTRID>ABC-12345</clTRID>
        </value>
        <reason>V274 Schema std-unrenew- not specified at login.</reason>
      </extValue>
    </result>
    <trID>
      <clTRID>ABC-12345</clTRID>
      <svTRID>xxxxxxx</svTRID>
    </trID>
  </response>
</epp>

I've not ever used any DOMDocument functionality etc. before which is why I was trying to do it this way - as creating an extension without guidance on how to do so is probably beyond me right now.

However I'm guessing from the above XML response I'd need to make an extension so it could be passed at login anyway?

metaregistrar commented 4 years ago

Ok, you are almost there

After making the connection, but before logging in, specify this:

$conn::addExtension('std-unrenew-1.0', 'http://www.nominet.org.uk/epp/xml/std-unrenew-1.0');

Please check the nominet EPP manuals for the correct syntax of this login addition

MrBMT commented 4 years ago

Thanks for that, it complained Non-static method Metaregistrar\EPP\eppConnection::addExtension() should not be called statically when I tried using it that way, however creating Registries/nominetEppConnection/eppConnection.php with the following contents and then changing the interface to nominetEppConnection within settings.ini resolved it:

<?php
namespace Metaregistrar\EPP;

class nominetEppConnection extends eppConnection {

    public function __construct($logging = false, $settingsfile = null) {
        parent::__construct($logging, $settingsfile);

        parent::addExtension('std-unrenew-1.0', 'http://www.nominet.org.uk/epp/xml/std-unrenew-1.0');
    }
}