/** * @param Country $country * @param $size * @return string */ public static function render(Country $country, $size) { $path = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'flags' . DIRECTORY_SEPARATOR . $size . DIRECTORY_SEPARATOR; $img = new Image($path . $country->getFlag()); $header = $img->getHeader(); ob_start(); $img->output(); $img->destroy(); $i = ob_get_clean(); return '<img src="data:' . $header . ';base64,' . base64_encode($i) . '" />'; }
/** * @param string $id * @return Country */ public static function generate($id) { static $inst = null; if ($inst === null) { $inst = new CountryFactory(); $inst->countries = (require 'countries.php'); } if (!isset($inst->countries[$id])) { throw new InvalidArgumentException('No country found with that ID'); } $c = $inst->countries[$id]; $country = new Country(); $country->setId($c['id'])->setIso($c['iso'])->setName($c['name'])->setCountry($c['country'])->setNumCode($c['numcode'])->setFlag($c['flag']); return $country; }
/** * @param Country $country * @return Person */ public function setCountry(Country $country) { $this->country = $country->getId(); return $this; }