-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from cultuurnet/feature/WID-377-calendar-summa…
…ry-parameter WID-377 Add calendar summary parameter
- Loading branch information
Showing
9 changed files
with
261 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\Parameter; | ||
|
||
use CultuurNet\SearchV3\ParameterInterface; | ||
use CultuurNet\SearchV3\ValueObjects\CalendarSummaryFormat; | ||
|
||
final class CalendarSummary implements ParameterInterface | ||
{ | ||
/** | ||
* @var CalendarSummaryFormat | ||
*/ | ||
private $format; | ||
|
||
public function __construct(CalendarSummaryFormat $format) | ||
{ | ||
$this->format = $format; | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
return 'embedCalendarSummaries'; | ||
} | ||
|
||
public function getValue(): string | ||
{ | ||
return $this->format->getCombined(); | ||
} | ||
|
||
public function allowsMultiple(): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\ValueObjects; | ||
|
||
use InvalidArgumentException; | ||
|
||
final class CalendarSummaryFormat | ||
{ | ||
private const TYPES = [ | ||
'text', | ||
'html', | ||
]; | ||
|
||
private const SIZES = [ | ||
'xs', | ||
'sm', | ||
'md', | ||
'lg', | ||
]; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $size; | ||
|
||
public function __construct(string $type, string $size) | ||
{ | ||
if (!in_array($type, self::TYPES)) { | ||
throw new InvalidArgumentException( | ||
'Unsupported type ' . $type . '. Allowed values: ' . implode(', ', self::TYPES) | ||
); | ||
} | ||
|
||
if (!in_array($size, self::SIZES)) { | ||
throw new InvalidArgumentException( | ||
'Unsupported size ' . $size . '. Allowed values: ' . implode(', ', self::SIZES) | ||
); | ||
} | ||
|
||
$this->type = $type; | ||
$this->size = $size; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getSize(): string | ||
{ | ||
return $this->size; | ||
} | ||
|
||
public function getCombined(): string | ||
{ | ||
return $this->size . '-' . $this->type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\ValueObjects; | ||
|
||
use InvalidArgumentException; | ||
|
||
final class CalendarSummaryLanguage | ||
{ | ||
private const LANGUAGES = [ | ||
'nl', | ||
'fr', | ||
'de', | ||
'en', | ||
]; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $value; | ||
|
||
public function __construct(string $value) | ||
{ | ||
if (!in_array($value, self::LANGUAGES)) { | ||
throw new InvalidArgumentException( | ||
'Unsupported language ' . $value . '. Allowed values: ' . implode(', ', self::LANGUAGES) | ||
); | ||
} | ||
|
||
$this->value = $value; | ||
} | ||
|
||
public static function nl(): self | ||
{ | ||
return new self('nl'); | ||
} | ||
|
||
public static function fr(): self | ||
{ | ||
return new self('fr'); | ||
} | ||
|
||
public static function de(): self | ||
{ | ||
return new self('de'); | ||
} | ||
|
||
public static function en(): self | ||
{ | ||
return new self('en'); | ||
} | ||
|
||
public function getValue(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\ValueObjects; | ||
|
||
use InvalidArgumentException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class CalendarSummaryFormatTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_throws_on_unsupported_type(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
|
||
new CalendarSummaryFormat('markdown', 'sm'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_throws_on_unsupported_size(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
|
||
new CalendarSummaryFormat('html', 'xl'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\ValueObjects; | ||
|
||
use InvalidArgumentException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class CalendarSummaryLanguageTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_throws_on_unsupported_language(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
|
||
new CalendarSummaryLanguage('es'); | ||
} | ||
} |
Oops, something went wrong.