Skip to content

Commit

Permalink
On 11th day of Cristmas my true love gave to me RFC 5733 compatibility (
Browse files Browse the repository at this point in the history
#62)

Another present for v1.0.0 - a set of RFC5733 compatibility enhancements:

 - contact voice & fax extension for update & create
 - contact status update
  • Loading branch information
johnny-bit authored and lifeofguenter committed Jan 4, 2019
1 parent cc6969d commit 3d9aa5e
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/create_contact.php
Expand Up @@ -22,7 +22,7 @@
$frame->setPostalCode('8001');
$frame->setCountryCode('ZA');
$frame->setVoice('+27.844784784');
$frame->setFax('+1.844784784');
$frame->setFax('+1.844784784', '123');
$frame->setEmail('github@afri.cc');
$auth = $frame->setAuthInfo();
$frame->addDisclose('voice');
Expand Down
2 changes: 1 addition & 1 deletion examples/create_contact_disclose.php
Expand Up @@ -21,7 +21,7 @@
$frame->setProvince('WC');
$frame->setPostalCode('8001');
$frame->setCountryCode('ZA');
$frame->setVoice('+27.844784784');
$frame->setVoice('+27.844784784', '123');
$frame->setFax('+1.844784784');
$frame->setEmail('github@afri.cc');
$auth = $frame->setAuthInfo();
Expand Down
3 changes: 3 additions & 0 deletions examples/update_contact.php
Expand Up @@ -12,11 +12,14 @@

$frame = new UpdateContact();
$frame->setId('C0054');
$frame->changeVoice('+12.345678', '123');
$frame->addCity('Voerde');
$frame->addAddStreet('Long St. 14');
$frame->addAddStreet('CBD');
$frame->changeAddStreet('Long St. 15');
$frame->changeCity('Cape Town');
$frame->removeAddStreet('Long St. 16');
$frame->removeCity('Durban');
$frame->addStatus('clientUpdateProhibited');
$frame->removeStatus('clientDeleteProhibited');
echo $frame;
45 changes: 35 additions & 10 deletions src/AfriCC/EPP/ContactTrait.php
Expand Up @@ -38,27 +38,44 @@ trait ContactTrait
*/
protected $skip_loc = false;

/**
* @param string $path
* @param mixed $value
*
* @return \DOMElement
*/
abstract public function set($path = null, $value = null);

public function forceAscii()
/**
* Whether to force ASCI on loc contacts
*
* @param bool $value
*
* @see \AfriCC\EPP\ContactTrait::force_ascii
*/
public function forceAscii($value = true)
{
$this->force_ascii = true;
$this->force_ascii = $value;
}

/**
* Skip the generation of type=int.
*
* @param bool $value
*/
public function skipInt()
public function skipInt($value = true)
{
$this->skip_int = true;
$this->skip_int = $value;
}

/**
* Skip the generation of type=loc.
*
* @param bool $value
*/
public function skipLoc()
public function skipLoc($value = true)
{
$this->skip_loc = true;
$this->skip_loc = $value;
}

public function appendId($path, $id)
Expand Down Expand Up @@ -147,14 +164,22 @@ public function appendCountryCode($path, $cc)
}
}

public function appendVoice($path, $voice)
public function appendVoice($path, $voice, $extension = null)
{
$this->set($path, $voice);
$node = $this->set($path, $voice);

if (!is_null($extension)) {
$node->setAttribute('x', $extension);
}
}

public function appendFax($path, $fax)
public function appendFax($path, $fax, $extension = null)
{
$this->set($path, $fax);
$node = $this->set($path, $fax);

if (!is_null($extension)) {
$node->setAttribute('x', $extension);
}
}

public function appendEmail($path, $email)
Expand Down
8 changes: 4 additions & 4 deletions src/AfriCC/EPP/Frame/Command/Create/Contact.php
Expand Up @@ -61,14 +61,14 @@ public function setCountryCode($cc)
$this->appendCountryCode('contact:postalInfo[@type=\'%s\']/contact:addr/contact:cc', $cc);
}

public function setVoice($voice)
public function setVoice($voice, $extension = null)
{
$this->appendVoice('contact:voice', $voice);
$this->appendVoice('contact:voice', $voice, $extension);
}

public function setFax($fax)
public function setFax($fax, $extension = null)
{
$this->appendFax('contact:fax', $fax);
$this->appendFax('contact:fax', $fax, $extension);
}

public function setEmail($email)
Expand Down
5 changes: 5 additions & 0 deletions src/AfriCC/EPP/Frame/Command/Info/Contact.php
Expand Up @@ -23,6 +23,11 @@ public function setId($id)
$this->set('contact:id', $id);
}

