Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Property implements LolalizedPropertyInterface
- {
- // by default pick primary title
- public function getTitle(): string {
- return getTitlePrimary();
- }
- // "real" accessors
- public function getTitlePrimary();
- public function getTitleSecondary();
- // ... same for other attributes //
- public function getQualityScore();
- public function getSerpScore();
- public function getPrice();
- }
- interface LolalizedPropertyInterface
- {
- public function getTitle(): string;
- public function getQualityScore(): float;
- public function getSerpScore(): float;
- }
- class LocalizedProperty
- {
- private $property;
- public function getTitle(): string
- {
- if ($language->getCurrent() == $language->getPrimary()) {
- return $this->getTitlePrimary();
- }
- if ($language->getCurrent() == $language->getSecondary()) {
- return $this->getTitleSecondary();
- }
- }
- // ... same for other attributes //
- public function getQualityScore(): float;
- public function getSerpScore(): float;
- }
- interface PriceFormatterInterface
- {
- public function format(float $price): string;
- }
- class VoidPriceFormatter implements PriceFormatterInterface
- {
- public function format(float $price): string
- {
- return $price;
- }
- }
- class CurrencyPriceFormatter implements PriceFormatterInterface
- {
- private $settings;
- public function format(float $price): string
- {
- return sprintf('%f %s', $price, $settings->getCurrency());
- }
- }
- class PropertyNormalizer
- {
- /** @var PriceFormatterInterface */
- private $priceFormatter;
- // Same normalizer, same structure,
- public function normalize(LocalizedPropertyInterface $property): array
- {
- return [
- 'title' => $property->getTitle(),
- 'price' => $this->priceFormatter->format($property-getPrice()),
- ];
- }
- }
- class PropertyItemViewBuilder
- {
- public function build(LocalizedPropertyInterface $property): PropertyItemView
- }
Add Comment
Please, Sign In to add comment