Skip to content

Commit 472bcf5

Browse files
committed
Přidána knihovna s CZ a SK lokalizací
1 parent b910f56 commit 472bcf5

21 files changed

+667
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor
2+
/composer.lock
3+
/output.cs

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.PHONY: build-staging
2+
.PHONY: clean
3+
.PHONY: clean-cache
4+
.PHONY: cs
5+
6+
7+
build-staging:
8+
- composer install --no-interaction -o -a --no-suggest
9+
10+
11+
clean:
12+
git clean -xdf .
13+
14+
15+
clean-cache:
16+
git clean -xdf tests/
17+
18+
19+
run-tests:
20+
git clean -xdf tests/
21+
composer install --no-interaction
22+
- vendor/bin/tester -p php -c tests/php.ini -o tap tests > output.tap
23+
git clean -xdf tests/
24+
25+
26+
cs:
27+
git clean -xdf output.cs output-strict.cs
28+
- vendor/bin/phpcs src/ --standard=vendor/pd/coding-standard/src/PeckaCodingStandard/ruleset.xml --report-file=output.cs
29+
- vendor/bin/phpcs src/ --standard=vendor/pd/coding-standard/src/PeckaCodingStandardStrict/ruleset.xml --report-file=output-strict.cs
30+
- test -f output-strict.cs && cat output-strict.cs >> output.cs && rm output-strict.cs

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "pd/holidays",
3+
"type": "library",
4+
"description": "Přehled svátků pro různé lokalizace",
5+
"authors": [
6+
{
7+
"name": "Milan Pála",
8+
"email": "milan.pala@peckadesign.cz"
9+
}
10+
],
11+
"require": {
12+
"nette/utils": "2.3.*|2.4.*"
13+
},
14+
"minimum-stability": "stable",
15+
"require-dev": {
16+
"nette/tester": "1.7.*",
17+
"pd/coding-standard": "1.7.*"
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"Pd\\Holidays\\": "src"
22+
}
23+
},
24+
"autoload-dev": {
25+
"psr-4": {
26+
"PdTests\\Holidays\\": "tests"
27+
}
28+
}
29+
30+
}

src/Holiday.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Pd\Holidays;
4+
5+
class Holiday implements IHoliday
6+
{
7+
8+
/**
9+
* @var int
10+
*/
11+
private $month;
12+
13+
/**
14+
* @var int
15+
*/
16+
private $day;
17+
18+
/**
19+
* @var string
20+
*/
21+
private $name;
22+
23+
24+
public function __construct(
25+
int $month,
26+
int $day,
27+
string $name
28+
) {
29+
$this->month = $month;
30+
$this->day = $day;
31+
$this->name = $name;
32+
}
33+
34+
35+
public function getMonth(): int
36+
{
37+
return $this->month;
38+
}
39+
40+
41+
public function getDay(): int
42+
{
43+
return $this->day;
44+
}
45+
46+
47+
public function getName(): string
48+
{
49+
return $this->name;
50+
}
51+
52+
}

src/HolidayFacade.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Pd\Holidays;
4+
5+
use Pd;
6+
7+
8+
class HolidayFacade implements IHolidayFacade
9+
{
10+
11+
/** @var array|ILocalization[] */
12+
private $localizations;
13+
14+
15+
public function getHoliday(string $countryCode, \DateTimeInterface $dateTime): ?IHoliday
16+
{
17+
$localization = $this->localizations[$countryCode] ?? NULL;
18+
19+
if ( ! $localization) {
20+
return NULL;
21+
}
22+
23+
$year = $localization->getHolidays((int) $dateTime->format('Y'));
24+
25+
if ( ! $year) {
26+
return NULL;
27+
}
28+
29+
return $year->getHoliday($dateTime);
30+
}
31+
32+
33+
public function getHolidays(string $countryCode, int $year): IYear
34+
{
35+
$localization = $this->localizations[$countryCode] ?? NULL;
36+
37+
if ( ! $localization) {
38+
return new Year([]);
39+
}
40+
41+
return $localization->getHolidays($year);
42+
}
43+
44+
45+
public function addLocalization(string $countryCode, ILocalization $localization): void
46+
{
47+
$this->localizations[$countryCode] = $localization;
48+
}
49+
50+
}

src/HolidayFactory.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Pd\Holidays;
4+
5+
class HolidayFactory
6+
{
7+
8+
/**
9+
* @var array ['_lang' => 'value']
10+
*/
11+
private $translates;
12+
13+
14+
public function __construct(array $translates)
15+
{
16+
$this->translates = $translates;
17+
}
18+
19+
20+
public function create(int $month, int $day, string $name): Holiday
21+
{
22+
return new Holiday($month, $day, $this->translates[$name] ?? $name);
23+
}
24+
}

src/IHoliday.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Pd\Holidays;
4+
5+
interface IHoliday
6+
{
7+
8+
public function getMonth(): int;
9+
10+
11+
public function getDay(): int;
12+
13+
14+
public function getName(): string;
15+
16+
}

src/IHolidayFacade.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Pd\Holidays;
4+
5+
interface IHolidayFacade
6+
{
7+
8+
public function getHoliday(string $countryCode, \DateTimeInterface $dateTime): ?IHoliday;
9+
10+
public function getHolidays(string $countryCode, int $year): IYear;
11+
12+
}

src/ILocalization.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Pd\Holidays;
4+
5+
interface ILocalization
6+
{
7+
8+
public function getHolidays(int $year): IYear;
9+
10+
}

src/IYear.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Pd\Holidays;
4+
5+
interface IYear
6+
{
7+
8+
public function getHoliday(\DateTimeInterface $dateTime): ?IHoliday;
9+
10+
11+
/** @return array|IHoliday[] */
12+
public function getHolidays(): array;
13+
}

0 commit comments

Comments
 (0)