Overview

Namespaces

  • Peach
    • DF
    • DT
    • Http
      • Body
      • Header
    • Markup
    • Util

Classes

  • Peach\DF\Base64Codec
  • Peach\DF\CodecChain
  • Peach\DF\JsonCodec
  • Peach\DF\SerializationCodec
  • Peach\DF\Utf8Codec
  • Peach\DT\AbstractTime
  • Peach\DT\Clock
  • Peach\DT\Date
  • Peach\DT\Datetime
  • Peach\DT\DefaultClock
  • Peach\DT\FixedClock
  • Peach\DT\FormatWrapper
  • Peach\DT\HttpDateFormat
  • Peach\DT\OffsetClock
  • Peach\DT\ShiftFormat
  • Peach\DT\SimpleFormat
  • Peach\DT\TimeEquator
  • Peach\DT\Timestamp
  • Peach\DT\TimeWrapper
  • Peach\DT\UnixTimeFormat
  • Peach\DT\Util
  • Peach\DT\W3cDatetimeFormat
  • Peach\Http\Body
  • Peach\Http\Body\CodecRenderer
  • Peach\Http\Body\StringRenderer
  • Peach\Http\DefaultEndpoint
  • Peach\Http\Header\CookieItem
  • Peach\Http\Header\CookieOptions
  • Peach\Http\Header\HttpDate
  • Peach\Http\Header\NoField
  • Peach\Http\Header\QualityValues
  • Peach\Http\Header\Raw
  • Peach\Http\Header\SetCookie
  • Peach\Http\Header\Status
  • Peach\Http\Request
  • Peach\Http\Response
  • Peach\Http\Util
  • Peach\Markup\AbstractHelper
  • Peach\Markup\AbstractRenderer
  • Peach\Markup\BaseHelper
  • Peach\Markup\BreakControlWrapper
  • Peach\Markup\Builder
  • Peach\Markup\Code
  • Peach\Markup\Comment
  • Peach\Markup\ContainerElement
  • Peach\Markup\Context
  • Peach\Markup\DebugBuilder
  • Peach\Markup\DebugContext
  • Peach\Markup\DefaultBreakControl
  • Peach\Markup\DefaultBuilder
  • Peach\Markup\DefaultContext
  • Peach\Markup\Element
  • Peach\Markup\EmptyElement
  • Peach\Markup\HelperObject
  • Peach\Markup\HtmlHelper
  • Peach\Markup\Indent
  • Peach\Markup\MinimalBreakControl
  • Peach\Markup\NameBreakControl
  • Peach\Markup\NameValidator
  • Peach\Markup\NodeList
  • Peach\Markup\None
  • Peach\Markup\SgmlRenderer
  • Peach\Markup\Text
  • Peach\Markup\XmlRenderer
  • Peach\Util\AbstractMapEntry
  • Peach\Util\ArrayMap
  • Peach\Util\ArrayMapEntry
  • Peach\Util\Arrays
  • Peach\Util\DefaultComparator
  • Peach\Util\DefaultEquator
  • Peach\Util\HashMap
  • Peach\Util\HashMapEntry
  • Peach\Util\Strings
  • Peach\Util\Values

