当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Http_Client::setStream方法代码示例

本文整理汇总了PHP中Zend_Http_Client::setStream方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::setStream方法的具体用法?PHP Zend_Http_Client::setStream怎么用?PHP Zend_Http_Client::setStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Http_Client的用法示例。


在下文中一共展示了Zend_Http_Client::setStream方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testStreamResponseNamed

    public function testStreamResponseNamed()
    {
        if(!($this->client->getAdapter() instanceof Zend_Http_Client_Adapter_Stream)) {
              $this->markTestSkipped('Current adapter does not support streaming');
              return;
        }
        $this->client->setUri($this->baseuri . 'staticFile.jpg');
        $outfile = tempnam(sys_get_temp_dir(), "outstream");
        $this->client->setStream($outfile);

        $response = $this->client->request();

        $this->assertTrue($response instanceof Zend_Http_Response_Stream, 'Request did not return stream response!');
        $this->assertTrue(is_resource($response->getStream()), 'Request does not contain stream!');

        $this->assertEquals($outfile, $response->getStreamName());

        $stream_read = stream_get_contents($response->getStream());
        $file_read = file_get_contents($outfile);

        $expected = $this->_getTestFileContents('staticFile.jpg');

        $this->assertEquals($expected, $stream_read, 'Downloaded stream does not seem to match!');
        $this->assertEquals($expected, $file_read, 'Downloaded file does not seem to match!');
    }
开发者ID:nbcutech,项目名称:o3drupal,代码行数:25,代码来源:CommonHttpTests.php

示例2: getProperDimensionsPictureUrl

 public function getProperDimensionsPictureUrl($twitterId, $pictureUrl)
 {
     $pictureUrl = str_replace('_normal', '', $pictureUrl);
     $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'le' . '/' . 'sociallogin' . '/' . 'twitter' . '/' . $twitterId;
     $filename = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . 'le' . DS . 'sociallogin' . DS . 'twitter' . DS . $twitterId;
     $directory = dirname($filename);
     if (!file_exists($directory) || !is_dir($directory)) {
         if (!@mkdir($directory, 0777, true)) {
             return null;
         }
     }
     if (!file_exists($filename) || file_exists($filename) && time() - filemtime($filename) >= 3600) {
         $client = new Zend_Http_Client($pictureUrl);
         $client->setStream();
         $response = $client->request('GET');
         stream_copy_to_stream($response->getStream(), fopen($filename, 'w'));
         $imageObj = new Varien_Image($filename);
         $imageObj->constrainOnly(true);
         $imageObj->keepAspectRatio(true);
         $imageObj->keepFrame(false);
         $imageObj->resize(150, 150);
         $imageObj->save($filename);
     }
     return $url;
 }
开发者ID:cabrerabywaters,项目名称:magentoSunshine,代码行数:25,代码来源:Twitter.php

示例3: addFile

 /**
  * Adds one or more files
  *
  * @param  string|array $file      File to add
  * @param  string|array $validator Validators to use for this file, must be set before
  * @param  string|array $filter    Filters to use for this file, must be set before
  * @return Zend_File_Transfer_Adapter_Abstract
  * @throws Zend_File_Transfer_Exception Not implemented
  */
 public function addFile($files, $validator = null, $filter = null)
 {
     foreach ($files as $name => $file) {
         $dest = tempnam(sys_get_temp_dir(), 'transfert');
         $client = new Zend_Http_Client($file, array('adapter' => 'Zend_Http_Client_Adapter_Curl'));
         $response = $client->setStream($dest)->request(Zend_Http_Client::GET);
         $this->_files[$name] = array('size' => filesize($dest), 'tmp_name' => $dest, 'name' => basename($file));
         $this->_files[$name]['type'] = $this->_detectMimeType($this->_files[$name]);
     }
     return $this;
 }
开发者ID:rom1git,项目名称:Centurion,代码行数:20,代码来源:Remote.php

