當前位置: 首頁>>代碼示例>>PHP>>正文


PHP StreamInterface::getMetadata方法代碼示例

本文整理匯總了PHP中Psr\Http\Message\StreamInterface::getMetadata方法的典型用法代碼示例。如果您正苦於以下問題:PHP StreamInterface::getMetadata方法的具體用法?PHP StreamInterface::getMetadata怎麽用?PHP StreamInterface::getMetadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Psr\Http\Message\StreamInterface的用法示例。


在下文中一共展示了StreamInterface::getMetadata方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: addAttachment

 /**
  * Function always use provided $filename. In cases when it's empty, for string content or when name cannot be
  * automatically discovered the $filename will be set to attachment name.
  * If attachment name is not provided, it will be randomly generated.
  * @param resource|string|StreamInterface $content  StreamInterface/resource/string to send
  * @param string                          $filename Optional. Filename of attachment, can't be empty if content is string
  * @param array                           $headers  Optional. Associative array of custom headers
  * @param string                          $name     Optional. Form field name
  * @return $this
  */
 public function addAttachment($content, $filename = '', array $headers = array(), $name = '')
 {
     $uri = null;
     if (!empty($filename)) {
         $uri = $filename;
     } elseif ($content instanceof StreamInterface) {
         $meta = $content->getMetadata('uri');
         if (substr($meta, 0, 6) !== 'php://') {
             $uri = $meta;
         }
     } elseif (is_resource($content)) {
         $meta = stream_get_meta_data($content);
         $uri = $meta['uri'];
     }
     $basename = basename($uri);
     if (empty($basename)) {
         throw new \InvalidArgumentException('File name was not provided and cannot be auto-discovered');
     }
     $name = !empty($name) ? $name : $basename;
     $element = array('contents' => $content, 'name' => $name);
     // always set as defined or else it will be auto-discovered by Guzzle
     if (!empty($filename)) {
         $element['filename'] = $filename;
     }
     if (!empty($headers)) {
         $element['headers'] = $headers;
     }
     $contentKey = null;
     foreach ($headers as $k => $v) {
         if (strtolower($k) == 'content-type') {
             $contentKey = $k;
         }
     }
     if (empty($contentKey)) {
         if (is_string($content)) {
             // Automatically set
             $element['headers']['Content-Type'] = 'application/octet-stream';
         } elseif ($content instanceof StreamInterface) {
             $type = \GuzzleHttp\Psr7\mimetype_from_filename($basename);
             if (!$type) {
                 throw new \InvalidArgumentException('Content-Type header was not provided and cannot be auto-discovered');
             }
         }
     }
     $this->elements[] = $element;
     return $this;
 }
開發者ID:RingCentralVuk,項目名稱:ringcentral-php,代碼行數:57,代碼來源:MultipartBuilder.php

示例2: testGetMetadata

 public function testGetMetadata()
 {
     $this->assertTrue(is_array($this->stream->getMetadata()));
     $this->assertNull($this->stream->getMetadata('unknown.........'));
 }
開發者ID:Golpha,項目名稱:Http,代碼行數:5,代碼來源:StreamTestTrait.php

示例3: getMetadata

 /**
  * {@inheritdoc}
  */
 public function getMetadata($key = null)
 {
     return $this->stream->getMetadata($key);
 }
開發者ID:narrowspark,項目名稱:framework,代碼行數:7,代碼來源:AbstractStreamDecorator.php

示例4: getMetadata

 /**
  * {@inheritdoc}
  */
 public function getMetadata($key = null)
 {
     return $this->decoratedStream->getMetadata($key);
 }
開發者ID:zendframework,項目名稱:zend-diactoros,代碼行數:7,代碼來源:RelativeStream.php

示例5: testWrapsMetadata

 public function testWrapsMetadata()
 {
     $this->assertSame($this->b->getMetadata(), $this->a->getMetadata());
     $this->assertSame($this->b->getMetadata('uri'), $this->a->getMetadata('uri'));
 }
開發者ID:nystudio107,項目名稱:instantanalytics,代碼行數:5,代碼來源:StreamDecoratorTraitTest.php


注:本文中的Psr\Http\Message\StreamInterface::getMetadata方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。