本文整理汇总了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;
}
示例2: testGetMetadata
public function testGetMetadata()
{
$this->assertTrue(is_array($this->stream->getMetadata()));
$this->assertNull($this->stream->getMetadata('unknown.........'));
}
示例3: getMetadata
/**
* {@inheritdoc}
*/
public function getMetadata($key = null)
{
return $this->stream->getMetadata($key);
}
示例4: getMetadata
/**
* {@inheritdoc}
*/
public function getMetadata($key = null)
{
return $this->decoratedStream->getMetadata($key);
}
示例5: testWrapsMetadata
public function testWrapsMetadata()
{
$this->assertSame($this->b->getMetadata(), $this->a->getMetadata());
$this->assertSame($this->b->getMetadata('uri'), $this->a->getMetadata('uri'));
}