示例4: getStreamData

 /**
  * Get Stream Data.
  *
  *
  * $data can also be stream (such as file) to which the data will be save.
  * 
  * $client->setStream(); // will use temp file
  * $response = $client->request('GET');
  * // copy file
  * copy($response->getStreamName(), "my/downloads/file");
  * // use stream
  * $fp = fopen("my/downloads/file2", "w");
  * stream_copy_to_stream($response->getStream(), $fp);
  * // Also can write to known file
  * $client->setStream("my/downloads/myfile")->request('GET');
  * 
  * @param resource $data
  * @param string $enctype
  * @return Default_Plugin_HttpBox
  */
 function getStreamData($filename = null)
 {
     if (is_string($filename)) {
         $this->client->setStream($filename)->request('GET');
     } else {
         $this->client->setStream();
         // will use temp file
         $this->client->request('GET');
     }
     // Запомним последний запрос в виде строки
     $this->last_request = $this->client->getLastRequest();
     // Запомним последний запрос в виде Zend_Http_Response
     $this->last_response = $this->client->getLastResponse();
     return $this;
 }
开发者ID:bsa-git,项目名称:zf-myblog,代码行数:35,代码来源:HttpBox.php

示例5: downloadPlugin

    /**
     * Helper function to download the zip file from the passed url.
     * @param $url
     * @return array
     */
    public function downloadPlugin($url)
    {
        $name = 'plugin' . md5($url) . '.zip';
        $tmp = Shopware()->DocPath() . 'files/downloads/' . $name;
        $message = '';

        try {
            $client = new Zend_Http_Client($url, array(
                'timeout' => 30,
                'useragent' => 'Shopware/' . Shopware()->Config()->Version
            ));
            $client->setStream($tmp);
            $client->request('GET');
            $this->decompressFile($tmp);
        } catch (Exception $e) {
            $message = $e->getMessage();
        }

        @unlink($tmp);

        return array(
            'success' => empty($message),
            'message' => $message,
            'url' => $url
        );
    }
开发者ID:nhp,项目名称:shopware-4,代码行数:31,代码来源:Store.php

