Skip to content

Commit a448374

Browse files
committed
Added domain classes for address ontology. EmailAddress and TelNumber use the same JSON standard for the polymorphic type.
1 parent 0c70820 commit a448374

17 files changed

+706
-11
lines changed

src/org/nameapi/client/services/ServiceFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
require_once(__DIR__.'/../../ontology/input/entities/contact/EmailAddressFactory.php');
2222
require_once(__DIR__.'/../../ontology/input/entities/contact/TelNumberFactory.php');
2323
require_once(__DIR__.'/../../ontology/input/entities/person/NaturalInputPersonBuilder.php');
24+
require_once(__DIR__.'/../../ontology/input/entities/address/StructuredAddressBuilder.php');
25+
require_once(__DIR__.'/../../ontology/input/entities/address/UseForAllAddressRelation.php');
2426

2527

2628

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\address;
4+
5+
6+
/**
7+
* Specifies for what purposes a certain InputAddress is, for example for AddressUsage CORRESPONDENCE.
8+
*/
9+
abstract class AddressRelation implements \JsonSerializable {
10+
11+
}
12+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\address;
4+
5+
6+
/**
7+
* Lists the possible purposes of an InputAddress.
8+
*
9+
* Possible values are: DOMICILE, CORRESPONDENCE, INVOICE, DELIVERY, OTHER
10+
*
11+
* @package org\nameapi\ontology\input\entities\address
12+
*/
13+
final class AddressUsage {
14+
15+
/**
16+
* @var string $value
17+
*/
18+
private $value = null;
19+
20+
public function __construct($value) {
21+
if ($value!='DOMICILE' && $value!='CORRESPONDENCE' && $value!='INVOICE' && $value!='DELIVERY' && $value!='OTHER') {
22+
throw new \Exception('Invalid value for AddressUsage: '.$value.'!');
23+
}
24+
$this->value = $value;
25+
}
26+
27+
28+
29+
public function __toString() {
30+
return $this->value;
31+
}
32+
33+
}
34+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\address;
4+
5+
6+
/**
7+
* Represents a physical address which can be an address to a house, a postbox, a "packet pickup station" etc.
8+
*
9+
* @see StructuredAddressBuilder
10+
*/
11+
abstract class InputAddress implements \JsonSerializable {
12+
13+
}
14+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\address;
4+
5+
6+
/**
7+
* Information about the locality, possibly including:
8+
* - locality
9+
* - postal code
10+
* - neighborhood
11+
* - region (state)
12+
* - country
13+
*
14+
*/
15+
abstract class PlaceInfo implements \JsonSerializable {
16+
17+
}
18+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\address;
4+
5+
6+
/**
7+
* Information about the house, possibly including:
8+
* - street name
9+
* - street number
10+
* - block, entrance, floor
11+
* - apartment/suite
12+
*
13+
*/
14+
abstract class StreetInfo implements \JsonSerializable {
15+
16+
}
17+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\address;
4+
5+
require_once(__DIR__.'/InputAddress.php');
6+
require_once(__DIR__.'/StructuredStreetInfoBuilder.php');
7+
require_once(__DIR__.'/StructuredPlaceInfoBuilder.php');
8+
9+
/**
10+
* An address where the individual parts (street name, postal code, ...) are structured into separate values.
11+
*
12+
* @see StructuredAddressBuilder
13+
*/
14+
class StructuredAddress extends InputAddress {
15+
16+
/**
17+
* @return StructuredAddressBuilder
18+
*/
19+
static function builder() {
20+
return new StructuredAddressBuilder();
21+
}
22+
23+
24+
/**
25+
* @var StreetInfo|null $streetInfo
26+
*/
27+
public $streetInfo;
28+
/**
29+
* @var string|null $pobox
30+
*/
31+
public $pobox;
32+
/**
33+
* @var PlaceInfo|null $placeInfo
34+
*/
35+
public $placeInfo;
36+
37+
/**
38+
* @param StreetInfo $streetInfo
39+
* @param string $pobox
40+
* @param PlaceInfo $placeInfo
41+
*/
42+
public function __construct($streetInfo, $pobox, $placeInfo) {
43+
$this->streetInfo = $streetInfo;
44+
$this->pobox = $pobox;
45+
$this->placeInfo = $placeInfo;
46+
}
47+
48+
public function jsonSerialize() {
49+
return array(
50+
'type' => "StructuredAddress",
51+
'streetInfo' => $this->streetInfo,
52+
'pobox' => $this->pobox,
53+
'placeInfo' => $this->placeInfo,
54+
);
55+
}
56+
57+
58+
}
59+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\address;
4+
5+
require_once(__DIR__.'/StructuredAddress.php');
6+
7+
/**
8+
* Builder for a StructuredAddress.
9+
*
10+
* <p>The setters don't do anything other than setting the value. They don't check if the value was
11+
* set already, they don't trim the values.</p>
12+
*/
13+
class StructuredAddressBuilder {
14+
15+
/**
16+
* @var StreetInfo|null $streetInfo
17+
*/
18+
private $streetInfo;
19+
/**
20+
* @var string|null $pobox
21+
*/
22+
private $pobox;
23+
/**
24+
* @var PlaceInfo|null $placeInfo
25+
*/
26+
private $placeInfo;
27+
28+
29+
function __construct() {
30+
}
31+
32+
33+
/**
34+
* @param StreetInfo|null $streetInfo
35+
* @return StructuredAddressBuilder
36+
*/
37+
public function streetInfo($streetInfo) {
38+
$this->streetInfo = $streetInfo;
39+
return $this;
40+
}
41+
42+
/**
43+
* @param string|null $pobox
44+
* @return StructuredAddressBuilder
45+
*/
46+
public function pobox($pobox) {
47+
$this->pobox = $pobox;
48+
return $this;
49+
}
50+
51+
/**
52+
* @param PlaceInfo|null $placeInfo
53+
* @return StructuredAddressBuilder
54+
*/
55+
public function placeInfo($placeInfo) {
56+
$this->placeInfo = $placeInfo;
57+
return $this;
58+
}
59+
60+
61+
/**
62+
* @return StructuredAddress
63+
*/
64+
public function build() {
65+
return new StructuredAddress(
66+
$this->streetInfo,
67+
$this->pobox,
68+
$this->placeInfo
69+
);
70+
}
71+
72+
}
73+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\address;
4+
5+
require_once(__DIR__.'/PlaceInfo.php');
6+
7+
/**
8+
* @see StructuredPlaceInfoBuilder
9+
*/
10+
class StructuredPlaceInfo extends PlaceInfo {
11+
12+
/**
13+
* @return StructuredPlaceInfoBuilder
14+
*/
15+
static function builder() {
16+
return new StructuredPlaceInfoBuilder();
17+
}
18+
19+
20+
/**
21+
* @var string|null $locality
22+
*/
23+
public $locality;
24+
/**
25+
* @var string|null $postalCode
26+
*/
27+
public $postalCode;
28+
/**
29+
* @var string|null $neighborhood
30+
*/
31+
public $neighborhood;
32+
/**
33+
* @var string|null $region
34+
*/
35+
public $region;
36+
/**
37+
* @var string|null $country
38+
*/
39+
public $country;
40+
41+
/**
42+
* @param string $locality
43+
* @param string $postalCode
44+
* @param string $neighborhood
45+
* @param string $region
46+
* @param string $country
47+
*/
48+
public function __construct($locality, $postalCode, $neighborhood, $region, $country) {
49+
$this->locality = $locality;
50+
$this->postalCode = $postalCode;
51+
$this->neighborhood = $neighborhood;
52+
$this->region = $region;
53+
$this->country = $country;
54+
}
55+
56+
57+
public function jsonSerialize() {
58+
return array(
59+
'type' => "StructuredPlaceInfo",
60+
'locality' => $this->locality,
61+
'postalCode' => $this->postalCode,
62+
'neighborhood' => $this->neighborhood,
63+
'region' => $this->region,
64+
'country' => $this->country,
65+
);
66+
}
67+
68+
}
69+

0 commit comments

Comments
 (0)