toArray(), $options); Qs_Options::setOptions($this, $options); } /** * @return mixed */ public function getBasePath() { return $this->basePath; } /** * @param mixed $basePath * @return $this */ public function setBasePath($basePath) { $this->basePath = $basePath; return $this; } /** * @return array */ public function getFonts() { return $this->fonts; } /** * @param array $fonts * @return $this */ public function setFonts($fonts) { $this->fonts = $fonts; return $this; } /** * @return array */ public function getUserAgents() { return $this->userAgents; } /** * @param array $userAgents * @return $this */ public function setUserAgents($userAgents) { $this->userAgents = $userAgents; return $this; } /** * @param null $browser * @return mixed */ public function getUserAgent($browser = null) { if (null !== $browser) { return Qs_Array::get($this->userAgents, $browser); } return $this->userAgent; } /** * @param mixed $userAgent * @return $this */ public function setUserAgent($userAgent) { $this->userAgent = $userAgent; return $this; } public function getStylesheet() { return Qs_Array::get($this->fonts, $this->getBrowser(), false); } public function getBrowser() { if (null === $this->browser) { $userAgent = $this->getUserAgent(); if (preg_match('/MSIE/i', $userAgent)) { $this->browser = 'ie'; } elseif (preg_match('/Firefox/i', $userAgent)) { $this->browser = 'firefox'; } elseif (preg_match('/Chrome/i', $userAgent)) { $this->browser = 'chrome'; } elseif (preg_match('/Safari/i', $userAgent)) { $this->browser = 'safari'; } else { $this->browser = 'other'; } } return $this->browser; } public function downloadAsBrowser($url, $fileName, $browser) { if ('//' == substr($url, 0, 2)) { $url = 'http:' . $url; } $userAgent = $this->getUserAgent($browser); $client = new \Zend\Http\Client($url, ['useragent' => $userAgent]); $response = $client->send(); if ($response->getStatusCode() != 200) { trigger_error('Failed to download google fonts stylesheet. HTTP ' . $response->getStatusCode()); return false; } $content = $response->getBody(); $content = str_replace('http://', '//', $content); if (false === file_put_contents($this->basePath . '/' . $fileName, $content)) { trigger_error('Can\'t write file ' . $fileName); return false; } return true; } }