Horde_Timezone::_download PHP Method

_download() protected method

Downloads a timezone database.
protected _download ( )
    protected function _download()
    {
        $url = @parse_url($this->_params['location']);
        if (!isset($url['scheme'])) {
            throw new Horde_Timezone_Exception('"location" parameter is missing an URL scheme.');
        }
        if (!in_array($url['scheme'], array('http', 'ftp', 'file'))) {
            throw new Horde_Timezone_Exception(sprintf('Unsupported URL scheme "%s"', $url['scheme']));
        }
        if ($url['scheme'] == 'http') {
            if (isset($this->_params['client'])) {
                $client = $this->_params['client'];
            } else {
                $client = new Horde_Http_Client();
            }
            $response = $client->get($this->_params['location']);
            $this->_tmpfile = Horde_Util::getTempFile('', true, isset($this->_params['temp']) ? $this->_params['temp'] : '');
            stream_copy_to_stream($response->getStream(), fopen($this->_tmpfile, 'w'));
            return;
        }
        if ($url['scheme'] == 'ftp') {
            try {
                $vfs = new Horde_Vfs_Ftp(array('hostspec' => $url['host'], 'username' => 'anonymous', 'password' => 'anonymous', 'pasv' => true));
                $this->_tmpfile = $vfs->readFile(dirname($url['path']), basename($url['path']));
            } catch (Horde_Vfs_Exception $e) {
                throw new Horde_Timezone_Exception($e);
            }
        } else {
            $this->_tmpfile = $this->_params['location'];
            if (!is_readable($this->_tmpfile)) {
                $e = new Horde_Timezone_Exception(sprintf('Unable to open file %s.', $this->_params['location']));
                if (isset($php_errormsg)) {
                    $e->details = $php_errormsg;
                }
                throw $e;
            }
        }
    }