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


PHP StreamInterface::detach方法代码示例

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


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

示例1: put

 /**
  * Upload data to tracker
  *
  * @param string|StreamInterface|UploadedFileInterface $file
  * @param string $key
  * @param string $class
  * @param bool $use_file
  *
  * @return bool
  * @throws Exception
  */
 public function put($file, $key, $class, $use_file = true)
 {
     if ($key === null) {
         throw new InvalidArgumentException(get_class($this) . "::put key cannot be null");
     }
     if ($use_file) {
         if ($file instanceof UploadedFileInterface) {
             $fh = $file->getStream()->detach();
             $length = $file->getSize();
         } elseif ($file instanceof StreamInterface) {
             $fh = $file->detach();
             $length = $file->getSize();
         } elseif (is_resource($file) && get_resource_type($file) == 'stream') {
             $fh = $file;
         } else {
             $fh = fopen($file, 'r');
         }
         if (!$fh) {
             throw new RuntimeException(get_class($this) . "::put failed to open file");
         }
         if (!$length) {
             $length = filesize($file);
         }
     } else {
         $fh = fopen('php://memory', 'rw');
         if ($fh === false) {
             throw new RuntimeException(get_class($this) . "::put failed to open memory stream");
         }
         fwrite($fh, $file);
         rewind($fh);
         $length = strlen($file);
     }
     //CREATE_OPEN domain=%s&key=%s&class=%s&multi_dest=%d
     $location = $this->doRequest('CREATE_OPEN', ['domain' => $this->domain, 'key' => $key, 'class' => $class]);
     $uri = $location['path'];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_INFILE, $fh);
     curl_setopt($ch, CURLOPT_INFILESIZE, $length);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->request_timeout);
     curl_setopt($ch, CURLOPT_PUT, $this->request_timeout);
     curl_setopt($ch, CURLOPT_URL, $uri);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect: ']);
     $response = curl_exec($ch);
     fclose($fh);
     if ($response === false) {
         $error = curl_error($ch);
         curl_close($ch);
         throw new RuntimeException(get_class($this) . "::put {$error}");
     }
     curl_close($ch);
     $this->doRequest('CREATE_CLOSE', ['key' => $key, 'class' => $class, 'domain' => $this->domain, 'devid' => $location['devid'], 'fid' => $location['fid'], 'path' => urldecode($uri)]);
     return true;
 }
开发者ID:sunkan,项目名称:php-mogilefs,代码行数:65,代码来源:Client.php

示例2: detach

 /**
  * {@inheritdoc}
  */
 public function detach()
 {
     return $this->stream->detach();
 }
开发者ID:narrowspark,项目名称:framework,代码行数:7,代码来源:AbstractStreamDecorator.php

示例3: getHashOfStream

 /**
  * {@inheritdoc}
  */
 public function getHashOfStream(StreamInterface $stream, $binary = false)
 {
     $res = hash_init($this->alg);
     hash_update_stream($res, $stream->detach());
     return hash_final($res);
 }
开发者ID:spomky-labs,项目名称:php-http-digest,代码行数:9,代码来源:Sha512Algorithm.php

示例4: __construct

 public function __construct(StreamInterface $stream)
 {
     $this->socket = $stream->detach();
 }
开发者ID:hafeez3000,项目名称:docker-php,代码行数:4,代码来源:AttachWebsocketStream.php

示例5: detach

 /**
  * {@inheritdoc}
  */
 public function detach()
 {
     return $this->decoratedStream->detach();
 }
开发者ID:zendframework,项目名称:zend-diactoros,代码行数:7,代码来源:RelativeStream.php

示例6: parseCsv

 /**
  * Parses csv.
  * 
  * @param StreamInterface $body
  * 
  * @return array
  */
 protected function parseCsv(StreamInterface $body)
 {
     if ($body->isSeekable()) {
         $body->rewind();
     }
     $stream = $body->detach();
     $data = [];
     while (($row = fgetcsv($stream)) !== false) {
         $data[] = $row;
     }
     fclose($stream);
     return $data;
 }
开发者ID:jordiwes,项目名称:psr7-middlewares,代码行数:20,代码来源:Payload.php

示例7: testDetaches

 public function testDetaches()
 {
     $this->b->detach();
     $this->assertFalse($this->b->isReadable());
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:5,代码来源:StreamDecoratorTraitTest.php


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