|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace LVR\State; |
| 4 | + |
| 5 | +class Parameters |
| 6 | +{ |
| 7 | + protected $country = null; |
| 8 | + protected $case = null; |
| 9 | + protected $type = null; |
| 10 | + |
| 11 | + public function __construct($params) |
| 12 | + { |
| 13 | + $params = array_map('strtolower', $params); |
| 14 | + $this->country = $this->pullCountry($params); |
| 15 | + $this->case = $this->pullCase($params); |
| 16 | + $this->type = $this->pullType($params); |
| 17 | + } |
| 18 | + |
| 19 | + protected function pullCountry($params) |
| 20 | + { |
| 21 | + $z = null; |
| 22 | + $x = [ |
| 23 | + "usa" => ["us", "usa"], |
| 24 | + "canada" => ["ca", "canada"], |
| 25 | + ]; |
| 26 | + |
| 27 | + foreach ($x as $key => $possibilities) { |
| 28 | + foreach ($possibilities as $value) { |
| 29 | + $z = in_array($value, $params) ? $key : $z; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + return $z; |
| 34 | + } |
| 35 | + |
| 36 | + protected function pullCase($params) |
| 37 | + { |
| 38 | + $z = null; |
| 39 | + $x = ["upper", "lower", "title"]; |
| 40 | + |
| 41 | + foreach ($x as $value) { |
| 42 | + $z = in_array($value, $params) ? $value : $z; |
| 43 | + } |
| 44 | + |
| 45 | + return $z; |
| 46 | + } |
| 47 | + |
| 48 | + protected function pullType($params) |
| 49 | + { |
| 50 | + $z = null; |
| 51 | + $x = [ |
| 52 | + "abbr" => ["abbr", "abbrev", "abbreviation"], |
| 53 | + "full" => ["full", "long", "whole"], |
| 54 | + ]; |
| 55 | + |
| 56 | + foreach ($x as $key => $possibilities) { |
| 57 | + foreach ($possibilities as $value) { |
| 58 | + $z = in_array($value, $params) ? $key : $z; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return $z; |
| 63 | + } |
| 64 | + |
| 65 | + public function getCountry() |
| 66 | + { |
| 67 | + return $this->country; |
| 68 | + } |
| 69 | + |
| 70 | + public function getCase() |
| 71 | + { |
| 72 | + return $this->case; |
| 73 | + } |
| 74 | + |
| 75 | + public function getType() |
| 76 | + { |
| 77 | + return $this->type; |
| 78 | + } |
| 79 | +} |
0 commit comments