Advertisement
Guest User

Presenter

a guest
Feb 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. class Country {
  2.     private $value;
  3.    
  4.     public function __construct(string $value)
  5.     {
  6.         $this->value = $value;
  7.     }
  8.  
  9.     public function __toString(): string
  10.     {
  11.         return $this->value;
  12.     }
  13. }
  14.  
  15. class Locale {
  16.     private $value;
  17.     private $country;
  18.  
  19.     public function __construct(string $value, Country $country) {
  20.         $this->value = $value;
  21.         $this->country = (string)$country;
  22.     }
  23.  
  24.     public function presentWith(callable $presenter): array {
  25.         return $presenter($this->value, $this->country);
  26.     }
  27. }
  28.  
  29. $locale = new Locale('RU', new Country('RUSSIA'));
  30.  
  31. $present = $locale->presentWith(function(string $locale, string $country) {
  32.     return [
  33.         'locale' => $locale,
  34.         'country' => $country
  35.     ];
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement