当前位置: 首页>>代码示例>>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;未经允许,请勿转载。