Skip to content

Commit 0bb6b41

Browse files
author
Gunter Grodotzki
committed
add possibility to skip the generation of type=int in contacts (fixes
#4)
1 parent 3cedc7f commit 0bb6b41

File tree

5 files changed

+214
-8
lines changed

5 files changed

+214
-8
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: php
22

33
php:
4+
- 5.6
45
- 5.5
56
- 5.4
67
- hhvm

examples/create_contact_skipint.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
// debug
4+
error_reporting(E_ALL);
5+
ini_set('display_errors', true);
6+
7+
require '../src/AfriCC/autoload.php';
8+
9+
use AfriCC\EPP\Frame\Command\Create\Contact as CreateContact;
10+
11+
$frame = new CreateContact;
12+
$frame->skipInt();
13+
$frame->setId('CONTACT1');
14+
$frame->setName('Günter Grodotzki');
15+
$frame->setName('Peter Fütterer');
16+
$frame->setOrganization('weheartwebsites UG');
17+
$frame->addStreet('Rönskenstraße 23');
18+
$frame->addStreet('Around the Corner');
19+
$frame->setCity('Cape Town');
20+
$frame->setProvince('WC');
21+
$frame->setPostalCode('8001');
22+
$frame->setCountryCode('ZA');
23+
$frame->setVoice('+27.844784784');
24+
$frame->setFax('+1.844784784');
25+
$frame->setEmail('[email protected]');
26+
$auth = $frame->setAuthInfo();
27+
$frame->addDisclose('voice');
28+
$frame->addDisclose('email');
29+
echo $frame;
30+
var_dump($auth);

src/AfriCC/EPP/ContactTrait.php

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
11
<?php
22

3+
/**
4+
* This file is part of the php-epp2 library.
5+
*
6+
* (c) Gunter Grodotzki <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE file
9+
* that was distributed with this source code.
10+
*/
11+
312
namespace AfriCC\EPP;
413

514
use Exception;
615

716
trait ContactTrait
817
{
18+
/**
19+
* this was once needed as the conversion done by COZA was faulty
20+
* the bug has since been fixed but this remains to allow testing
21+
* set true to force ascii usage on type=loc (which should allow UTF8)
22+
*
23+
* @var bool
24+
*/
925
protected $force_ascii = false;
1026

27+
/**
28+
* set true to skip the generation of type=int (like .MX)
29+
*
30+
* @var bool
31+
*/
32+
protected $skip_int = false;
33+
1134
public function forceAscii()
1235
{
1336
$this->force_ascii = true;
1437
}
1538

39+
public function skipInt()
40+
{
41+
$this->skip_int = true;
42+
}
43+
1644
public function appendId($path, $id)
1745
{
1846
$this->set($path, $id);
@@ -26,7 +54,9 @@ public function appendName($path, $name)
2654
$this->set(sprintf($path, 'loc'), $name);
2755
}
2856

29-
$this->set(sprintf($path, 'int'), Translit::transliterate($name));
57+
if (!$this->skip_int) {
58+
$this->set(sprintf($path, 'int'), Translit::transliterate($name));
59+
}
3060
}
3161

3262
public function appendOrganization($path, $org)
@@ -37,7 +67,9 @@ public function appendOrganization($path, $org)
3767
$this->set(sprintf($path, 'loc'), $org);
3868
}
3969

40-
$this->set(sprintf($path, 'int'), Translit::transliterate($org));
70+
if (!$this->skip_int) {
71+
$this->set(sprintf($path, 'int'), Translit::transliterate($org));
72+
}
4173
}
4274

4375
public function appendStreet($path, $street)
@@ -48,7 +80,9 @@ public function appendStreet($path, $street)
4880
$this->set(sprintf($path, 'loc'), $street);
4981
}
5082

51-
$this->set(sprintf($path, 'int'), Translit::transliterate($street));
83+
if (!$this->skip_int) {
84+
$this->set(sprintf($path, 'int'), Translit::transliterate($street));
85+
}
5286
}
5387

5488
public function appendCity($path, $city)
@@ -59,7 +93,9 @@ public function appendCity($path, $city)
5993
$this->set(sprintf($path, 'loc'), $city);
6094
}
6195

62-
$this->set(sprintf($path, 'int'), Translit::transliterate($city));
96+
if (!$this->skip_int) {
97+
$this->set(sprintf($path, 'int'), Translit::transliterate($city));
98+
}
6399
}
64100

65101
public function appendProvince($path, $sp)
@@ -70,7 +106,9 @@ public function appendProvince($path, $sp)
70106
$this->set(sprintf($path, 'loc'), $sp);
71107
}
72108

73-
$this->set(sprintf($path, 'int'), Translit::transliterate($sp));
109+
if (!$this->skip_int) {
110+
$this->set(sprintf($path, 'int'), Translit::transliterate($sp));
111+
}
74112
}
75113

76114
public function appendPostalCode($path, $pc)
@@ -81,7 +119,9 @@ public function appendPostalCode($path, $pc)
81119
$this->set(sprintf($path, 'loc'), $pc);
82120
}
83121

84-
$this->set(sprintf($path, 'int'), Translit::transliterate($pc));
122+
if (!$this->skip_int) {
123+
$this->set(sprintf($path, 'int'), Translit::transliterate($pc));
124+
}
85125
}
86126

87127
public function appendCountryCode($path, $cc)
@@ -96,7 +136,9 @@ public function appendCountryCode($path, $cc)
96136
$this->set(sprintf($path, 'loc'), $cc);
97137
}
98138

99-
$this->set(sprintf($path, 'int'), Translit::transliterate($cc));
139+
if (!$this->skip_int) {
140+
$this->set(sprintf($path, 'int'), Translit::transliterate($cc));
141+
}
100142
}
101143

