Overview

Namespaces

  • Kotchasan
    • Cache
    • Database
    • Http
    • Log
    • Orm
  • None
  • PHP
  • Psr
    • Cache
    • Http
      • Message
    • Log

Classes

  • AbstractMessage
  • AbstractRequest
  • Message
  • NotFound
  • Request
  • Response
  • Stream
  • UploadedFile
  • Uri
  • Overview
  • Namespace
  • Class
  • Tree

Class Request

คลาสสำหรับจัดการตัวแปรต่างๆจาก Server

Kotchasan\Http\AbstractMessage implements Psr\Http\Message\MessageInterface
Extended by Kotchasan\Http\AbstractRequest implements Psr\Http\Message\RequestInterface
Extended by Kotchasan\Http\Request implements Psr\Http\Message\RequestInterface
Namespace: Kotchasan\Http
Author: Goragod Wiriya admin@goragod.com
Since: 1.0
Located at Kotchasan/Http/Request.php
Methods summary
public Kotchasan\InputItem|Kotchasan\Inputs
# cookie( string $name, mixed $default = '' )

อ่านค่าจากตัวแปร COOKIE คืนค่า InputItem หรือ Collection ของ InputItem.

อ่านค่าจากตัวแปร COOKIE คืนค่า InputItem หรือ Collection ของ InputItem.

Parameters

$name
ชื่อตัวแปร
$default
ค่าเริ่มต้นหากไม่พบตัวแปร

Returns

Kotchasan\InputItem|Kotchasan\Inputs
public string
# createToken( )

ฟังก์ชั่นสร้าง token

ฟังก์ชั่นสร้าง token

Returns

string
public Kotchasan\InputItem|Kotchasan\Inputs
# get( string $name, mixed $default = null )

อ่านค่าจากตัวแปร GET คืนค่า InputItem หรือ Collection ของ InputItem

อ่านค่าจากตัวแปร GET คืนค่า InputItem หรือ Collection ของ InputItem

Parameters

$name
ชื่อตัวแปร
$default
ค่าเริ่มต้นหากไม่พบตัวแปร

Returns

Kotchasan\InputItem|Kotchasan\Inputs
public array
# getAcceptableLanguages( )

คืนค่ารายการภาษาที่รองรับ จาก HTTP header

คืนค่ารายการภาษาที่รองรับ จาก HTTP header

Returns

array
public mixed
# getAttribute( string $name, mixed $default = null )

อ่านค่า attributes ที่ต้องการ

อ่านค่า attributes ที่ต้องการ

Parameters

$name
ชื่อของ attributes
$default
คืนค่า $default ถ้าไม่พบ

Returns

mixed
public array
# getAttributes( )

คืนค่า attributes ทั้งหมด

คืนค่า attributes ทั้งหมด

Returns

array
public string|null
# getClientIp( )

ฟังก์ชั่น อ่าน ip ของ client คืนค่า IP ที่อ่านได้

ฟังก์ชั่น อ่าน ip ของ client คืนค่า IP ที่อ่านได้

Returns

string|null
public array
# getCookieParams( )

คืนค่าจากตัวแปร $_COOKIE

คืนค่าจากตัวแปร $_COOKIE

Returns

array
public null|array|object
# getParsedBody( )

คืนค่าจากตัวแปร $_POST

คืนค่าจากตัวแปร $_POST

Returns

null|array|object
public null|array|object
# getQueryParams( )

คืนค่าจากตัวแปร $_GET

คืนค่าจากตัวแปร $_GET

Returns

null|array|object
public array
# getServerParams( )

คืนค่าจากตัวแปร $_SERVER

คืนค่าจากตัวแปร $_SERVER

Returns

array
public Kotchasan\Files
# getUploadedFiles( )

คืนค่าไฟล์อัปโหลด FILES

คืนค่าไฟล์อัปโหลด FILES

Returns

Kotchasan\Files
public Kotchasan\InputItem|Kotchasan\Inputs
# globals( array $keys, string $name, mixed $default = null )

