1616trait ContactTrait
1717{
1818 /**
19- * this was once needed as the conversion done by COZA was faulty
19+ * This was once needed as the conversion done by COZA was faulty
2020 * 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)
21+ * set true to force ascii usage on type=loc (which should allow UTF8).
2222 *
2323 * @var bool
2424 */
2525 protected $ force_ascii = false ;
2626
2727 /**
28- * set true to skip the generation of type=int (like .MX)
28+ * Set true to skip the generation of type=int.
2929 *
3030 * @var bool
3131 */
3232 protected $ skip_int = false ;
3333
34+ /**
35+ * Set true to skip the generation of type=loc.
36+ *
37+ * @var bool
38+ */
39+ protected $ skip_loc = false ;
40+
3441 abstract public function set ($ path = null , $ value = null );
3542
3643 public function forceAscii ()
3744 {
3845 $ this ->force_ascii = true ;
3946 }
4047
48+ /**
49+ * Skip the generation of type=int.
50+ */
4151 public function skipInt ()
4252 {
4353 $ this ->skip_int = true ;
4454 }
4555
56+ /**
57+ * Skip the generation of type=loc.
58+ */
59+ public function skipLoc ()
60+ {
61+ $ this ->skip_loc = true ;
62+ }
63+
4664 public function appendId ($ path , $ id )
4765 {
4866 $ this ->set ($ path , $ id );
4967 }
5068
5169 public function appendName ($ path , $ name )
5270 {
53- if ($ this ->force_ascii ) {
54- $ this ->set (sprintf ($ path , 'loc ' ), Translit::transliterate ($ name ));
55- } else {
56- $ this ->set (sprintf ($ path , 'loc ' ), $ name );
71+ if (!$ this ->skip_loc ) {
72+ $ this ->set (sprintf ($ path , 'loc ' ), $ this ->force_ascii ? Translit::transliterate ($ name ) : $ name );
5773 }
5874
5975 if (!$ this ->skip_int ) {
@@ -63,10 +79,8 @@ public function appendName($path, $name)
6379
6480 public function appendOrganization ($ path , $ org )
6581 {
66- if ($ this ->force_ascii ) {
67- $ this ->set (sprintf ($ path , 'loc ' ), Translit::transliterate ($ org ));
68- } else {
69- $ this ->set (sprintf ($ path , 'loc ' ), $ org );
82+ if (!$ this ->skip_loc ) {
83+ $ this ->set (sprintf ($ path , 'loc ' ), $ this ->force_ascii ? Translit::transliterate ($ org ) : $ org );
7084 }
7185
7286 if (!$ this ->skip_int ) {
@@ -76,10 +90,8 @@ public function appendOrganization($path, $org)
7690
7791 public function appendStreet ($ path , $ street )
7892 {
79- if ($ this ->force_ascii ) {
80- $ this ->set (sprintf ($ path , 'loc ' ), Translit::transliterate ($ street ));
81- } else {
82- $ this ->set (sprintf ($ path , 'loc ' ), $ street );
93+ if (!$ this ->skip_loc ) {
94+ $ this ->set (sprintf ($ path , 'loc ' ), $ this ->force_ascii ? Translit::transliterate ($ street ) : $ street );
8395 }
8496
8597 if (!$ this ->skip_int ) {
@@ -89,10 +101,8 @@ public function appendStreet($path, $street)
89101
90102 public function appendCity ($ path , $ city )
91103 {
92- if ($ this ->force_ascii ) {
93- $ this ->set (sprintf ($ path , 'loc ' ), Translit::transliterate ($ city ));
94- } else {
95- $ this ->set (sprintf ($ path , 'loc ' ), $ city );
104+ if (!$ this ->skip_loc ) {
105+ $ this ->set (sprintf ($ path , 'loc ' ), $ this ->force_ascii ? Translit::transliterate ($ city ) : $ city );
96106 }
97107
98108 if (!$ this ->skip_int ) {
@@ -102,10 +112,8 @@ public function appendCity($path, $city)
102112
103113 public function appendProvince ($ path , $ sp )
104114 {
105- if ($ this ->force_ascii ) {
106- $ this ->set (sprintf ($ path , 'loc ' ), Translit::transliterate ($ sp ));
107- } else {
108- $ this ->set (sprintf ($ path , 'loc ' ), $ sp );
115+ if (!$ this ->skip_loc ) {
116+ $ this ->set (sprintf ($ path , 'loc ' ), $ this ->force_ascii ? Translit::transliterate ($ sp ) : $ sp );
109117 }
110118
111119 if (!$ this ->skip_int ) {
@@ -115,10 +123,8 @@ public function appendProvince($path, $sp)
115123
116124 public function appendPostalCode ($ path , $ pc )
117125 {
118- if ($ this ->force_ascii ) {
119- $ this ->set (sprintf ($ path , 'loc ' ), Translit::transliterate ($ pc ));
120- } else {
121- $ this ->set (sprintf ($ path , 'loc ' ), $ pc );
126+ if (!$ this ->skip_loc ) {
127+ $ this ->set (sprintf ($ path , 'loc ' ), $ this ->force_ascii ? Translit::transliterate ($ pc ) : $ pc );
122128 }
123129
124130 if (!$ this ->skip_int ) {
@@ -132,10 +138,8 @@ public function appendCountryCode($path, $cc)
132138 throw new Exception (sprintf ('the country-code: \'%s \' is unknown ' , $ cc ));
133139 }
134140
135- if ($ this ->force_ascii ) {
136- $ this ->set (sprintf ($ path , 'loc ' ), Translit::transliterate ($ cc ));
137- } else {
138- $ this ->set (sprintf ($ path , 'loc ' ), $ cc );
141+ if (!$ this ->skip_loc ) {
142+ $ this ->set (sprintf ($ path , 'loc ' ), $ this ->force_ascii ? Translit::transliterate ($ cc ) : $ cc );
139143 }
140144
141145 if (!$ this ->skip_int ) {
0 commit comments