/**
* Set contact authinfo
*
* @param string $pw authinfo
*/
public function setAuthInfo($pw)
{
$this->set('contact:authInfo/contact:pw', $pw);
Expand Down
13 changes: 9 additions & 4 deletions src/AfriCC/EPP/Frame/Command/Update/Contact.php
Expand Up @@ -61,14 +61,14 @@ private function setCountryCode($mode, $cc)
$this->appendCountryCode(sprintf('contact:%s/contact:postalInfo[@type=\'%%s\']/contact:addr/contact:cc', $mode), $cc);
}

private function setVoice($mode, $voice)
private function setVoice($mode, $voice, $extension = null)
{
$this->appendVoice(sprintf('contact:%s/contact:voice', $mode), $voice);
$this->appendVoice(sprintf('contact:%s/contact:voice', $mode), $voice, $extension);
}

private function setFax($mode, $fax)
private function setFax($mode, $fax, $extension = null)
{
$this->appendFax(sprintf('contact:%s/contact:fax', $mode), $fax);
$this->appendFax(sprintf('contact:%s/contact:fax', $mode), $fax, $extension);
}

private function setEmail($mode, $email)
Expand All @@ -86,6 +86,11 @@ private function addDisclose($mode, $value, $flag = 0)
$this->appendDisclose(sprintf('contact:%s/contact:disclose[@flag=\'%d\']/contact:%s', $mode, $flag, $value));
}

private function setStatus($mode, $status)
{
$this->set(sprintf('contact:%s/contact:status[@s=\'%s\']', $mode, $status));
}

public function __call($name, $arguments)
{
if (strpos($name, 'add') === 0) {
Expand Down
8 changes: 4 additions & 4 deletions tests/EPP/Frame/Command/Create/ContactCreateTest.php
Expand Up @@ -21,7 +21,7 @@ public function testContactCreateFrame()
$frame->setPostalCode('8001');
$frame->setCountryCode('ZA');
$frame->setVoice('+27.844784784');
$frame->setFax('+1.844784784');
$frame->setFax('+1.844784784', '123');
$frame->setEmail('github@afri.cc');
$auth = $frame->setAuthInfo();
$frame->addDisclose('voice');
Expand Down Expand Up @@ -59,7 +59,7 @@ public function testContactCreateFrame()
</contact:addr>
</contact:postalInfo>
<contact:voice>+27.844784784</contact:voice>
<contact:fax>+1.844784784</contact:fax>
<contact:fax x="123">+1.844784784</contact:fax>
<contact:email>github@afri.cc</contact:email>
<contact:authInfo>
<contact:pw>' . $auth . '</contact:pw>
Expand Down Expand Up @@ -91,7 +91,7 @@ public function testContactCreateSkipIntFrame()
$frame->setProvince('WC');
$frame->setPostalCode('8001');
$frame->setCountryCode('ZA');
$frame->setVoice('+27.844784784');
$frame->setVoice('+27.844784784', '123');
$frame->setFax('+1.844784784');
$frame->setEmail('github@afri.cc');
$auth = $frame->setAuthInfo();
Expand All @@ -117,7 +117,7 @@ public function testContactCreateSkipIntFrame()
<contact:cc>ZA</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice>+27.844784784</contact:voice>
<contact:voice x="123">+27.844784784</contact:voice>
<contact:fax>+1.844784784</contact:fax>
<contact:email>github@afri.cc</contact:email>
<contact:authInfo>
Expand Down
33 changes: 33 additions & 0 deletions tests/EPP/Frame/Command/Update/ContactUpdateTest.php
Expand Up @@ -16,6 +16,8 @@ public function testUpdateContactFrame()
$frame->addAddStreet('CBD');
$frame->changeAddStreet('Long St. 15');
$frame->changeCity('Cape Town');
$frame->changeVoice('+12.345678', '123');
$frame->changeFax('+12.345678', '910');
$frame->removeAddStreet('Long St. 16');
$frame->removeCity('Durban');

Expand Down Expand Up @@ -55,6 +57,8 @@ public function testUpdateContactFrame()
<contact:city>Cape Town</contact:city>
</contact:addr>
</contact:postalInfo>
<contact:voice x="123">+12.345678</contact:voice>
<contact:fax x="910">+12.345678</contact:fax>
</contact:chg>
<contact:rem>
<contact:postalInfo type="loc">
Expand Down Expand Up @@ -156,4 +160,33 @@ public function testUpdateContactDiscloseFrame()
(string) $frame
);
}

public function testUpdateContactStatusFrame()
{
$frame = new Contact();
$frame->setId('C0054');
$frame->addStatus('clientUpdateProhibited');
$frame->removeStatus('clientDeleteProhibited');

$this->assertXmlStringEqualsXmlString(
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<contact:update xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>C0054</contact:id>
<contact:add>
<contact:status s="clientUpdateProhibited"/>
</contact:add>
<contact:rem>
<contact:status s="clientDeleteProhibited"/>
</contact:rem>
</contact:update>
</update>
</command>
</epp>
',
(string) $frame
);
}
}

0 comments on commit 3d9aa5e

Please sign in to comment.