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


PHP Message\StreamInterface类代码示例

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


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

示例1: send

 public function send(StreamInterface $stream)
 {
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     $stream->write($this->contents);
 }
开发者ID:koolkode,项目名称:http,代码行数:7,代码来源:StringEntity.php

示例2: writeText

    public function writeText(StreamInterface $stream)
    {
        $text = $this->text;
        $menu = $this->menu;
        $token = $this->requestToken;
        $stream->write(<<<HTML
            <form method="post" action="{$text->e($text->getUrlPage("rename_menu", $menu->getId()))}">
                <p>
                    {$text->t("main.fields_required")}
                </p>
                <p>
                    <label for="menu_name">
                        {$text->t("links.menu.name")}: <span class="required">*</span>
                    </label> <br />
                    <input type="text" name="menu_name" id="menu_name" value="{$text->e($menu->getName())}" size="20"
                            maxlength="{$text->e(MenuRepository::NAME_MAX_LENGTH)}" />
                </p>
                <p>
                    <input type="hidden" name="{$text->e(RequestToken::FIELD_NAME)}" value="{$text->e($token->getTokenString())}" />
                    <input class="button primary_button" type="submit" value="{$text->t("editor.save")}" />
                    <a class="button" href="{$text->e($text->getUrlPage("edit_menu", $menu->getId()))}">
                        {$text->t("main.cancel")}
                    </a>
                </p>
            </form>
HTML
);
    }
开发者ID:rutgerkok,项目名称:rCMS,代码行数:28,代码来源:MenuRenameTemplate.php

示例3: writeText

    public function writeText(StreamInterface $stream)
    {
        $text = $this->text;
        $stream->write(<<<HTML
            <p>
                {$text->t("main.fields_required")}
            </p>
            <form method="post" action="{$text->url("edit_category", $this->category->getId())}">
                <p>
                    <label for="category_name">{$text->t("categories.name")}:</label>
                    <span class="required">*</span>
                    <br />
                    <input type="text" id="category_name" name="category_name"
                        maxlength="{$text->e(CategoryRepository::NAME_MAX_LENGTH)}"
                        value="{$text->e($this->category->getName())}" />
                </p>
                <p>
                    <label for="category_description">{$text->t("categories.description")}:</label>
                    <br />
                    {$this->richEditor->getEditor("category_description", $this->category->getDescriptionHtml())}
                </p>
                <p>
                    <input type="hidden" name="{$text->e(RequestToken::FIELD_NAME)}"
                        value="{$text->e($this->requestToken->getTokenString())}" />
                    <input type="submit" class="button primary_button" value="{$text->t("editor.save")}" />
                    <a class="button" href="{$text->url("category_list")}">
                        {$text->t("main.cancel")}
                    </a>
                </p>
            </form>
HTML
);
    }
开发者ID:rutgerkok,项目名称:rCMS,代码行数:33,代码来源:CategoryEditTemplate.php

示例4: send

 public function send(StreamInterface $stream)
 {
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     if (is_array($this->callback)) {
         $ref = (new \ReflectionClass(is_object($this->callback[0]) ? get_class($this->callback[0]) : $this->callback[0]))->getMethod($this->callback[1]);
     } elseif (is_object($this->callback) && !$this->callback instanceof \Closure) {
         $ref = new \ReflectionMethod(get_class($this->callback), '__invoke');
     } else {
         $ref = new \ReflectionFunction($this->callback);
     }
     if ($ref->isGenerator()) {
         foreach (call_user_func($this->callback) as $chunk) {
             $stream->write($chunk);
         }
         return;
     }
     foreach ($ref->getParameters() as $param) {
         if (NULL !== ($type = $param->getClass())) {
             if ($type->name === StreamInterface::class || $type->implementsInterface(StreamInterface::class)) {
                 call_user_func($this->callback, $stream);
                 return;
             }
         }
         break;
     }
     $stream->write((string) call_user_func($this->callback));
 }
开发者ID:koolkode,项目名称:http,代码行数:29,代码来源:CallbackEntity.php

示例5: getLine

 /**
  * Retrieve a single line from the stream.
  *
  * Retrieves a line from the stream; a line is defined as a sequence of
  * characters ending in a CRLF sequence.
  *
  * @param StreamInterface $stream
  * @return string
  * @throws UnexpectedValueException if the sequence contains a CR or LF in
  *     isolation, or ends in a CR.
  */
 protected static function getLine(StreamInterface $stream)
 {
     $line = '';
     $crFound = false;
     while (!$stream->eof()) {
         $char = $stream->read(1);
         if ($crFound && $char === self::LF) {
             $crFound = false;
             break;
         }
         // CR NOT followed by LF
         if ($crFound && $char !== self::LF) {
             throw new UnexpectedValueException('Unexpected carriage return detected');
         }
         // LF in isolation
         if (!$crFound && $char === self::LF) {
             throw new UnexpectedValueException('Unexpected line feed detected');
         }
         // CR found; do not append
         if ($char === self::CR) {
             $crFound = true;
             continue;
         }
         // Any other character: append
         $line .= $char;
     }
     // CR found at end of stream
     if ($crFound) {
         throw new UnexpectedValueException("Unexpected end of headers");
     }
     return $line;
 }
