Guest User

Untitled

a guest
Nov 21st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. <?php
  2. class Property implements LolalizedPropertyInterface
  3. {
  4. // by default pick primary title
  5. public function getTitle(): string {
  6. return getTitlePrimary();
  7. }
  8.  
  9. // "real" accessors
  10. public function getTitlePrimary();
  11. public function getTitleSecondary();
  12.  
  13. // ... same for other attributes //
  14. public function getQualityScore();
  15. public function getSerpScore();
  16. public function getPrice();
  17. }
  18.  
  19. interface LolalizedPropertyInterface
  20. {
  21. public function getTitle(): string;
  22. public function getQualityScore(): float;
  23. public function getSerpScore(): float;
  24. }
  25.  
  26. class LocalizedProperty
  27. {
  28. private $property;
  29.  
  30. public function getTitle(): string
  31. {
  32. if ($language->getCurrent() == $language->getPrimary()) {
  33. return $this->getTitlePrimary();
  34. }
  35.  
  36. if ($language->getCurrent() == $language->getSecondary()) {
  37. return $this->getTitleSecondary();
  38. }
  39. }
  40. // ... same for other attributes //
  41. public function getQualityScore(): float;
  42. public function getSerpScore(): float;
  43. }
  44.  
  45. interface PriceFormatterInterface
  46. {
  47. public function format(float $price): string;
  48. }
  49.  
  50. class VoidPriceFormatter implements PriceFormatterInterface
  51. {
  52. public function format(float $price): string
  53. {
  54. return $price;
  55. }
  56. }
  57.  
  58. class CurrencyPriceFormatter implements PriceFormatterInterface
  59. {
  60. private $settings;
  61.  
  62. public function format(float $price): string
  63. {
  64. return sprintf('%f %s', $price, $settings->getCurrency());
  65. }
  66. }
  67.  
  68.  
  69. class PropertyNormalizer
  70. {
  71. /** @var PriceFormatterInterface */
  72. private $priceFormatter;
  73.  
  74. // Same normalizer, same structure,
  75. public function normalize(LocalizedPropertyInterface $property): array
  76. {
  77. return [
  78. 'title' => $property->getTitle(),
  79. 'price' => $this->priceFormatter->format($property-getPrice()),
  80. ];
  81. }
  82. }
  83.  
  84. class PropertyItemViewBuilder
  85. {
  86. public function build(LocalizedPropertyInterface $property): PropertyItemView
  87. }
Add Comment
Please, Sign In to add comment