選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

HtmlResponseFormatter.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\web;
  8. use yii\base\Component;
  9. /**
  10. * HtmlResponseFormatter formats the given data into an HTML response content.
  11. *
  12. * It is used by [[Response]] to format response data.
  13. *
  14. * @author Qiang Xue <qiang.xue@gmail.com>
  15. * @since 2.0
  16. */
  17. class HtmlResponseFormatter extends Component implements ResponseFormatterInterface
  18. {
  19. /**
  20. * @var string the Content-Type header for the response
  21. */
  22. public $contentType = 'text/html';
  23. /**
  24. * Formats the specified response.
  25. * @param Response $response the response to be formatted.
  26. */
  27. public function format($response)
  28. {
  29. if (stripos($this->contentType, 'charset') === false) {
  30. $this->contentType .= '; charset=' . $response->charset;
  31. }
  32. $response->getHeaders()->set('Content-Type', $this->contentType);
  33. if ($response->data !== null) {
  34. $response->content = $response->data;
  35. }
  36. }
  37. }