1 <?php
2 /* --------------------------------------------------------------
3 CustomerCountryRepository.inc.php 2015-02-18 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('CustomerCountryRepositoryInterface');
13
14 /**
15 * Class CustomerCountryRepository
16 *
17 * This class provides basic methods for finding customer country data
18 *
19 * @category System
20 * @package Customer
21 * @subpackage Country
22 * @implements CustomerCountryRepositoryInterface
23 */
24 class CustomerCountryRepository implements CustomerCountryRepositoryInterface
25 {
26 /**
27 * @var CustomerCountryReaderInterface
28 */
29 protected $customerCountryReader;
30
31
32 /**
33 * Constructor of the class CustomerCountryRepository
34 *
35 * @param CustomerCountryReader $customerCountryReader
36 */
37 public function __construct(CustomerCountryReader $customerCountryReader)
38 {
39 $this->customerCountryReader = $customerCountryReader;
40 }
41
42
43 /**
44 * @param IdType $countryId
45 *
46 * @return CustomerCountry
47 * @throws Exception if country not found
48 */
49 public function getById(IdType $countryId)
50 {
51 $country = $this->customerCountryReader->findById($countryId);
52
53 if($country === null)
54 {
55 throw new Exception('Country with the following ID could not be found: ' . (string)$countryId);
56 }
57
58 return $country;
59 }
60
61
62 /**
63 * This method will get a country if it exists else it will return null.
64 *
65 * @param IdType $countryId
66 *
67 * @return CustomerCountry|null
68 */
69 public function findById(IdType $countryId)
70 {
71 $country = $this->customerCountryReader->findById($countryId);
72
73 return $country;
74 }
75
76
77 /**
78 * Get country by name.
79 *
80 * @param \CustomerCountryNameInterface $countryName
81 *
82 * @return CustomerCountry
83 *
84 * @throws Exception If the country could not be found.
85 */
86 public function getByName(CustomerCountryNameInterface $countryName)
87 {
88 $country = $this->customerCountryReader->findByName($countryName);
89
90 if(empty($country))
91 {
92 throw new Exception('Country with the following name could not be found: ' . (string)$countryName);
93 }
94
95 return $country;
96 }
97 }