开发者ID:deepfreeze,项目名称:zend-diactoros,代码行数:43,代码来源:AbstractSerializer.php

示例6: writeText

    public function writeText(StreamInterface $stream)
    {
        $text = $this->text;
        foreach ($this->themeInfos as $themeInfo) {
            $stream->write(<<<HTML
                <h3>{$text->e($themeInfo->getDisplayName())}</h3>
                <p>
                    {$text->e($themeInfo->getDescription())}
                    {$text->tReplaced("themes.created_by", '<a href="' . $text->e($themeInfo->getAuthorWebsite()) . '">' . $text->e($themeInfo->getAuthor()) . '</a>')}.
                    <a href="{$text->e($themeInfo->getThemeWebsite())}" class="arrow">{$this->text->t("themes.view_more_information")}</a>
                </p>
                <p>
                    <form method="post" action="{$text->url("switch_theme")}">
                        <input type="hidden" name="theme" value="{$text->e($themeInfo->getDirectoryName())}" />
                        <input type="hidden" name="{$text->e(RequestToken::FIELD_NAME)}" value="{$text->e($this->requestToken->getTokenString())}" />
                        <input type="submit" class="button" value="{$text->t("themes.switch_to_this")}" />
                    </form>
                    </a>
                </p>
HTML
);
        }
        $stream->write(<<<HTML
            <p>
                <a class="arrow" href="{$text->url("admin")}">{$text->t("main.admin")}</a>         
            </p>
HTML
);
    }
开发者ID:rutgerkok,项目名称:rCMS,代码行数:29,代码来源:ThemeSwitchTemplate.php

示例7: requiresMultipart

 /**
  * Determines if the body should be uploaded using PutObject or the
  * Multipart Upload System. It also modifies the passed-in $body as needed
  * to support the upload.
  *
  * @param StreamInterface $body      Stream representing the body.
  * @param integer             $threshold Minimum bytes before using Multipart.
  *
  * @return bool
  */
 private function requiresMultipart(StreamInterface &$body, $threshold)
 {
     // If body size known, compare to threshold to determine if Multipart.
     if ($body->getSize() !== null) {
         return $body->getSize() >= $threshold;
     }
     /**
      * Handle the situation where the body size is unknown.
      * Read up to 5MB into a buffer to determine how to upload the body.
      * @var StreamInterface $buffer
      */
     $buffer = Psr7\stream_for();
     Psr7\copy_to_stream($body, $buffer, MultipartUploader::PART_MIN_SIZE);
     // If body < 5MB, use PutObject with the buffer.
     if ($buffer->getSize() < MultipartUploader::PART_MIN_SIZE) {
         $buffer->seek(0);
         $body = $buffer;
         return false;
     }
     // If body >= 5 MB, then use multipart. [YES]
     if ($body->isSeekable()) {
         // If the body is seekable, just rewind the body.
         $body->seek(0);
     } else {
         // If the body is non-seekable, stitch the rewind the buffer and
         // the partially read body together into one stream. This avoids
         // unnecessary disc usage and does not require seeking on the
         // original stream.
         $buffer->seek(0);
         $body = new Psr7\AppendStream([$buffer, $body]);
     }
     return true;
 }
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:43,代码来源:ObjectUploader.php

示例8: appendStream

 /**
  * Append another input stream.
  * 
  * @param StreamInterface $stream
  * 
  * @throws \InvalidArgumentException When the given stream is not readable.
  */
 public function appendStream(StreamInterface $stream)
 {
     if (!$stream->isReadable()) {
         throw new \InvalidArgumentException('Appended input stream must be readable');
     }
     $this->streams[] = $stream;
 }
开发者ID:koolkode,项目名称:stream,代码行数:14,代码来源:AppendInputStream.php

示例9: fromGlobals

 /**
  * {@inheritdoc}
  *
  * @param StreamInterface $content
  *   (Optional) The content to override the input stream with. This is mainly
  *   here for testing purposes.
  *
  */
 public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null, StreamInterface $content = null)
 {
     $server = static::normalizeServer($server ?: $_SERVER);
     $files = static::normalizeFiles($files ?: $_FILES);
     $headers = static::marshalHeaders($server);
     // static::get() has a default parameter, however, if the header is set but
     // the value is NULL, e.g. during a drush operation, the NULL result is
     // returned, instead of the default.
     $method = strtoupper(static::get('REQUEST_METHOD', $server) ?: 'GET');
     $request = new JsonRequest($server, $files, static::marshalUriFromServer($server, $headers), $method, $content ?: 'php://input', $headers);
     $is_json = strpos(static::get('CONTENT_TYPE', $server), 'application/json') !== FALSE;
     $vars_in_body = in_array($method, ['PUT', 'POST', 'PATCH', 'DELETE']);
     if ($vars_in_body) {
         $data = $content ? $content->getContents() : file_get_contents('php://input');
         $body = $body ?: [];
         $new = [];
         if ($is_json) {
             $new = json_decode($data, TRUE);
         } else {
             parse_str($data, $new);
         }
         // Merge in data to $body.
         $body = array_merge($body, $new);
     }
     return $request->withCookieParams($cookies ?: $_COOKIE)->withQueryParams($query ?: $_GET)->withParsedBody($body ?: $_POST);
 }
