Skip to content

Commit

Permalink
Merge pull request #72 from sokil/country_details
Browse files Browse the repository at this point in the history
add common name and flag of country
  • Loading branch information
sokil authored Jun 11, 2023
2 parents bed6de1 + 007c62b commit 81dcf7e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.2.0 (2023-06-11)
### Added
- Common name of country `\Sokil\IsoCodes\Database\Countries\Country::getCommonName`
- Flag of country `\Sokil\IsoCodes\Database\Countries\Country::getFlag`

## 4.1.1 (2023-02-10)
### Fixes
- Auth release fix. Swallow clone does not clone tags required to set version in README
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2013-2022 Dmytro Sokil
Copyright (c) 2013-2023 Dmytro Sokil

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Stand With Ukraine
# Stand With Ukraine 🇺🇦

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

Expand Down Expand Up @@ -248,7 +248,7 @@ $isoCodes = new IsoCodesFactory(

### Factory

All databases may be create through factory:
All databases may be created through factory:

```php
<?php
Expand Down Expand Up @@ -287,6 +287,34 @@ This may require a lot of RAM for storing all entries.

### Countries database (ISO 3166-1)

Country contains next names:

| Name | Description | Example |
|----------------|-------------|----------------------|
| Name | Required | Moldova, Republic of |
| Official Name | Optional | Republic of Moldova |
| Common Name | Optional | Moldova |
| Localised Name | Optional | Молдова |

This names may be get from country entity:

```php
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$country = $isoCodes->getCountries()->getByAlpha2('UA');
echo $country->getName();
echo $country->getLocalName();
echo $country->getOfficialName();
echo $country->getCommonName();
```

Also you may get flag of country:

```php
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$country = $isoCodes->getCountries()->getByAlpha2('UA');
echo $country->getFlag();
```

Get localized name of country by it's alpha2 code:
```php
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
Expand All @@ -296,13 +324,13 @@ $isoCodes->getCountries()->getByAlpha2('UA')->getLocalName();
Get localized name of country by it's alpha2 code:
```php
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$isoCodes->getCountries()->getByAlpha2('UKR')->getName();
$isoCodes->getCountries()->getByAlpha2('UKR')->getLocalName();
```

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

Get localised list of countries
Expand Down
4 changes: 3 additions & 1 deletion src/Database/Countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ protected function arrayToEntry(array $entry): Country
$entry['alpha_2'],
$entry['alpha_3'],
$entry['numeric'],
!empty($entry['official_name']) ? $entry['official_name'] : null
$entry['flag'],
!empty($entry['official_name']) ? $entry['official_name'] : null,
!empty($entry['common_name']) ? $entry['common_name'] : null,
);
}

Expand Down
31 changes: 30 additions & 1 deletion src/Database/Countries/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,23 @@ class Country
*/
private $numericCode;

/**
* Emoji of country flag
*
* @var string
*/
private $flag;

/**
* @var string
*/
private $officialName;

/**
* @var string
*/
private $commonName;

/**
* @var TranslatorInterface
*/
Expand All @@ -50,14 +62,18 @@ public function __construct(
string $alpha2,
string $alpha3,
string $numericCode,
?string $officialName = null
string $flag,
?string $officialName = null,
?string $commonName = null
) {
$this->translator = $translator;
$this->name = $name;
$this->alpha2 = $alpha2;
$this->alpha3 = $alpha3;
$this->numericCode = $numericCode;
$this->flag = $flag;
$this->officialName = $officialName;
$this->commonName = $commonName;
}

public function getAlpha2(): string
Expand All @@ -75,6 +91,14 @@ public function getNumericCode(): string
return $this->numericCode;
}

/**
* @return string
*/
public function getFlag(): string
{
return $this->flag;
}

public function getName(): string
{
return $this->name;
Expand All @@ -96,4 +120,9 @@ public function getOfficialName(): ?string
{
return $this->officialName;
}

public function getCommonName(): ?string
{
return $this->commonName;
}
}
10 changes: 10 additions & 0 deletions tests/Database/CountriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public function testGetByAlpha2(): void
null,
$country->getOfficialName()
);

$this->assertEquals(
null,
$country->getCommonName()
);

$this->assertEquals(
'🇺🇦',
$country->getFlag()
);
}

public function testGetByAlpha3(): void
Expand Down

0 comments on commit 81dcf7e

Please sign in to comment.