Skip to content

Commit 007c62b

Browse files
committed
add common name and flag of country
1 parent bed6de1 commit 007c62b

File tree

6 files changed

+81
-7
lines changed

6 files changed

+81
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 4.2.0 (2023-06-11)
2+
### Added
3+
- Common name of country `\Sokil\IsoCodes\Database\Countries\Country::getCommonName`
4+
- Flag of country `\Sokil\IsoCodes\Database\Countries\Country::getFlag`
5+
16
## 4.1.1 (2023-02-10)
27
### Fixes
38
- Auth release fix. Swallow clone does not clone tags required to set version in README

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2013-2022 Dmytro Sokil
3+
Copyright (c) 2013-2023 Dmytro Sokil
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Stand With Ukraine
1+
# Stand With Ukraine 🇺🇦
22

33
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
44

@@ -248,7 +248,7 @@ $isoCodes = new IsoCodesFactory(
248248

249249
### Factory
250250

251-
All databases may be create through factory:
251+
All databases may be created through factory:
252252

253253
```php
254254
<?php
@@ -287,6 +287,34 @@ This may require a lot of RAM for storing all entries.
287287

288288
### Countries database (ISO 3166-1)
289289

290+
Country contains next names:
291+
292+
| Name | Description | Example |
293+
|----------------|-------------|----------------------|
294+
| Name | Required | Moldova, Republic of |
295+
| Official Name | Optional | Republic of Moldova |
296+
| Common Name | Optional | Moldova |
297+
| Localised Name | Optional | Молдова |
298+
299+
This names may be get from country entity:
300+
301+
```php
302+
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
303+
$country = $isoCodes->getCountries()->getByAlpha2('UA');
304+
echo $country->getName();
305+
echo $country->getLocalName();
306+
echo $country->getOfficialName();
307+
echo $country->getCommonName();
308+
```
309+
310+
Also you may get flag of country:
311+
312+
```php
313+
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
314+
$country = $isoCodes->getCountries()->getByAlpha2('UA');
315+
echo $country->getFlag();
316+
```
317+
290318
Get localized name of country by it's alpha2 code:
291319
```php
292320
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
@@ -296,13 +324,13 @@ $isoCodes->getCountries()->getByAlpha2('UA')->getLocalName();
296324
Get localized name of country by it's alpha2 code:
297325
```php
298326
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
299-
$isoCodes->getCountries()->getByAlpha2('UKR')->getName();
327+
$isoCodes->getCountries()->getByAlpha2('UKR')->getLocalName();
300328
```
301329

302330
Get localized name of country by it's numeric code:
303331
```php
304332
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
305-
$isoCodes->getCountries()->getByAlpha2('804')->getName();
333+
$isoCodes->getCountries()->getByAlpha2('804')->getLocalName();
306334
```
307335

308336
Get localised list of countries

src/Database/Countries.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ protected function arrayToEntry(array $entry): Country
3333
$entry['alpha_2'],
3434
$entry['alpha_3'],
3535
$entry['numeric'],
36-
!empty($entry['official_name']) ? $entry['official_name'] : null
36+
$entry['flag'],
37+
!empty($entry['official_name']) ? $entry['official_name'] : null,
38+
!empty($entry['common_name']) ? $entry['common_name'] : null,
3739
);
3840
}
3941

src/Database/Countries/Country.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,23 @@ class Country
3434
*/
3535
private $numericCode;
3636

37+
/**
38+
* Emoji of country flag
39+
*
40+
* @var string
41+
*/
42+
private $flag;
43+
3744
/**
3845
* @var string
3946
*/
4047
private $officialName;
4148

49+
/**
50+
* @var string
51+
*/
52+
private $commonName;
53+
4254
/**
4355
* @var TranslatorInterface
4456
*/
@@ -50,14 +62,18 @@ public function __construct(
5062
string $alpha2,
5163
string $alpha3,
5264
string $numericCode,
53-
?string $officialName = null
65+
string $flag,
66+
?string $officialName = null,
67+
?string $commonName = null
5468
) {
5569
$this->translator = $translator;
5670
$this->name = $name;
5771
$this->alpha2 = $alpha2;
5872
$this->alpha3 = $alpha3;
5973
$this->numericCode = $numericCode;
74+
$this->flag = $flag;
6075
$this->officialName = $officialName;
76+
$this->commonName = $commonName;
6177
}
6278

6379
public function getAlpha2(): string
@@ -75,6 +91,14 @@ public function getNumericCode(): string
7591
return $this->numericCode;
7692
}
7793

94+
/**
95+
* @return string
96+
*/
97+
public function getFlag(): string
98+
{
99+
return $this->flag;
100+
}
101+
78102
public function getName(): string
79103
{
80104
return $this->name;
@@ -96,4 +120,9 @@ public function getOfficialName(): ?string
96120
{
97121
return $this->officialName;
98122
}
123+
124+
public function getCommonName(): ?string
125+
{
126+
return $this->commonName;
127+
}
99128
}

tests/Database/CountriesTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ public function testGetByAlpha2(): void
6666
null,
6767
$country->getOfficialName()
6868
);
69+
70+
$this->assertEquals(
71+
null,
72+
$country->getCommonName()
73+
);
74+
75+
$this->assertEquals(
76+
'🇺🇦',
77+
$country->getFlag()
78+
);
6979
}
7080

7181
public function testGetByAlpha3(): void

0 commit comments

Comments
 (0)