开发者ID:krisolafson,项目名称:restapi,代码行数:34,代码来源:ServerRequestFactory.php

示例10: __construct

 /**
  * StreamRange constructor.
  * @param StreamInterface $stream
  * @param string $range
  * @throws
  */
 public function __construct(StreamInterface $stream, $range)
 {
     $range = trim($range);
     $length = $stream->getSize();
     if (preg_match('/^(\\d+)\\-$/', $range, $match)) {
         $this->firstPos = intval($match[1]);
         if ($this->firstPos > $length - 1) {
             throw new StreamRangeException('HTTP/1.1 416 Requested Range Not Satisfiable');
         }
         $this->lastPos = $length - 1;
     } elseif (preg_match('/^(\\d+)\\-(\\d+)$/', $range, $match)) {
         $this->firstPos = intval($match[1]);
         $this->lastPos = intval($match[2]);
         if ($this->lastPos < $this->firstPos || $this->lastPos > $length - 1) {
             throw new StreamRangeException('HTTP/1.1 416 Requested Range Not Satisfiable');
         }
     } elseif (preg_match('/^\\-(\\d+)$/', $range, $match)) {
         $suffixLength = intval($match[1]);
         if ($suffixLength === 0 || $suffixLength > $length) {
             throw new StreamRangeException('HTTP/1.1 416 Requested Range Not Satisfiable');
         }
         $this->firstPos = $length - $suffixLength;
         $this->lastPos = $length - 1;
     } else {
         throw new StreamRangeException('HTTP/1.1 416 Requested Range Not Satisfiable');
     }
 }
开发者ID:oat-sa,项目名称:tao-core,代码行数:33,代码来源:StreamRange.php

示例11: writeText

    public function writeText(StreamInterface $stream)
    {
        $text = $this->text;
        $editorHtml = $this->installedWidgets->getEditor($this->editWidget);
        $actionUrl = $text->getUrlPage("edit_widget", $this->editWidget->getId());
        $documentEditUrl = $text->getUrlPage("edit_document", $this->editWidget->getDocumentId());
        $tokenNameHtml = $text->e(RequestToken::FIELD_NAME);
        $tokenValueHtml = $text->e($this->requestToken->getTokenString());
        $stream->write(<<<EDITOR
            <p>{$this->text->t("main.fields_required")}</p>
            <form method="POST" action="{$text->e($actionUrl)}">
                {$editorHtml}

                <p>
                    <input type="hidden" name="{$tokenNameHtml}" value="{$tokenValueHtml}" />
                    <input type="hidden" name="document_id" value="{$this->editWidget->getDocumentId()}" />
                    <input type="hidden" name="directory_name" value="{$this->editWidget->getDirectoryName()}" />
                    <input class="button primary_button" 
                        type="submit" 
                        name="submit"
                        value="{$this->text->t("editor.save")}" />
                    <a class="button" href="{$text->e($documentEditUrl)}">
                        {$this->text->t("main.cancel")}
                    </a>
                </p>
            </form>
EDITOR
);
    }
开发者ID:rutgerkok,项目名称:rCMS,代码行数:29,代码来源:WidgetEditTemplate.php

示例12: writeText

 public function writeText(StreamInterface $stream)
 {
     if ($this->newUser === null) {
         $stream->write($this->getErrorText());
     } else {
         $stream->write($this->getSuccessText());
     }
 }
开发者ID:rutgerkok,项目名称:rCMS,代码行数:8,代码来源:LoggedInOtherTemplate.php

示例13: send

 public function send(StreamInterface $stream)
 {
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     while (!$this->stream->eof()) {
         $stream->write($this->stream->read(4096));
     }
 }
开发者ID:koolkode,项目名称:http,代码行数:9,代码来源:StreamEntity.php

示例14: writeText

 public function writeText(StreamInterface $stream)
 {
     // Link to manage widgets
     $stream->write($this->getWidgetsEditLinks());
     // Output widgets
     foreach ($this->placedWidgets as $widget) {
         $this->widgetLoader->writeOutput($stream, $widget);
     }
 }
开发者ID:rutgerkok,项目名称:rCMS,代码行数:9,代码来源:WidgetsColumnTemplate.php

示例15: body

 /**
  * @param StreamInterface $stream
  */
 protected function body($stream)
 {
     if ($stream instanceof Messages\Stream\Implementation) {
         $stream->rewind();
         $this->fpassthru($stream->resource());
     } else {
         $this->output((string) $stream);
     }
 }
开发者ID:phpixie,项目名称:http,代码行数:12,代码来源:Output.php


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