示例6: testStreamWarningRewind

 function testStreamWarningRewind()
 {
     $httpClient = new Zend_Http_Client();
     $httpClient->setUri('http://example.org');
     $httpClient->setMethod(Zend_Http_Client::GET);
     ob_start();
     $httpClient->setStream('php://output')->request();
     ob_clean();
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:9,代码来源:StaticTest.php

示例7: getResultStream

 function getResultStream()
 {
     if (!$this->resourceURI) {
         $requestURI = $this->APIuri . "/users/" . $this->user . "/batchjobs/" . urlencode($this->batchName) . "/" . $this->resourceID . "." . $this->resultFormat;
         //$requestURI = $this->APIuri."/users/".$this->user."/batchjobs/".$this->batchName;
         $this->resourceURI = $requestURI;
     } else {
         $requestURI = $this->resourceURI;
     }
     $uriExplode = explode("/", $this->resourceURI);
     $fileName = $uriExplode[count($uriExplode) - 1];
     $tempID = preg_replace('/[^a-z0-9]/i', '_', $fileName);
     $tempID_a = $tempID . "-temp-a";
     $tempID_b = $tempID . "-temp-b";
     $client = new Zend_Http_Client($requestURI, array('maxredirects' => 1, 'timeout' => self::HTTPtimeout));
     $client->setStream();
     //$client->setHeaders('Host', $this->requestHost);
     if ($this->resultFormat == "xml") {
         $client->setHeaders('Accept', 'application/json');
     } else {
         $client->setHeaders('Accept', 'application/json');
     }
     //$client->setHeaders('Accept', 'application/json');
     $client->setHeaders('AUTHORIZATION', $this->password);
     //$client->setHeaders('User-Key', $this->userKey);
     $response = $client->request("GET");
     copy($response->getStreamName(), self::resultCache . "/" . $tempID_a);
     $fp = fopen(self::resultCache . "/" . $tempID_b, "w");
     stream_copy_to_stream($response->getStream(), $fp);
     $client->setStream(self::resultCache . "/" . $tempID_a)->request('GET');
     return $response;
 }
开发者ID:shawngraham,项目名称:gap2,代码行数:32,代码来源:EdinaText.php

示例8: installPlugin

 public function installPlugin($source, $isUrl = false)
 {
     X_Debug::i("Installing plugin from {{$source}}: isUrl = {{$isUrl}}");
     if ($isUrl) {
         // perform a download in a temp file
         $http = new Zend_Http_Client($source, array('headers' => array('User-Agent' => "vlc-shares/" . X_VlcShares::VERSION . " plugininstaller/" . X_VlcShares::VERSION)));
         $http->setStream(true);
         $source = $http->request()->getStreamName();
     }
     try {
         // unzip and manifest parse
         $egg = X_Egg::factory($source, APPLICATION_PATH . '/../', APPLICATION_PATH . '/../data/plugin/tmp/', true);
         $pluginKey = $egg->getKey();
         // first we must check if key already exists in the db
         $plugin = new Application_Model_Plugin();
         Application_Model_PluginsMapper::i()->fetchByKey($pluginKey, $plugin);
         if ($plugin->getId() !== null) {
             throw new Exception(X_Env::_('plugin_err_installerror_keyexists') . ": {$pluginKey}");
         }
         // time to check if plugin support this vlc-shares version
         $vFrom = $egg->getCompatibilityFrom();
         $vTo = $egg->getCompatibilityTo();
         if (version_compare(X_VlcShares::VERSION_CLEAN, $vFrom, '<') || $vTo !== null && version_compare(X_VlcShares::VERSION_CLEAN, $vTo, '>=')) {
             throw new Exception(X_Env::_('plugin_err_installerror_unsupported') . ": {$vFrom} - {$vTo}");
         }
         // copy the files: first check if some file exists...
         $toBeCopied = array();
         foreach ($egg->getFiles() as $file) {
             /* @var $file X_Egg_File */
             if (!$file->getProperty(X_Egg_File::P_REPLACE, false) && file_exists($file->getDestination())) {
                 throw new Exception(X_Env::_('plugin_err_installerror_fileexists') . ": {$file->getDestination()}");
             }
             if (!file_exists($file->getSource())) {
                 if (!$file->getProperty(X_Egg_File::P_IGNOREIFNOTEXISTS, false)) {
                     throw new Exception(X_Env::_('plugin_err_installerror_sourcenotexists') . ": {$file->getSource()}");
                 }
                 // ignore this item if P_IGNOREIFNOTEXISTS is true and file not exists
                 continue;
             }
             $toBeCopied[] = array('src' => $file->getSource(), 'dest' => $file->getDestination(), 'resource' => $file);
         }
         // before copy act, i must be sure to be able to revert changes
         $plugin = new Application_Model_Plugin();
         $plugin->setLabel($egg->getLabel())->setKey($pluginKey)->setDescription($egg->getDescription())->setFile($egg->getFile())->setClass($egg->getClass())->setType(Application_Model_Plugin::USER)->setVersion($egg->getVersion());
         Application_Model_PluginsMapper::i()->save($plugin);
         // so i must copy uninstall information inside a uninstall dir in data
         $dest = APPLICATION_PATH . '/../data/plugin/_uninstall/' . $pluginKey;
         // i have to create the directory
         if (!mkdir($dest, 0777, true)) {
             throw new Exception(X_Env::_('plugin_err_installerror_uninstalldircreation') . ": {$dest}");
         }
         if (!copy($egg->getManifestFile(), "{$dest}/manifest.xml")) {
             throw new Exception(X_Env::_('plugin_err_installerror_uninstallmanifestcopy') . ": " . $egg->getManifestFile() . " -> {$dest}/manifest.xml");
         }
         $uninstallSql = $egg->getUninstallSQL();
         if ($uninstallSql !== null && file_exists($uninstallSql)) {
             if (!copy($uninstallSql, "{$dest}/uninstall.sql")) {
                 throw new Exception(X_Env::_('plugin_err_installerror_uninstallsqlcopy') . ": {$dest}");
             }
         }
         // ... then copy
         foreach ($toBeCopied as $copyInfo) {
             $copied = false;
             if (!file_exists(dirname($copyInfo['dest']))) {
                 @mkdir(dirname($copyInfo['dest']), 0777, true);
             }
             if (!copy($copyInfo['src'], $copyInfo['dest'])) {
                 $this->_helper->flashMessenger(array('text' => X_Env::_('plugin_err_installerror_copyerror') . ": <br/>" . $copyInfo['src'] . '<br/>' . $copyInfo['dest'], 'type' => 'error'));
             } else {
                 X_Debug::i("File copied {{$copyInfo['dest']}}");
                 $copied = true;
             }
             /* @var $xeggFile X_Egg_File */
             $xeggFile = $copyInfo['resource'];
             if ($copied) {
                 // check permission
                 $permission = $xeggFile->getProperty(X_Egg_File::P_PERMISSIONS, false);
                 if ($permission !== false) {
                     if (!chmod($copyInfo['dest'], octdec($permission))) {
                         X_Debug::e("Chmod {{$permission}} failed for file {{$copyInfo['dest']}}");
                     } else {
                         X_Debug::i("Permissions set to {{$permission}} for file {{$copyInfo['dest']}} as required");
                     }
                 }
             } else {
                 if ($xeggFile->getProperty(X_Egg_File::P_HALTONCOPYERROR, false)) {
                     X_Debug::f("File not copied {{$copyInfo['dest']}} and flagged as HaltOnCopyError");
                     break;
                 }
             }
         }
         // change database
         $installSql = $egg->getInstallSQL();
         if ($installSql !== null && file_exists($installSql)) {
             try {
                 $dataSql = file_get_contents($installSql);
                 if (trim($dataSql) !== '') {
                     $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
                     $db = $bootstrap->getResource('db');
                     $db->getConnection()->exec($dataSql);
//.........这里部分代码省略.........
开发者ID:google-code-backups,项目名称:vlc-shares,代码行数:101,代码来源:PluginInstaller.php

示例9: downloadArchive

 /**
  * Attempt to download the extension archive file to var directory
  *
  * @param  Ash_Up_Model_Extension $extension
  * @return Ash_Up_Helper_Data
  */
 public function downloadArchive(Ash_Up_Model_Extension $extension)
 {
     $uri = $extension->getDownloadUri();
     $path = Mage::getConfig()->getVarDir('ash_installer/downloads');
     Mage::getConfig()->createDirIfNotExists($path);
     $archivePath = $path . DIRECTORY_SEPARATOR . $extension->getExtensionName() . '.zip';
     // configure client to download archive file
     $client = new Zend_Http_Client($uri);
     $adapter = new Zend_Http_Client_Adapter_Curl();
     $adapter->setConfig(array('curloptions' => array(CURLOPT_BINARYTRANSFER => true)));
     $client->setAdapter($adapter);
     $client->setStream($archivePath);
     // stream file to specified path
     $response = $client->request(Zend_Http_Client::GET);
     if ($response->getStatus() != 200) {
         Mage::throwException($this->__('Error downloading archive (%s): %s', $extension->getExtensionName(), $response->getMessage()));
     }
     // set archive path
     $extension->setLastDownloaded(time())->setArchivePath($archivePath)->save();
     return $this;
 }
开发者ID:AleksNesh,项目名称:pandora,代码行数:27,代码来源:Data.php

示例10: downloadAction

    /**
     * Direct download of a plugin zip file.
     */
    public function downloadAction()
    {
        return; //As long as this action is not being used, they should be inactive.
        $url = $this->Request()->link;
        $tmp = @tempnam(Shopware()->DocPath() . 'files/downloads', 'plugins');

        try {
            $client = new Zend_Http_Client($url, array(
                'timeout' => 10,
                'useragent' => 'Shopware/' . Shopware()->Config()->Version
            ));
            $client->setStream($tmp);
            $client->request('GET');

            $this->decompressFile($tmp);

        } catch (Exception $e) {
            $message = $e->getMessage();
        }

        @unlink($tmp);

        $this->View()->assign(array(
            'success' => !isset($message),
            'message' => isset($message) ? $message : ''
        ));
    }
开发者ID:nhp,项目名称:shopware-4,代码行数:30,代码来源:Plugin.php


注:本文中的Zend_Http_Client::setStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。