Interfaces

  • Peach\DF\Codec
  • Peach\DT\Format
  • Peach\DT\Time
  • Peach\Http\BodyRenderer
  • Peach\Http\Endpoint
  • Peach\Http\HeaderField
  • Peach\Http\MultiHeaderField
  • Peach\Http\SingleHeaderField
  • Peach\Markup\BreakControl
  • Peach\Markup\Component
  • Peach\Markup\Container
  • Peach\Markup\Helper
  • Peach\Markup\Node
  • Peach\Markup\Renderer
  • Peach\Util\Comparable
  • Peach\Util\Comparator
  • Peach\Util\Equator
  • Peach\Util\Map
  • Peach\Util\MapEntry
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /*
  4:  * Copyright (c) 2015 @trashtoy
  5:  * https://github.com/trashtoy/
  6:  * 
  7:  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8:  * this software and associated documentation files (the "Software"), to deal in
  9:  * the Software without restriction, including without limitation the rights to use,
 10:  * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
 11:  * Software, and to permit persons to whom the Software is furnished to do so,
 12:  * subject to the following conditions:
 13:  * 
 14:  * The above copyright notice and this permission notice shall be included in all
 15:  * copies or substantial portions of the Software.
 16:  * 
 17:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 19:  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 20:  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 21:  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 22:  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23:  */
 24: /**
 25:  * PHP class file.
 26:  * @auhtor trashtoy
 27:  * @since  2.2.0
 28:  */
 29: namespace Peach\Http;
 30: 
 31: use Peach\Http\Header\NoField;
 32: use Peach\Http\Header\Status;
 33: use Peach\Util\ArrayMap;
 34: 
 35: /**
 36:  * HTTP レスポンスをあらわすクラスです.
 37:  */
 38: class Response
 39: {
 40:     /**
 41:      * HeaderField 型オブジェクトを格納する ArrayMap です.
 42:      * @var ArrayMap
 43:      */
 44:     private $headerList;
 45:     
 46:     /**
 47:      * HTTP レスポンスのメッセージボディ部分を表す Body オブジェクトです.
 48:      * @var Body
 49:      */
 50:     private $body;
 51:     
 52:     /**
 53:      * 空の Response インスタンスを構築します.
 54:      * 
 55:      * @codeCoverageIgnore
 56:      */
 57:     public function __construct()
 58:     {
 59:         $this->headerList = new ArrayMap();
 60:         $this->body       = null;
 61:     }
 62:     
 63:     /**
 64:      * 指定された名前のヘッダーを取得します.
 65:      * 存在しない場合は null を返します.
 66:      * 
 67:      * @param  string $name ヘッダー名
 68:      * @return HeaderField   指定されたヘッダーに該当する HeaderField オブジェクト
 69:      */
 70:     public function getHeader($name)
 71:     {
 72:         $header = $this->headerList->get(strtolower($name));
 73:         return ($header instanceof HeaderField) ? $header : NoField::getInstance();
 74:     }
 75:     
 76:     /**
 77:      * この Response が持つヘッダーの一覧を取得します.
 78:      * 返り値の配列に対する操作はこのオブジェクトに影響しません.
 79:      * 
 80:      * @return HeaderField[] この Response にセットされている HeaderField の一覧
 81:      */
 82:     public function getHeaderList()
 83:     {
 84:         return $this->headerList->asArray();
 85:     }
 86:     
 87:     /**
 88:      * 指定されたヘッダーをこの Response に設定します.
 89:      * 
 90:      * @param HeaderField $item
 91:      */
 92:     public function setHeader(HeaderField $item)
 93:     {
 94:         $name = strtolower($item->getName());
 95:         $this->headerList->put($name, $item);
 96:     }
 97:     
 98:     /**
 99:      * 指定された名前の HeaderField が存在するかどうか調べます.
100:      * @param  string $name ヘッダー名
101:      * @return bool         指定された名前の HeaderField が存在する場合のみ true
102:      */
103:     public function hasHeader($name)
104:     {
105:         return $this->headerList->containsKey(strtolower($name));
106:     }
107:     
108:     /**
109:      * この Response が malformed (奇形) かどうかを判断します.
110:      * 
111:      * @todo 実装する
112:      * @return bool このオブジェクトが表現する Response が malformed (奇形) と判定される場合に true, それ以外は false
113:      */
114:     public function isMalformed()
115:     {
116:         if (!$this->validateStatusHeader()) {
117:             return true;
118:         }
119:         
120:         return false;
121:     }
122:     
123:     /**
124:      * この Response の :status 擬似ヘッダーが適切かどうかを調べます.
125:      * 
126:      * @return bool
127:      */
128:     private function validateStatusHeader()
129:     {
130:         if (!$this->hasHeader(":status")) {
131:             return false;
132:         }
133:         $status = $this->getHeader(":status");
134:         return ($status instanceof Status);
135:     }
136:     
137:     /**
138:      * 指定された Body オブジェクトをセットします.
139:      * @param Body $body
140:      */
141:     public function setBody(Body $body)
142:     {
143:         $this->body = $body;
144:     }
145:     
146:     /**
147:      * このオブジェクトにセットされている Body オブジェクトを返します.
148:      * セットされていない場合は null を返します.
149:      * 
150:      * @return Body
151:      */
152:     public function getBody()
153:     {
154:         return $this->body;
155:     }
156: }
157: 
PEACH2 API documentation generated by ApiGen