Phalcon http
注意
所有类都以前缀命名Phalcon
Http\Cookie¶
-
命名空间
Phalcon\Http
-
使用
Phalcon\Di\AbstractInjectionAware
Phalcon\Di\DiInterface
Phalcon\Encryption\Crypt\CryptInterface
Phalcon\Encryption\Crypt\Mismatch
Phalcon\Filter\FilterInterface
Phalcon\Http\Cookie\CookieInterface
Phalcon\Http\Cookie\Exception
Phalcon\Http\Response\Exception
Phalcon\Session\ManagerInterface
-
继承
AbstractInjectionAware
-
实现
CookieInterface
提供面向对象封装,用于管理 HTTP cookie。
属性¶
/**
* @var string
*/
protected $domain;
/**
* @var int
*/
protected $expire;
/**
* @var FilterInterface|null
*/
protected $filter;
/**
* @var bool
*/
protected $httpOnly;
/**
* @var string
*/
protected $name;
/**
* @var array
*/
protected $options;
/**
* @var string
*/
protected $path;
/**
* @var bool
*/
protected $read = false;
/**
* @var bool
*/
protected $restored = false;
/**
* @var bool
*/
protected $secure = true;
/**
* The cookie's sign key.
*
* @var string|null
*/
protected $signKey;
/**
* @var bool
*/
protected $useEncryption = false;
/**
* @var mixed|null
*/
protected $value;
方法¶
public function __construct( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = bool, string $domain = string, bool $httpOnly = bool, array $options = [] );
此方法会自动被内部调用,通常不需要手动调用它。
将 cookie 发送至 HTTP 客户端。将 cookie 定义存储到 session 中。
设置 cookie 所属的域名 设置 cookie 的过期时间 设置 cookie 是否只能通过 HTTP 协议访问 设置 cookie 的选项 设置 cookie 的路径 设置 cookie 是否仅在连接安全(HTTPS)时发送 设置 Cookie 的签名密钥`$signKey` 必须至少有 32 个字符,并且必须使用密码学安全伪随机生成器生成
使用 NULL 来禁用 Cookie 签名
@see \Phalcon\Security\Random @throws \Phalcon\Http\Cookie\Exception
设置 cookie 的值 设置 cookie 是否需要自动加密/解密 验证 cookie 的密钥是否足够长。@throws \Phalcon\Http\Cookie\Exception
Http\Cookie\CookieInterface
¶
-
命名空间
Phalcon\Http\Cookie
-
使用
-
继承
-
实现
Phalcon\Http\Cookie 的接口定义
方法¶
删除 cookie 返回 cookie 所属的域名 返回当前过期时间 返回 cookie 是否只能通过 HTTP 协议访问 返回当前 cookie 的名称 返回当前 cookie 的选项 返回当前 cookie 的路径 返回 cookie 是否仅在连接安全(HTTPS)时发送 返回 cookie 的值。 检查 cookie 是否使用了隐式加密 将 cookie 发送至 HTTP 客户端 设置 cookie 所属的域名 设置 cookie 的过期时间 设置 cookie 是否只能通过 HTTP 协议访问 设置 cookie 的选项 设置 cookie 的过期时间 设置 cookie 是否仅在连接安全(HTTPS)时发送 设置 cookie 的值 设置 cookie 是否需要自动加密/解密Http\Cookie\Exception¶
-
命名空间
Phalcon\Http\Cookie
-
使用
-
继承
\Exception
-
实现
Phalcon\Http\Cookie\Exception
Phalcon\Http\Cookie 中抛出的异常将使用此类。
Http\Message\RequestMethodInterface
¶
-
命名空间
Phalcon\Http\Message
-
使用
-
继承
-
实现
请求方法的接口定义
此文件的实现受 PHP FIG 影响 @link https://github.com/php-fig/http-message-util/ @license https://github.com/php-fig/http-message-util/blob/master/LICENSE
常量¶
const METHOD_CONNECT = CONNECT;
const METHOD_DELETE = DELETE;
const METHOD_GET = GET;
const METHOD_HEAD = HEAD;
const METHOD_OPTIONS = OPTIONS;
const METHOD_PATCH = PATCH;
const METHOD_POST = POST;
const METHOD_PURGE = PURGE;
const METHOD_PUT = PUT;
const METHOD_TRACE = TRACE;
Http\Message\ResponseStatusCodeInterface
¶
-
命名空间
Phalcon\Http\Message
-
使用
-
继承
-
实现
请求方法的接口定义
此文件的实现受 PHP FIG 影响 @link https://github.com/php-fig/http-message-util/ @license https://github.com/php-fig/http-message-util/blob/master/LICENSE
定义常见 HTTP 状态码的常量。
@see https://tools.ietf.org/html/rfc2295#section-8.1 @see https://tools.ietf.org/html/rfc2324#section-2.3 @see https://tools.ietf.org/html/rfc2518#section-9.7 @see https://tools.ietf.org/html/rfc2774#section-7 @see https://tools.ietf.org/html/rfc3229#section-10.4 @see https://tools.ietf.org/html/rfc4918#section-11 @see https://tools.ietf.org/html/rfc5842#section-7.1 @see https://tools.ietf.org/html/rfc5842#section-7.2 @see https://tools.ietf.org/html/rfc6585#section-3 @see https://tools.ietf.org/html/rfc6585#section-4 @see https://tools.ietf.org/html/rfc6585#section-5 @see https://tools.ietf.org/html/rfc6585#section-6 @see https://tools.ietf.org/html/rfc7231#section-6 @see https://tools.ietf.org/html/rfc7238#section-3 @see https://tools.ietf.org/html/rfc7725#section-3 @see https://tools.ietf.org/html/rfc7540#section-9.1.2 @see https://tools.ietf.org/html/rfc8297#section-2 @see https://tools.ietf.org/html/rfc8470#section-7
常量¶
const STATUS_ACCEPTED = 202;
const STATUS_ALREADY_REPORTED = 208;
const STATUS_BAD_GATEWAY = 502;
const STATUS_BAD_REQUEST = 400;
const STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509;
const STATUS_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS = 450;
const STATUS_CLIENT_CLOSED_REQUEST = 499;
const STATUS_CONFLICT = 409;
const STATUS_CONNECTION_TIMEOUT = 522;
const STATUS_CONTINUE = 100;
const STATUS_CREATED = 201;
const STATUS_EARLY_HINTS = 103;
const STATUS_EXPECTATION_FAILED = 417;
const STATUS_FAILED_DEPENDENCY = 424;
const STATUS_FORBIDDEN = 403;
const STATUS_FOUND = 302;
const STATUS_GATEWAY_TIMEOUT = 504;
const STATUS_GONE = 410;
const STATUS_HTTP_REQUEST_SENT_TO_HTTPS_PORT = 497;
const STATUS_IM_A_TEAPOT = 418;
const STATUS_IM_USED = 226;
const STATUS_INSUFFICIENT_STORAGE = 507;
const STATUS_INTERNAL_SERVER_ERROR = 500;
const STATUS_INVALID_SSL_CERTIFICATE = 526;
const STATUS_INVALID_TOKEN_ESRI = 498;
const STATUS_LENGTH_REQUIRED = 411;
const STATUS_LOCKED = 423;
const STATUS_LOGIN_TIMEOUT = 440;
const STATUS_LOOP_DETECTED = 508;
const STATUS_METHOD_FAILURE = 420;
const STATUS_METHOD_NOT_ALLOWED = 405;
const STATUS_MISDIRECTED_REQUEST = 421;
const STATUS_MOVED_PERMANENTLY = 301;
const STATUS_MULTIPLE_CHOICES = 300;
const STATUS_MULTI_STATUS = 207;
const STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511;
const STATUS_NETWORK_CONNECT_TIMEOUT_ERROR = 599;
const STATUS_NETWORK_READ_TIMEOUT_ERROR = 598;
const STATUS_NON_AUTHORITATIVE_INFORMATION = 203;
const STATUS_NOT_ACCEPTABLE = 406;
const STATUS_NOT_EXTENDED = 510;
const STATUS_NOT_FOUND = 404;
const STATUS_NOT_IMPLEMENTED = 501;
const STATUS_NOT_MODIFIED = 304;
const STATUS_NO_CONTENT = 204;
const STATUS_NO_RESPONSE = 444;
const STATUS_OK = 200;
const STATUS_ORIGIN_DNS_ERROR = 530;
const STATUS_ORIGIN_IS_UNREACHABLE = 523;
const STATUS_PAGE_EXPIRED = 419;
const STATUS_PARTIAL_CONTENT = 206;
const STATUS_PAYLOAD_TOO_LARGE = 413;
const STATUS_PAYMENT_REQUIRED = 402;
const STATUS_PERMANENT_REDIRECT = 308;
const STATUS_PRECONDITION_FAILED = 412;
const STATUS_PRECONDITION_REQUIRED = 428;
const STATUS_PROCESSING = 102;
const STATUS_PROXY_AUTHENTICATION_REQUIRED = 407;
const STATUS_RAILGUN_ERROR = 527;
const STATUS_RANGE_NOT_SATISFIABLE = 416;
const STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
const STATUS_REQUEST_HEADER_TOO_LARGE = 494;
const STATUS_REQUEST_TIMEOUT = 408;
const STATUS_RESERVED = 306;
const STATUS_RESET_CONTENT = 205;
const STATUS_RETRY_WITH = 449;
const STATUS_SEE_OTHER = 303;
const STATUS_SERVICE_UNAVAILABLE = 503;
const STATUS_SSL_CERTIFICATE_ERROR = 495;
const STATUS_SSL_CERTIFICATE_REQUIRED = 496;
const STATUS_SSL_HANDSHAKE_FAILED = 525;
const STATUS_SWITCHING_PROTOCOLS = 101;
const STATUS_TEMPORARY_REDIRECT = 307;
const STATUS_THIS_IS_FINE = 218;
const STATUS_TIMEOUT_OCCURRED = 524;
const STATUS_TOO_EARLY = 425;
const STATUS_TOO_MANY_REQUESTS = 429;
const STATUS_UNAUTHORIZED = 401;
const STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451;
const STATUS_UNKNOWN_ERROR = 520;
const STATUS_UNPROCESSABLE_ENTITY = 422;
const STATUS_UNSUPPORTED_MEDIA_TYPE = 415;
const STATUS_UPGRADE_REQUIRED = 426;
const STATUS_URI_TOO_LONG = 414;
const STATUS_USE_PROXY = 305;
const STATUS_VARIANT_ALSO_NEGOTIATES = 506;
const STATUS_VERSION_NOT_SUPPORTED = 505;
const STATUS_WEB_SERVER_IS_DOWN = 521;
Http\Request¶
-
命名空间
Phalcon\Http
-
使用
Phalcon\Di\AbstractInjectionAware
Phalcon\Di\DiInterface
Phalcon\Events\ManagerInterface
Phalcon\Filter\FilterInterface
Phalcon\Http\Message\RequestMethodInterface
Phalcon\Http\Request\Exception
Phalcon\Http\Request\File
Phalcon\Http\Request\FileInterface
Phalcon\Support\Helper\Json\Decode
UnexpectedValueException
stdClass
-
继承
AbstractInjectionAware
-
实现
RequestInterface
RequestMethodInterface
封装请求信息以便于应用程序控制器进行简单和安全的访问。
请求对象是一个简单的值对象,在调度器和控制器类之间传递。它打包了 HTTP 请求环境。
use Phalcon\Http\Request;
$request = new Request();
if ($request->isPost() && $request->isAjax()) {
echo "Request was made using POST and AJAX";
}
// Retrieve SERVER variables
$request->getServer("HTTP_HOST");
// GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH, PURGE, TRACE, CONNECT
$request->getMethod();
// An array of languages the client accepts
$request->getLanguages();
属性¶
/**
* @var FilterInterface|null
*/
private $filterService;
/**
* @var bool
*/
private $httpMethodParameterOverride = false;
/**
* @var array
*/
private $queryFilters;
/**
* @var array|null
*/
private $patchCache;
/**
* @var array|null
*/
private $putCache;
/**
* @var string
*/
private $rawBody = ;
/**
* @var bool
*/
private $strictHostCheck = false;
方法¶
public function get( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from $_REQUEST["user_email"] without sanitizing
$userEmail = $request->get("user_email");
// Returns value from $_REQUEST["user_email"] with sanitizing
$userEmail = $request->get("user_email", "email");
$_SERVER["REMOTE_ADDR"]
以及可选地在$_SERVER["HTTP_X_FORWARDED_FOR"]
从_SERVER["HTTP_ACCEPT_CHARSET"]获取浏览器/客户端接受的字符集及其质量值组成的数组。 获取请求的内容类型 从$_SERVER["PHP_AUTH_DIGEST"]获取浏览器/客户端接受的身份验证信息。 public function getFilteredData( string $methodKey, string $method, string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
public function getFilteredPatch( string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
public function getFilteredPost( string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
public function getFilteredPut( string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
public function getFilteredQuery( string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
$_SERVER = [ "PHP_AUTH_USER" => "phalcon", "PHP_AUTH_PW" => "secret", ];
$headers = $request->getHeaders();
echo $headers["Authorization"]; // Basic cGhhbGNvbjpzZWNyZXQ=
Request::getHttpHost
按照以下顺序尝试查找主机名:
$_SERVER["HTTP_HOST"]
$_SERVER["SERVER_NAME"]
$_SERVER["SERVER_ADDR"]
可选地Request::getHttpHost
验证并清理主机名。Request::$strictHostCheck
可用于验证主机名。
注意:验证和清理会对性能产生负面影响,因为它们使用了正则表达式。
use Phalcon\Http\Request;
$request = new Request;
$_SERVER["HTTP_HOST"] = "example.com";
$request->getHttpHost(); // example.com
$_SERVER["HTTP_HOST"] = "example.com:8080";
$request->getHttpHost(); // example.com:8080
$request->setStrictHostCheck(true);
$_SERVER["HTTP_HOST"] = "ex=am~ple.com";
$request->getHttpHost(); // UnexpectedValueException
$_SERVER["HTTP_HOST"] = "ExAmPlE.com";
$request->getHttpHost(); // example.com
如果设置了X-HTTP-Method-Override头,并且方法是POST,则使用它来确定“真实”的预期HTTP方法。
_method请求参数也可以用来确定HTTP方法,但仅在调用了setHttpMethodParameterOverride(true)时有效。
方法始终是一个大写的字符串。
public function getPatch( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from $_PATCH["user_email"] without sanitizing
$userEmail = $request->getPatch("user_email");
// Returns value from $_PATCH["user_email"] with sanitizing
$userEmail = $request->getPatch("user_email", "email");
public function getPost( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from $_POST["user_email"] without sanitizing
$userEmail = $request->getPost("user_email");
// Returns value from $_POST["user_email"] with sanitizing
$userEmail = $request->getPost("user_email", "email");
从 "Accept-Language" 请求 HTTP 头部中获取客户端接受的首选区域,并返回其基本部分。例如:en
而不是en-US
.
注意:此方法依赖于$_SERVER["HTTP_ACCEPT_LANGUAGE"]
头部。
@link https://www.iso.org/standard/50707.html
public function getPut( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from PUT stream without sanitizing
$userEmail = $request->getPut("user_email");
// Returns value from PUT stream with sanitizing
$userEmail = $request->getPut("user_email", "email");
public function getQuery( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from $_GET["id"] without sanitizing
$id = $request->getQuery("id");
// Returns value from $_GET["id"] with sanitizing
$id = $request->getQuery("id", "int");
// Returns value from $_GET["id"] with a default value
$id = $request->getQuery("id", null, 150);
// Returns /some/path?with=queryParams
$uri = $request->getURI();
// Returns /some/path
$uri = $request->getURI(true);
public function getUploadedFiles( bool $onlySuccessful = bool, bool $namedKeys = bool ): FileInterface[];
Request::getHttpHost
方法是否会使用严格的主机名验证。 检查 HTTP 方法是否为 TRACE。即 if _SERVER["REQUEST_METHOD"]==="TRACE" 检查某个方法是否为有效的HTTP方法 返回可用文件的数量。 设置 HTTP 方法参数覆盖标志。 public function setParameterFilters( string $name, array $filters = [], array $scope = [] ): RequestInterface;
Request::getHttpHost
方法是否必须使用严格的主机名验证。 处理一个请求头并返回具有最佳质量值的项。 final protected function getHelper( array $source, string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
final protected function smoothFiles( array $names, array $types, array $tmp_names, array $sizes, array $errors, string $prefix ): array;
Http\Request\Exception¶
-
命名空间
Phalcon\Http\Request
-
使用
-
继承
\Exception
-
实现
Phalcon\Http\Request\Exception
Phalcon\Http\Request 中抛出的异常将使用此类。
Http\Request\File¶
-
命名空间
Phalcon\Http\Request
-
使用
-
继承
-
实现
FileInterface
Phalcon\Http\Request\File
为 $_FILES 超全局变量提供面向对象封装。
use Phalcon\Mvc\Controller;
class PostsController extends Controller
{
public function uploadAction()
{
// Check if the user has uploaded files
if ($this->request->hasFiles() == true) {
// Print the real file names and their sizes
foreach ($this->request->getUploadedFiles() as $file) {
echo $file->getName(), " ", $file->getSize(), "\n";
}
}
}
}
属性¶
/**
* @var string|null
*/
protected $error;
/**
* @var string
*/
protected $extension;
/**
* @var string|null
*/
protected $key;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $realType;
/**
* @var int
*/
protected $size = ;
/**
* @var string|null
*/
protected $tmp;
/**
* @var string
*/
protected $type;
方法¶
Phalcon\Http\Request\File 构造函数。 返回上传文件的真实名称 使用finfo获取上传文件的真实mime类型。 返回上传文件的文件大小 返回上传文件的临时名称 返回浏览器报告的mime类型。此mime类型并不完全安全,请改用getRealType()方法。 检查文件是否通过Post上传。 将临时文件移动到应用程序内的目标位置Http\Request\FileInterface
¶
-
命名空间
Phalcon\Http\Request
-
使用
-
继承
-
实现
Phalcon\Http\Request\File的接口。
方法¶
如果有的话返回错误信息。 返回上传文件的真实名称 使用finfo获取上传文件的真实mime类型。 返回上传文件的文件大小 返回上传文件的临时名称。 返回浏览器报告的mime类型。此mime类型并不完全安全,请改用getRealType()方法。 将临时文件移动到目标位置。Http\RequestInterface
¶
-
命名空间
Phalcon\Http
-
使用
Phalcon\Http\Request\FileInterface
stdClass
-
继承
-
实现
Phalcon\Http\Request的接口。
方法¶
public function get( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from $_REQUEST["user_email"] without sanitizing
$userEmail = $request->get("user_email");
// Returns value from $_REQUEST["user_email"] with sanitizing
$userEmail = $request->get("user_email", "email");
$_SERVER = [
"PHP_AUTH_USER" => "phalcon",
"PHP_AUTH_PW" => "secret",
];
$headers = $request->getHeaders();
echo $headers["Authorization"]; // Basic cGhhbGNvbjpzZWNyZXQ=
Request::getHttpHost
按照以下顺序尝试查找主机名:
$_SERVER["HTTP_HOST"]
$_SERVER["SERVER_NAME"]
$_SERVER["SERVER_ADDR"]
可选地Request::getHttpHost
验证并清理主机名。Request::$_strictHostCheck
可用于验证主机名。
注意:验证和清理会对性能产生负面影响,因为它们使用了正则表达式。
use Phalcon\Http\Request;
$request = new Request;
$_SERVER["HTTP_HOST"] = "example.com";
$request->getHttpHost(); // example.com
$_SERVER["HTTP_HOST"] = "example.com:8080";
$request->getHttpHost(); // example.com:8080
$request->setStrictHostCheck(true);
$_SERVER["HTTP_HOST"] = "ex=am~ple.com";
$request->getHttpHost(); // UnexpectedValueException
$_SERVER["HTTP_HOST"] = "ExAmPlE.com";
$request->getHttpHost(); // example.com
如果设置了X-HTTP-Method-Override头,并且方法是POST,则使用它来确定“真实”的预期HTTP方法。
_method请求参数也可以用来确定HTTP方法,但仅在调用了setHttpMethodParameterOverride(true)时有效。
方法始终是一个大写的字符串。
获取请求所用端口的信息public function getPost( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from $_POST["user_email"] without sanitizing
$userEmail = $request->getPost("user_email");
// Returns value from $_POST["user_email"] with sanitizing
$userEmail = $request->getPost("user_email", "email");
public function getPut( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from PUT stream without sanitizing
$userEmail = $request->getPut("user_email");
// Returns value from PUT stream with sanitizing
$userEmail = $request->getPut("user_email", "email");
public function getQuery( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
// Returns value from $_GET["id"] without sanitizing
$id = $request->getQuery("id");
// Returns value from $_GET["id"] with sanitizing
$id = $request->getQuery("id", "int");
// Returns value from $_GET["id"] with a default value
$id = $request->getQuery("id", null, 150);
// Returns /some/path?with=queryParams
$uri = $request->getURI();
// Returns /some/path
$uri = $request->getURI(true);
public function getUploadedFiles( bool $onlySuccessful = bool, bool $namedKeys = bool ): FileInterface[];
Http\Response¶
-
命名空间
Phalcon\Http
-
使用
DateTime
DateTimeZone
Phalcon\Di\Di
Phalcon\Di\DiInterface
Phalcon\Di\InjectionAwareInterface
Phalcon\Events\EventsAwareInterface
Phalcon\Events\ManagerInterface
Phalcon\Http\Message\ResponseStatusCodeInterface
Phalcon\Http\Response\CookiesInterface
Phalcon\Http\Response\Exception
Phalcon\Http\Response\Headers
Phalcon\Http\Response\HeadersInterface
Phalcon\Mvc\Url\UrlInterface
Phalcon\Mvc\ViewInterface
Phalcon\Support\Helper\Json\Encode
-
继承
-
实现
EventsAwareInterface
InjectionAwareInterface
ResponseInterface
ResponseStatusCodeInterface
HTTP周期的一部分是将响应返回给客户端。Phalcon\HTTP\Response是Phalcon组件负责完成这一任务的组件。HTTP响应通常由头和正文组成。
$response = new \Phalcon\Http\Response();
$response->setStatusCode(200, "OK");
$response->setContent("<html><body>Hello</body></html>");
$response->send();
属性¶
/**
* @var DiInterface|null
*/
protected $container;
/**
* @var string|null
*/
protected $content;
/**
* @var CookiesInterface|null
*/
protected $cookies;
/**
* @var ManagerInterface|null
*/
protected $eventsManager;
/**
* @var string|null
*/
protected $file;
/**
* @var Headers
*/
protected $headers;
/**
* @var bool
*/
protected $sent = false;
/**
* @var array
*/
protected $statusCodes;
/**
* @var Encode
*/
private $encode;
方法¶
Phalcon\Http\Response构造函数。 向 HTTP 响应体追加一个字符串 获取 HTTP 响应体 返回用户设置的cookie。 返回内部的依赖注入器 返回内部事件管理器 返回用户设置的头部 返回原因短语。 返回状态码 检查一个头部是否存在 检查响应是否已经发送。public function redirect( mixed $location = null, bool $externalRedirect = bool, int $statusCode = int ): ResponseInterface;
// Using a string redirect (internal/external)
$response->redirect("posts/index");
$response->redirect("http://en.wikipedia.org", true);
$response->redirect("http://www.example.com/new-location", true, 301);
// Making a redirection based on a named route
$response->redirect(
[
"for" => "index-lang",
"lang" => "jp",
"controller" => "index",
]
);
public function setFileToSend( string $filePath, mixed $attachmentName = null, mixed $attachment = bool ): ResponseInterface;
public function setJsonContent( mixed $content, int $jsonOptions = int, int $depth = int ): ResponseInterface;
Http\Response\Cookies¶
-
命名空间
Phalcon\Http\Response
-
使用
Phalcon\Di\AbstractInjectionAware
Phalcon\Di\DiInterface
Phalcon\Http\Cookie\CookieInterface
Phalcon\Http\Cookie\Exception
-
继承
AbstractInjectionAware
-
实现
CookiesInterface
Phalcon\Http\Response\Cookies
此类是用于管理 Cookie 的容器。
Cookie 容器会作为 DI 中 'response' 服务的一部分自动注册。默认情况下,Cookie 在发送到客户端之前会被自动加密,从用户端检索时会被解密。要设置用于生成消息认证码的签名密钥,请使用Phalcon\Http\Response\Cookies::setSignKey()
.
use Phalcon\Di\Di;
use Phalcon\Encryption\Crypt;
use Phalcon\Http\Response\Cookies;
$di = new Di();
$di->set(
'crypt',
function () {
$crypt = new Crypt();
// The `$key' should have been previously generated in a cryptographically safe way.
$key = "T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3";
$crypt->setKey($key);
return $crypt;
}
);
$di->set(
'cookies',
function () {
$cookies = new Cookies();
// The `$key' MUST be at least 32 characters long and generated using a
// cryptographically secure pseudo random generator.
$key = "#1dj8$=dp?.ak//j1V$~%*0XaK\xb1\x8d\xa9\x98\x054t7w!z%C*F-Jk\x98\x05\\\x5c";
$cookies->setSignKey($key);
return $cookies;
}
);
属性¶
/**
* @var array
*/
protected $cookies;
/**
* @var bool
*/
protected $isSent = false;
/**
* @var bool
*/
protected $registered = false;
/**
* The cookie's sign key.
* @var string|null
*/
protected $signKey;
/**
* @var bool
*/
protected $useEncryption = true;
方法¶
Phalcon\Http\Response\Cookies 构造函数 按名称删除一个 Cookie。此方法不会从 _COOKIE 超全局变量中移除 Cookie 从容器中获取一个 Cookie 从容器中获取所有 Cookie 检查某个 Cookie 是否在容器中定义或在 _COOKIE 超全局变量中存在 返回头部是否已经发送 返回该容器是否正在自动加密/解密 Cookie 重置已设置的 Cookie 将 Cookie 发送给客户端。如果当前请求中头部已经发送,则 Cookie 不会发送public function set( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = bool, string $domain = string, bool $httpOnly = bool, array $options = [] ): CookiesInterface;
此方法会覆盖之前同名的 Cookie
use Phalcon\Http\Response\Cookies;
$now = new DateTimeImmutable();
$tomorrow = $now->modify('tomorrow');
$cookies = new Cookies();
$cookies->set(
'remember-me',
json_encode(['user_id' => 1]),
(int) $tomorrow->format('U'),
);
`$signKey` 必须至少有 32 个字符,并且必须使用密码学安全伪随机生成器生成
使用 NULL 来禁用 Cookie 签名
@see \Phalcon\Security\Random
设置 Cookie 容器中的 Cookie 是否需要自动加密/解密Http\Response\CookiesInterface
¶
-
命名空间
Phalcon\Http\Response
-
使用
Phalcon\Http\Cookie\CookieInterface
-
继承
-
实现
Phalcon\Http\Response\CookiesInterface
Phalcon\Http\Response\Cookies 接口
方法¶
按名称删除一个 Cookie。此方法不会从 _COOKIE 超全局变量中移除 Cookie 从容器中获取一个 Cookie 检查某个 Cookie 是否在容器中定义或在 _COOKIE 超全局变量中存在 返回该容器是否正在自动加密/解密 Cookie 重置已设置的 Cookie 将 Cookie 发送给客户端public function set( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = bool, string $domain = string, bool $httpOnly = bool, array $options = [] ): CookiesInterface;
Http\Response\Exception¶
-
命名空间
Phalcon\Http\Response
-
使用
-
继承
\Exception
-
实现
Phalcon\Http\Response\Exception
Phalcon\Http\Response 抛出的异常将使用此类
Http\Response\Headers¶
-
命名空间
Phalcon\Http\Response
-
使用
-
继承
-
实现
HeadersInterface
Phalcon\Http\Response\Headers
此类是用于管理响应头部的容器
属性¶
方法¶
从内部容器中获取一个头部值 检查一个头部是否存在 返回头部是否已经发送 按名称移除一个头部 重置已设置的头部 将头部发送给客户端 设置一个将在请求结束时发送的头部 设置一个将在请求结束时发送的原始头部 以数组形式返回当前的头部Http\Response\HeadersInterface
¶
-
命名空间
Phalcon\Http\Response
-
使用
-
继承
-
实现
Phalcon\Http\Response\HeadersInterface
Phalcon\Http\Response\Headers 兼容容器的接口
方法¶
从内部容器中获取一个头部值 检查一个头部是否存在 重置已设置的头部 将头部发送给客户端 设置一个将在请求结束时发送的头部 设置一个将在请求结束时发送的原始头部Http\ResponseInterface
¶
-
命名空间
Phalcon\Http
-
使用
DateTime
Phalcon\Http\Response\HeadersInterface
-
继承
-
实现
Phalcon\Http\Response
Phalcon\Http\Response 接口