Hello all,
I’m trying to understand a given class for interacting with a EPP server.
On that class we have two methods:
One:
function getFrame() {
if (@feof($this->socket)) return new PEAR_Error('connection closed by remote server');
$hdr = @fread($this->socket, 4);
if (empty($hdr) && feof($this->socket))
{
return new PEAR_Error('connection closed by remote server');
}
elseif (empty($hdr))
{
return new PEAR_Error('Error reading from server: '.$php_errormsg);
}
else
{
//este unpack parece estar relacionado com o pern, pois não devolve
//nenhum array associativo. Mas, apesar disto... temos de ver que está chamar por uma chave numérica.
$unpacked = unpack('N', $hdr);
$length = $unpacked[1];
if ($length < 5)
{
return new PEAR_Error(sprintf('Got a bad frame header length of %d bytes from server', $length));
}
else
{
return fread($this->socket, ($length - 4));
}
}
}
Two:
function sendFrame($xml) {
fwrite($this->socket, pack('N', (strlen($xml)+4)).$xml);
}
And then, we have a wrapper method:
function request($xml) {
$this->sendFrame($xml);
return $this->getFrame();
}
Assuming that a wrapper methods commonly, are used to add behavior before and after the default method executes.
I presume that this interacts with the sendFrame and getFrame somehow. But I’m not getting how?
Is this something we do when we instantiate?
But how?
When we call the request method, it will execute the sendFrame($xml) and return a Frame.
So, it is a wrapper because, by calling this $request we are executing both, SendFrame and then getFrame?
$this->sendFrame($xml);
return $this->getFrame();
Can anyone help me understand this if, possible by relating it with a EPP communication context?
Any lights into this, any thoughts could help me out somehow.
Additional request: we can use PHP exceptions and have one less dependency by removing the required perl. Can’t we?
Thanks a lot,
Márcio