102144
public function appendVoice($path, $voice)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
namespace AfriCC\EPP\Frame\Command;
4+
5+
use AfriCC\EPP\Frame\Command\Create\Contact as CreateContact;
6+
7+
class ContactTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testContactCreate()
10+
{
11+
$frame = new CreateContact;
12+
$frame->setId('CONTACT1');
13+
$frame->setName('Günter Grodotzki');
14+
$frame->setName('Jun Grodotzki');
15+
$frame->setOrganization('weheartwebsites UG');
16+
$frame->addStreet('Rönskenstraße 23');
17+
$frame->addStreet('Around the Corner');
18+
$frame->setCity('Cape Town');
19+
$frame->setProvince('WC');
20+
$frame->setPostalCode('8001');
21+
$frame->setCountryCode('ZA');
22+
$frame->setVoice('+27.844784784');
23+
$frame->setFax('+1.844784784');
24+
$frame->setEmail('[email protected]');
25+
$auth = $frame->setAuthInfo();
26+
$frame->addDisclose('voice');
27+
$frame->addDisclose('email');
28+
29+
$this->assertXmlStringEqualsXmlString((string) $frame,
30+
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
31+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
32+
<command>
33+
<create>
34+
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
35+
<contact:id>CONTACT1</contact:id>
36+
<contact:postalInfo type="loc">
37+
<contact:name>Jun Grodotzki</contact:name>
38+
<contact:org>weheartwebsites UG</contact:org>
39+
<contact:addr>
40+
<contact:street>Rönskenstraße 23</contact:street>
41+
<contact:street>Around the Corner</contact:street>
42+
<contact:city>Cape Town</contact:city>
43+
<contact:sp>WC</contact:sp>
44+
<contact:pc>8001</contact:pc>
45+
<contact:cc>ZA</contact:cc>
46+
</contact:addr>
47+
</contact:postalInfo>
48+
<contact:postalInfo type="int">
49+
<contact:name>Jun Grodotzki</contact:name>
50+
<contact:org>weheartwebsites UG</contact:org>
51+
<contact:addr>
52+
<contact:street>Ronskenstrasse 23</contact:street>
53+
<contact:street>Around the Corner</contact:street>
54+
<contact:city>Cape Town</contact:city>
55+
<contact:sp>WC</contact:sp>
56+
<contact:pc>8001</contact:pc>
57+
<contact:cc>ZA</contact:cc>
58+
</contact:addr>
59+
</contact:postalInfo>
60+
<contact:voice>+27.844784784</contact:voice>
61+
<contact:fax>+1.844784784</contact:fax>
62+
<contact:email>[email protected]</contact:email>
63+
<contact:authInfo>
64+
<contact:pw>' . $auth . '</contact:pw>
65+
</contact:authInfo>
66+
<contact:disclose flag="0">
67+
<contact:voice/>
68+
<contact:email/>
69+
</contact:disclose>
70+
</contact:create>
71+
</create>
72+
</command>
73+
</epp>'
74+
);
75+
}
76+
77+
public function testContactCreateSkipInt()
78+
{
79+
$frame = new CreateContact;
80+
$frame->skipInt();
81+
$frame->setId('CONTACT1');
82+
$frame->setName('Günter Grodotzki');
83+
$frame->setName('Jun Grodotzki');
84+
$frame->setOrganization('weheartwebsites UG');
85+
$frame->addStreet('Rönskenstraße 23');
86+
$frame->addStreet('Around the Corner');
87+
$frame->setCity('Cape Town');
88+
$frame->setProvince('WC');
89+
$frame->setPostalCode('8001');
90+
$frame->setCountryCode('ZA');
91+
$frame->setVoice('+27.844784784');
92+
$frame->setFax('+1.844784784');
93+
$frame->setEmail('[email protected]');
94+
$auth = $frame->setAuthInfo();
95+
$frame->addDisclose('voice');
96+
$frame->addDisclose('email');
97+
98+
$this->assertXmlStringEqualsXmlString((string) $frame,
99+
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
100+
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
101+
<command>
102+
<create>
103+
<contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
104+
<contact:id>CONTACT1</contact:id>
105+
<contact:postalInfo type="loc">
106+
<contact:name>Jun Grodotzki</contact:name>
107+
<contact:org>weheartwebsites UG</contact:org>
108+
<contact:addr>
109+
<contact:street>Rönskenstraße 23</contact:street>
110+
<contact:street>Around the Corner</contact:street>
111+
<contact:city>Cape Town</contact:city>
112+
<contact:sp>WC</contact:sp>
113+
<contact:pc>8001</contact:pc>
114+
<contact:cc>ZA</contact:cc>
115+
</contact:addr>
116+
</contact:postalInfo>
117+
<contact:voice>+27.844784784</contact:voice>
118+
<contact:fax>+1.844784784</contact:fax>
119+
<contact:email>[email protected]</contact:email>
120+
<contact:authInfo>
121+
<contact:pw>' . $auth . '</contact:pw>
122+
</contact:authInfo>
123+
<contact:disclose flag="0">
124+
<contact:voice/>
125+
<contact:email/>
126+
</contact:disclose>
127+
</contact:create>
128+
</create>
129+
</command>
130+
</epp>'
131+
);
132+
}
133+
}

tests/AfriCC/EPP/Test/Frame/Command/LoginTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class LoginTest extends \PHPUnit_Framework_TestCase
88
{
9-
public function testLoginServices()
9+
public function testLoginServices()
1010
{
1111
$frame = new Login;
1212
$frame->setClientId('gunter');

0 commit comments

Comments
 (0)