อ่านค่าจากตัวแปร GLOBALS เช่น $_POST $_GET $_SESSION $_COOKIE ตามที่ระบุใน $keys ตามลำดับ เช่น array('POST', 'GET') หมายถึงอ่านจาก $_POST ก่อน ถ้าไม่พบจะอ่านจาก $_GET และถ้าไม่พบอีกจะคืนค่า $default

อ่านค่าจากตัวแปร GLOBALS เช่น $_POST $_GET $_SESSION $_COOKIE ตามที่ระบุใน $keys ตามลำดับ เช่น array('POST', 'GET') หมายถึงอ่านจาก $_POST ก่อน ถ้าไม่พบจะอ่านจาก $_GET และถ้าไม่พบอีกจะคืนค่า $default

Parameters

$keys
ชื่อตัวแปรที่ต้องการอ่าน ตัวพิมพ์ใหญ่ เช่น array('POST', 'GET')
$name
ชื่อตัวแปร
$default
ค่าเริ่มต้นหากไม่พบตัวแปร

Returns

Kotchasan\InputItem|Kotchasan\Inputs
public boolean
# initSession( )

ฟังก์ชั่นเริ่มต้นใช้งาน session

ฟังก์ชั่นเริ่มต้นใช้งาน session

Returns

boolean
public boolean
# isAjax( )

ตรวจสอบว่าเรียกมาโดย Ajax หรือไม่ คืนค่า true ถ้าเรียกมาจาก Ajax (XMLHttpRequest).

ตรวจสอบว่าเรียกมาโดย Ajax หรือไม่ คืนค่า true ถ้าเรียกมาจาก Ajax (XMLHttpRequest).

Returns

boolean
public boolean
# isReferer( )

ฟังก์ชั่น ตรวจสอบ referer คืนค่า true ถ้า referer มาจากเว็บไซต์นี้

ฟังก์ชั่น ตรวจสอบ referer คืนค่า true ถ้า referer มาจากเว็บไซต์นี้

Returns

boolean
public boolean
# isSafe( )

ฟังก์ชั่น ตรวจสอบ token ที่มาจากฟอร์ม และ ตรวจสอบ Referer ด้วย รับค่าที่มาจาก $_POST เท่านั้น ฟังก์ชั่นนี้ต้องเรียกต่อจาก initSession() เสมอ อายุของ token กำหนดที่ TOKEN_LIMIT คืนค่า true ถ้า token ถูกต้องและไม่หมดอายุ

ฟังก์ชั่น ตรวจสอบ token ที่มาจากฟอร์ม และ ตรวจสอบ Referer ด้วย รับค่าที่มาจาก $_POST เท่านั้น ฟังก์ชั่นนี้ต้องเรียกต่อจาก initSession() เสมอ อายุของ token กำหนดที่ TOKEN_LIMIT คืนค่า true ถ้า token ถูกต้องและไม่หมดอายุ

Returns

boolean
public Kotchasan\InputItem|Kotchasan\Inputs
# post( string $name, mixed $default = null )

อ่านค่าจากตัวแปร $_POST ถ้าไม่พบเลยคืนค่า $default คืนค่า InputItem หรือ แอเรย์ของ InputItem

อ่านค่าจากตัวแปร $_POST ถ้าไม่พบเลยคืนค่า $default คืนค่า InputItem หรือ แอเรย์ของ InputItem

Parameters

$name
ชื่อตัวแปร
$default
ค่าเริ่มต้นหากไม่พบตัวแปร

Returns

Kotchasan\InputItem|Kotchasan\Inputs
public
# removeToken( )

ลบ token

ลบ token

public Kotchasan\InputItem|Kotchasan\Inputs
# request( string $name, mixed $default = null, mixed $cookie = false )

อ่านค่าจากตัวแปร $_POST $_GET $_COOKIE(options) ตามลำดับ คืนค่ารายการแรกที่พบ ถ้าไม่พบเลยคืนค่า $default คืนค่า InputItem หรือ แอเรย์ของ InputItem

อ่านค่าจากตัวแปร $_POST $_GET $_COOKIE(options) ตามลำดับ คืนค่ารายการแรกที่พบ ถ้าไม่พบเลยคืนค่า $default คืนค่า InputItem หรือ แอเรย์ของ InputItem

Parameters

$name
ชื่อตัวแปร
$default
ค่าเริ่มต้นหากไม่พบตัวแปร
$cookie
false (default) ไม่อ่านจาก cookie, true อ่านจาก cookie ด้วย

Returns

Kotchasan\InputItem|Kotchasan\Inputs
public mixed
# server( string $name, mixed $default = null )

อ่านค่าจากตัวแปร $_SERVER ถ้าไม่พบเลยคืนค่า $default

อ่านค่าจากตัวแปร $_SERVER ถ้าไม่พบเลยคืนค่า $default

Parameters

$name
ชื่อตัวแปร
$default
ค่าเริ่มต้นหากไม่พบตัวแปร

Returns

mixed
public Kotchasan\InputItem|Kotchasan\Inputs
# session( string $name, mixed $default = null )

อ่านค่าจากตัวแปร $_SESSION ถ้าไม่พบเลยคืนค่า $default คืนค่า InputItem หรือ Collection ของ InputItem

อ่านค่าจากตัวแปร $_SESSION ถ้าไม่พบเลยคืนค่า $default คืนค่า InputItem หรือ Collection ของ InputItem

Parameters

$name
ชื่อตัวแปร
$default
ค่าเริ่มต้นหากไม่พบตัวแปร

Returns

Kotchasan\InputItem|Kotchasan\Inputs
public static
# setSession( string $name, mixed $value )

กำหนดค่าตัวแปร $_SESSION

กำหนดค่าตัวแปร $_SESSION

Parameters

$name
ชื่อตัวแปร
$value
ค่าของตัวแปร

Returns

static
public static
# withAttribute( string $name, mixed $value )

กำหนดค่า attributes

กำหนดค่า attributes

Parameters

$name
ชื่อของ attributes
$value
ค่าของ attribute

Returns

static
public static
# withCookieParams( array $cookies )

กำหนดค่า cookieParams

กำหนดค่า cookieParams

Parameters

$cookies

Returns

static
public static
# withParsedBody( mixed $data )

กำหนดค่า parsedBody

กำหนดค่า parsedBody

Parameters

$data

Returns

static
public static
# withQueryParams( array $query )

กำหนดค่า queryParams

กำหนดค่า queryParams

Parameters

$query

Returns

static
public static
# withUploadedFiles( array $uploadedFiles )

กำหนดค่า uploadedFiles

กำหนดค่า uploadedFiles

Parameters

$uploadedFiles

Returns

static
public static
# withoutAttribute( string|array $names )

ลบ attributes

ลบ attributes

Parameters

$names
ชื่อของ attributes ที่ต้องการลบ

Returns

static
public static array
# filterRequestKey( array $source )

key ของ Input ต่างๆเป็น ตัวเลข ภาษาอังกฤษ และ [ ] _ - เท่านั้น

key ของ Input ต่างๆเป็น ตัวเลข ภาษาอังกฤษ และ [ ] _ - เท่านั้น

Parameters

$source

Returns

array
Methods inherited from Kotchasan\Http\AbstractRequest
createUriWithGet(), createUriWithGlobals(), createUriWithPost(), getMethod(), getRequestTarget(), getUri(), map(), withMethod(), withRequestTarget(), withUri()
Methods inherited from Kotchasan\Http\AbstractMessage
__construct(), filterHeader(), getBody(), getHeader(), getHeaderLine(), getHeaders(), getProtocolVersion(), getRequestHeaders(), hasHeader(), withAddedHeader(), withBody(), withHeader(), withHeaders(), withProtocolVersion(), withoutHeader()
Properties inherited from Kotchasan\Http\AbstractRequest
$method, $requestTarget, $uri
Properties inherited from Kotchasan\Http\AbstractMessage
$headers, $protocol, $stream
Kotchasan API documentation generated by ApiGen