Skip to content

Phalcon http

NOTE

All classes are prefixed with Phalcon

Http\Cookie

Source on GitHub

  • Namespace

    • Phalcon\Http
  • Uses

    • 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
  • Extends

    AbstractInjectionAware

  • Implements

    • CookieInterface

Provide OO wrappers to manage a HTTP cookie.

Properties

/**
 * @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;

Methods

public function __construct( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = null, string $domain = null, bool $httpOnly = null, array $options = [] );
Phalcon\Http\Cookie constructor.

public function __toString(): string;
Magic __toString method converts the cookie's value to string

public function delete();
Deletes the cookie by setting an expire time in the past

public function getDomain(): string;
Returns the domain that the cookie is available to

public function getExpiration(): string;
Returns the current expiration time

public function getHttpOnly(): bool;
Returns if the cookie is accessible only through the HTTP protocol

public function getName(): string;
Returns the current cookie's name

public function getOptions(): array;
Returns the current cookie's options

public function getPath(): string;
Returns the current cookie's path

public function getSecure(): bool;
Returns whether the cookie must only be sent when the connection is secure (HTTPS)

public function getValue( mixed $filters = null, mixed $defaultValue = null ): mixed;
Returns the cookie's value.

public function isUsingEncryption(): bool;
Check if the cookie is using implicit encryption

public function restore(): CookieInterface;
Reads the cookie-related info from the SESSION to restore the cookie as it was set.

This method is automatically called internally so normally you don't need to call it.

public function send(): CookieInterface;
Sends the cookie to the HTTP client.

Stores the cookie definition in session.

public function setDomain( string $domain ): CookieInterface;
Sets the domain that the cookie is available to

public function setExpiration( int $expire ): CookieInterface;
Sets the cookie's expiration time

public function setHttpOnly( bool $httpOnly ): CookieInterface;
Sets if the cookie is accessible only through the HTTP protocol

public function setOptions( array $options ): CookieInterface;
Sets the cookie's options

public function setPath( string $path ): CookieInterface;
Sets the cookie's path

public function setSecure( bool $secure ): CookieInterface;
Sets if the cookie must only be sent when the connection is secure (HTTPS)

public function setSignKey( string $signKey = null ): CookieInterface;
Sets the cookie's sign key.

The `$signKey' MUST be at least 32 characters long and generated using a cryptographically secure pseudo random generator.

Use NULL to disable cookie signing.

@see \Phalcon\Security\Random @throws \Phalcon\Http\Cookie\Exception

public function setValue( mixed $value ): CookieInterface;
Sets the cookie's value

public function useEncryption( bool $useEncryption ): CookieInterface;
Sets if the cookie must be encrypted/decrypted automatically

protected function assertSignKeyIsLongEnough( string $signKey ): void;
Assert the cookie's key is enough long.

@throws \Phalcon\Http\Cookie\Exception

Http\Cookie\CookieInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Http\Cookie
  • Uses

  • Extends

  • Implements

Interface for Phalcon\Http\Cookie

Methods

public function delete();
Deletes the cookie

public function getDomain(): string;
Returns the domain that the cookie is available to

public function getExpiration(): string;
Returns the current expiration time

public function getHttpOnly(): bool;
Returns if the cookie is accessible only through the HTTP protocol

public function getName(): string;
Returns the current cookie's name

public function getOptions(): array;
Returns the current cookie's options

public function getPath(): string;
Returns the current cookie's path

public function getSecure(): bool;
Returns whether the cookie must only be sent when the connection is secure (HTTPS)

public function getValue( mixed $filters = null, mixed $defaultValue = null ): mixed;
Returns the cookie's value.

public function isUsingEncryption(): bool;
Check if the cookie is using implicit encryption

public function send(): CookieInterface;
Sends the cookie to the HTTP client

public function setDomain( string $domain ): CookieInterface;
Sets the domain that the cookie is available to

public function setExpiration( int $expire ): CookieInterface;
Sets the cookie's expiration time

public function setHttpOnly( bool $httpOnly ): CookieInterface;
Sets if the cookie is accessible only through the HTTP protocol

public function setOptions( array $options ): CookieInterface;
Sets the cookie's options

public function setPath( string $path ): CookieInterface;
Sets the cookie's expiration time

public function setSecure( bool $secure ): CookieInterface;
Sets if the cookie must only be sent when the connection is secure (HTTPS)

public function setValue( mixed $value ): CookieInterface;
Sets the cookie's value

public function useEncryption( bool $useEncryption ): CookieInterface;
Sets if the cookie must be encrypted/decrypted automatically

Http\Cookie\Exception

Source on GitHub

  • Namespace

    • Phalcon\Http\Cookie
  • Uses

  • Extends

    \Exception

  • Implements

Phalcon\Http\Cookie\Exception

Exceptions thrown in Phalcon\Http\Cookie will use this class.

Http\Message\RequestMethodInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Http\Message
  • Uses

  • Extends

  • Implements

Interface for Request methods

Implementation of this file has been influenced by PHP FIG @link https://github.com/php-fig/http-message-util/ @license https://github.com/php-fig/http-message-util/blob/master/LICENSE

Constants

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 Interface

Source on GitHub

  • Namespace

    • Phalcon\Http\Message
  • Uses

  • Extends

  • Implements

Interface for Request methods

Implementation of this file has been influenced by PHP FIG @link https://github.com/php-fig/http-message-util/ @license https://github.com/php-fig/http-message-util/blob/master/LICENSE

Defines constants for common HTTP status code.

@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

Constants

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

Source on GitHub

  • Namespace

    • Phalcon\Http
  • Uses

    • 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
  • Extends

    AbstractInjectionAware

  • Implements

    • RequestInterface
    • RequestMethodInterface

Encapsulates request information for easy and secure access from application controllers.

The request object is a simple value object that is passed between the dispatcher and controller classes. It packages the HTTP request environment.

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();

Properties

/**
 * @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;

Methods

public function get( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Gets a variable from the $_REQUEST superglobal applying filters if needed. If no parameters are given the $_REQUEST superglobal is returned

// 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");

public function getAcceptableContent(): array;
Gets an array with mime/types and their quality accepted by the browser/client from _SERVER["HTTP_ACCEPT"]

public function getBasicAuth(): array | null;
Gets auth info accepted by the browser/client from $_SERVER["PHP_AUTH_USER"]

public function getBestAccept(): string;
Gets best mime/type accepted by the browser/client from _SERVER["HTTP_ACCEPT"]

public function getBestCharset(): string;
Gets best charset accepted by the browser/client from _SERVER["HTTP_ACCEPT_CHARSET"]

public function getBestLanguage(): string;
Gets best language accepted by the browser/client from _SERVER["HTTP_ACCEPT_LANGUAGE"]

public function getClientAddress( bool $trustForwardedHeader = bool ): string | bool;
Gets most possible client IPv4 Address. This method searches in $_SERVER["REMOTE_ADDR"] and optionally in $_SERVER["HTTP_X_FORWARDED_FOR"]

public function getClientCharsets(): array;
Gets a charsets array and their quality accepted by the browser/client from _SERVER["HTTP_ACCEPT_CHARSET"]

public function getContentType(): string | null;
Gets content type which request has been made

public function getDigestAuth(): array;
Gets auth info accepted by the browser/client from $_SERVER["PHP_AUTH_DIGEST"]

public function getFilteredData( string $methodKey, string $method, string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Gets filtered data

public function getFilteredPatch( string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Retrieves a patch value always sanitized with the preset filters

public function getFilteredPost( string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Retrieves a post value always sanitized with the preset filters

public function getFilteredPut( string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Retrieves a put value always sanitized with the preset filters

public function getFilteredQuery( string $name = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Retrieves a query/get value always sanitized with the preset filters

public function getHTTPReferer(): string;
Gets web page that refers active request. ie: https://www.google.com

final public function getHeader( string $header ): string;
Gets HTTP header from request data

public function getHeaders(): array;
Returns the available headers in the request

$_SERVER = [ "PHP_AUTH_USER" => "phalcon", "PHP_AUTH_PW" => "secret", ];

$headers = $request->getHeaders();

echo $headers["Authorization"]; // Basic cGhhbGNvbjpzZWNyZXQ=

public function getHttpHost(): string;
Gets host name used by the request.

Request::getHttpHost trying to find host name in following order:

  • $_SERVER["HTTP_HOST"]
  • $_SERVER["SERVER_NAME"]
  • $_SERVER["SERVER_ADDR"]

Optionally Request::getHttpHost validates and clean host name. The Request::$strictHostCheck can be used to validate host name.

Note: validation and cleaning have a negative performance impact because they use regular expressions.

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

public function getHttpMethodParameterOverride(): bool;
Return the HTTP method parameter override flag

public function getJsonRawBody( bool $associative = bool ): \stdClass | array | bool;
Gets decoded JSON HTTP raw request body

public function getLanguages(): array;
Gets languages array and their quality accepted by the browser/client from _SERVER["HTTP_ACCEPT_LANGUAGE"]

final public function getMethod(): string;
Gets HTTP method which request has been made

If the X-HTTP-Method-Override header is set, and if the method is a POST, then it is used to determine the "real" intended HTTP method.

The _method request parameter can also be used to determine the HTTP method, but only if setHttpMethodParameterOverride(true) has been called.

The method is always an uppercased string.

public function getPatch( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Gets a variable from put request

// 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 getPort(): int;
Gets information about the port on which the request is made.

public function getPost( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Gets a variable from the $_POST superglobal applying filters if needed If no parameters are given the $_POST superglobal is returned

// 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 getPreferredIsoLocaleVariant(): string;
Gets the preferred ISO locale variant.

Gets the preferred locale accepted by the client from the "Accept-Language" request HTTP header and returns the base part of it i.e. en instead of en-US.

Note: This method relies on the $_SERVER["HTTP_ACCEPT_LANGUAGE"] header.

@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;
Gets a variable from put request

// Returns value from $_PUT["user_email"] without sanitizing
$userEmail = $request->getPut("user_email");

// Returns value from $_PUT["user_email"] 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;
Gets variable from $_GET superglobal applying filters if needed If no parameters are given the $_GET superglobal is returned

// 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);

public function getRawBody(): string;
Gets HTTP raw request body

public function getScheme(): string;
Gets HTTP schema (http/https)

public function getServer( string $name ): string | null;
Gets variable from $_SERVER superglobal

public function getServerAddress(): string;
Gets active server address IP

public function getServerName(): string;
Gets active server name

final public function getURI( bool $onlyPath = bool ): string;
Gets HTTP URI which request has been made to

// 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[];
Gets attached files as Phalcon\Http\Request\File instances

public function getUserAgent(): string;
Gets HTTP user agent used to made the request

public function has( string $name ): bool;
Checks whether $_REQUEST superglobal has certain index

public function hasFiles(): bool;
Returns if the request has files or not

final public function hasHeader( string $header ): bool;
Checks whether headers has certain index

public function hasPatch( string $name ): bool;
Checks whether the PATCH data has certain index

public function hasPost( string $name ): bool;
Checks whether $_POST superglobal has certain index

public function hasPut( string $name ): bool;
Checks whether the PUT data has certain index

public function hasQuery( string $name ): bool;
Checks whether $_GET superglobal has certain index

final public function hasServer( string $name ): bool;
Checks whether $_SERVER superglobal has certain index

public function isAjax(): bool;
Checks whether request has been made using ajax

public function isConnect(): bool;
Checks whether HTTP method is CONNECT. if _SERVER["REQUEST_METHOD"]==="CONNECT"

public function isDelete(): bool;
Checks whether HTTP method is DELETE. if _SERVER["REQUEST_METHOD"]==="DELETE"

public function isGet(): bool;
Checks whether HTTP method is GET. if _SERVER["REQUEST_METHOD"]==="GET"

public function isHead(): bool;
Checks whether HTTP method is HEAD. if _SERVER["REQUEST_METHOD"]==="HEAD"

public function isMethod( mixed $methods, bool $strict = bool ): bool;
Check if HTTP method match any of the passed methods When strict is true it checks if validated methods are real HTTP methods

public function isOptions(): bool;
Checks whether HTTP method is OPTIONS. if _SERVER["REQUEST_METHOD"]==="OPTIONS"

public function isPatch(): bool;
Checks whether HTTP method is PATCH. if _SERVER["REQUEST_METHOD"]==="PATCH"

public function isPost(): bool;
Checks whether HTTP method is POST. if _SERVER["REQUEST_METHOD"]==="POST"

public function isPurge(): bool;
Checks whether HTTP method is PURGE (Squid and Varnish support). if _SERVER["REQUEST_METHOD"]==="PURGE"

public function isPut(): bool;
Checks whether HTTP method is PUT. if _SERVER["REQUEST_METHOD"]==="PUT"

public function isSecure(): bool;
Checks whether request has been made using any secure layer

public function isSoap(): bool;
Checks whether request has been made using SOAP

public function isStrictHostCheck(): bool;
Checks if the Request::getHttpHost method will be use strict validation of host name or not

public function isTrace(): bool;
Checks whether HTTP method is TRACE. if _SERVER["REQUEST_METHOD"]==="TRACE"

public function isValidHttpMethod( string $method ): bool;
Checks if a method is a valid HTTP method

public function numFiles( bool $onlySuccessful = bool ): long;
Returns the number of files available

public function setHttpMethodParameterOverride( bool $override ): Request;
Set the HTTP method parameter override flag

public function setParameterFilters( string $name, array $filters = [], array $scope = [] ): RequestInterface;
Sets automatic sanitizers/filters for a particular field and for particular methods

public function setStrictHostCheck( bool $flag = bool ): RequestInterface;
Sets if the Request::getHttpHost method must be use strict validation of host name or not

final protected function getBestQuality( array $qualityParts, string $name ): string;
Process a request header and return the one with best quality

final protected function getHelper( array $source, string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Helper to get data from superglobals, applying filters if needed. If no parameters are given the superglobal is returned.

final protected function getQualityHeader( string $serverIndex, string $name ): array;
Process a request header and return an array of values with their qualities

final protected function hasFileHelper( mixed $data, bool $onlySuccessful ): long;
Recursively counts file in an array of files

protected function resolveAuthorizationHeaders(): array;
Resolve authorization headers.

final protected function smoothFiles( array $names, array $types, array $tmp_names, array $sizes, array $errors, string $prefix ): array;
Smooth out $_FILES to have plain array with all files uploaded

Http\Request\Exception

Source on GitHub

  • Namespace

    • Phalcon\Http\Request
  • Uses

  • Extends

    \Exception

  • Implements

Phalcon\Http\Request\Exception

Exceptions thrown in Phalcon\Http\Request will use this class

Http\Request\File

Source on GitHub

  • Namespace

    • Phalcon\Http\Request
  • Uses

  • Extends

  • Implements

    • FileInterface

Phalcon\Http\Request\File

Provides OO wrappers to the $_FILES superglobal

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";
            }
        }
    }
}

Properties

/**
 * @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;

Methods

public function __construct( array $file, mixed $key = null );
Phalcon\Http\Request\File constructor

public function getError(): string | null;
public function getExtension(): string;
public function getKey(): string | null;

public function getName(): string;
Returns the real name of the uploaded file

public function getRealType(): string;
Gets the real mime type of the upload file using finfo

public function getSize(): int;
Returns the file size of the uploaded file

public function getTempName(): string;
Returns the temporary name of the uploaded file

public function getType(): string;
Returns the mime type reported by the browser This mime type is not completely secure, use getRealType() instead

public function isUploadedFile(): bool;
Checks whether the file has been uploaded via Post.

public function moveTo( string $destination ): bool;
Moves the temporary file to a destination within the application

Http\Request\FileInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Http\Request
  • Uses

  • Extends

  • Implements

Interface for Phalcon\Http\Request\File

Methods

public function getError(): string | null;
Returns the error if any

public function getName(): string;
Returns the real name of the uploaded file

public function getRealType(): string;
Gets the real mime type of the upload file using finfo

public function getSize(): int;
Returns the file size of the uploaded file

public function getTempName(): string;
Returns the temporal name of the uploaded file

public function getType(): string;
Returns the mime type reported by the browser This mime type is not completely secure, use getRealType() instead

public function moveTo( string $destination ): bool;
Move the temporary file to a destination

Http\RequestInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Http
  • Uses

    • Phalcon\Http\Request\FileInterface
    • stdClass
  • Extends

  • Implements

Interface for Phalcon\Http\Request

Methods

public function get( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Gets a variable from the $_REQUEST superglobal applying filters if needed. If no parameters are given the $_REQUEST superglobal is returned

// 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");

public function getAcceptableContent(): array;
Gets an array with mime/types and their quality accepted by the browser/client from _SERVER["HTTP_ACCEPT"]

public function getBasicAuth(): array | null;
Gets auth info accepted by the browser/client from $_SERVER["PHP_AUTH_USER"]

public function getBestAccept(): string;
Gets best mime/type accepted by the browser/client from _SERVER["HTTP_ACCEPT"]

public function getBestCharset(): string;
Gets best charset accepted by the browser/client from _SERVER["HTTP_ACCEPT_CHARSET"]

public function getBestLanguage(): string;
Gets best language accepted by the browser/client from _SERVER["HTTP_ACCEPT_LANGUAGE"]

public function getClientAddress( bool $trustForwardedHeader = bool ): string | bool;
Gets most possible client IPv4 Address. This method searches in $_SERVER["REMOTE_ADDR"] and optionally in $_SERVER["HTTP_X_FORWARDED_FOR"]

public function getClientCharsets(): array;
Gets a charsets array and their quality accepted by the browser/client from _SERVER["HTTP_ACCEPT_CHARSET"]

public function getContentType(): string | null;
Gets content type which request has been made

public function getDigestAuth(): array;
Gets auth info accepted by the browser/client from $_SERVER["PHP_AUTH_DIGEST"]

public function getHTTPReferer(): string;
Gets web page that refers active request. ie: https://www.google.com

public function getHeader( string $header ): string;
Gets HTTP header from request data

public function getHeaders(): array;
Returns the available headers in the request

$_SERVER = [
    "PHP_AUTH_USER" => "phalcon",
    "PHP_AUTH_PW"   => "secret",
];

$headers = $request->getHeaders();

echo $headers["Authorization"]; // Basic cGhhbGNvbjpzZWNyZXQ=

public function getHttpHost(): string;
Gets host name used by the request.

Request::getHttpHost trying to find host name in following order:

  • $_SERVER["HTTP_HOST"]
  • $_SERVER["SERVER_NAME"]
  • $_SERVER["SERVER_ADDR"]

Optionally Request::getHttpHost validates and clean host name. The Request::$_strictHostCheck can be used to validate host name.

Note: validation and cleaning have a negative performance impact because they use regular expressions.

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

public function getJsonRawBody( bool $associative = bool ): stdClass | array | bool;
Gets decoded JSON HTTP raw request body

public function getLanguages(): array;
Gets languages array and their quality accepted by the browser/client from _SERVER["HTTP_ACCEPT_LANGUAGE"]

public function getMethod(): string;
Gets HTTP method which request has been made

If the X-HTTP-Method-Override header is set, and if the method is a POST, then it is used to determine the "real" intended HTTP method.

The _method request parameter can also be used to determine the HTTP method, but only if setHttpMethodParameterOverride(true) has been called.

The method is always an uppercased string.

public function getPort(): int;
Gets information about the port on which the request is made

public function getPost( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
Gets a variable from the $_POST superglobal applying filters if needed If no parameters are given the $_POST superglobal is returned

// 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;
Gets a variable from put request

// Returns value from $_PUT["user_email"] without sanitizing
$userEmail = $request->getPut("user_email");

// Returns value from $_PUT["user_email"] 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;
Gets variable from $_GET superglobal applying filters if needed If no parameters are given the $_GET superglobal is returned

// 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);

public function getRawBody(): string;
Gets HTTP raw request body

public function getScheme(): string;
Gets HTTP schema (http/https)

public function getServer( string $name ): string | null;
Gets variable from $_SERVER superglobal

public function getServerAddress(): string;
Gets active server address IP

public function getServerName(): string;
Gets active server name

public function getURI( bool $onlyPath = bool ): string;
Gets HTTP URI which request has been made to

// 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[];
Gets attached files as Phalcon\Http\Request\FileInterface compatible instances

public function getUserAgent(): string;
Gets HTTP user agent used to made the request

public function has( string $name ): bool;
Checks whether $_REQUEST superglobal has certain index

public function hasFiles(): bool;
Checks whether request include attached files

public function hasHeader( string $header ): bool;
Checks whether headers has certain index

public function hasPost( string $name ): bool;
Checks whether $_POST superglobal has certain index

public function hasPut( string $name ): bool;
Checks whether the PUT data has certain index

public function hasQuery( string $name ): bool;
Checks whether $_GET superglobal has certain index

public function hasServer( string $name ): bool;
Checks whether $_SERVER superglobal has certain index

public function isAjax(): bool;
Checks whether request has been made using ajax. Checks if $_SERVER["HTTP_X_REQUESTED_WITH"] === "XMLHttpRequest"

public function isConnect(): bool;
Checks whether HTTP method is CONNECT. if $_SERVER["REQUEST_METHOD"] === "CONNECT"

public function isDelete(): bool;
Checks whether HTTP method is DELETE. if $_SERVER["REQUEST_METHOD"] === "DELETE"

public function isGet(): bool;
Checks whether HTTP method is GET. if $_SERVER["REQUEST_METHOD"] === "GET"

public function isHead(): bool;
Checks whether HTTP method is HEAD. if $_SERVER["REQUEST_METHOD"] === "HEAD"

public function isMethod( mixed $methods, bool $strict = bool ): bool;
Check if HTTP method match any of the passed methods

public function isOptions(): bool;
Checks whether HTTP method is OPTIONS. if $_SERVER["REQUEST_METHOD"] === "OPTIONS"

public function isPost(): bool;
Checks whether HTTP method is POST. if $_SERVER["REQUEST_METHOD"] === "POST"

public function isPurge(): bool;
Checks whether HTTP method is PURGE (Squid and Varnish support). if $_SERVER["REQUEST_METHOD"] === "PURGE"

public function isPut(): bool;
Checks whether HTTP method is PUT. if $_SERVER["REQUEST_METHOD"] === "PUT"

public function isSecure(): bool;
Checks whether request has been made using any secure layer

public function isSoap(): bool;
Checks whether request has been made using SOAP

public function isTrace(): bool;
Checks whether HTTP method is TRACE. if $_SERVER["REQUEST_METHOD"] === "TRACE"

public function numFiles( bool $onlySuccessful = bool ): long;
Returns the number of files available

Http\Response

Source on GitHub

  • Namespace

    • Phalcon\Http
  • Uses

    • 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
  • Extends

  • Implements

    • EventsAwareInterface
    • InjectionAwareInterface
    • ResponseInterface
    • ResponseStatusCodeInterface

Part of the HTTP cycle is return responses to the clients. Phalcon\HTTP\Response is the Phalcon component responsible to achieve this task. HTTP responses are usually composed by headers and body.

$response = new \Phalcon\Http\Response();

$response->setStatusCode(200, "OK");
$response->setContent("<html><body>Hello</body></html>");

$response->send();

Properties

/**
 * @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;

Methods

public function __construct( string $content = null, mixed $code = null, mixed $status = null );
Phalcon\Http\Response constructor

public function appendContent( mixed $content ): ResponseInterface;
Appends a string to the HTTP response body

public function getContent(): string;
Gets the HTTP response body

public function getCookies(): CookiesInterface;
Returns cookies set by the user

public function getDI(): DiInterface;
Returns the internal dependency injector

public function getEventsManager(): ManagerInterface | null;
Returns the internal event manager

public function getHeaders(): HeadersInterface;
Returns headers set by the user

public function getReasonPhrase(): string | null;
Returns the reason phrase

echo $response->getReasonPhrase();

public function getStatusCode(): int | null;
Returns the status code

echo $response->getStatusCode();

public function hasHeader( string $name ): bool;
Checks if a header exists

$response->hasHeader("Content-Type");

public function isSent(): bool;
Check if the response is already sent

public function redirect( mixed $location = null, bool $externalRedirect = bool, int $statusCode = int ): ResponseInterface;
Redirect by HTTP to another action or URL

// 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 removeHeader( string $name ): ResponseInterface;
Remove a header in the response

$response->removeHeader("Expires");

public function resetHeaders(): ResponseInterface;
Resets all the established headers

public function send(): ResponseInterface;
Prints out HTTP response to the client

public function sendCookies(): ResponseInterface;
Sends cookies to the client

public function sendHeaders(): ResponseInterface | bool;
Sends headers to the client

public function setCache( int $minutes ): ResponseInterface;
Sets Cache headers to use HTTP cache

$this->response->setCache(60);

public function setContent( string $content ): ResponseInterface;
Sets HTTP response body

$response->setContent("<h1>Hello!</h1>");

public function setContentLength( int $contentLength ): ResponseInterface;
Sets the response content-length

$response->setContentLength(2048);

public function setContentType( string $contentType, mixed $charset = null ): ResponseInterface;
Sets the response content-type mime, optionally the charset

$response->setContentType("application/pdf");
$response->setContentType("text/plain", "UTF-8");

public function setCookies( CookiesInterface $cookies ): ResponseInterface;
Sets a cookies bag for the response externally

public function setDI( DiInterface $container ): void;
Sets the dependency injector

public function setEtag( string $etag ): ResponseInterface;
Set a custom ETag

$response->setEtag(
    md5(
        time()
    )
);

public function setEventsManager( ManagerInterface $eventsManager ): void;
Sets the events manager

public function setExpires( DateTime $datetime ): ResponseInterface;
Sets an Expires header in the response that allows to use the HTTP cache

$this->response->setExpires(
    new DateTime()
);

public function setFileToSend( string $filePath, mixed $attachmentName = null, mixed $attachment = bool ): ResponseInterface;
Sets an attached file to be sent at the end of the request

public function setHeader( string $name, mixed $value ): ResponseInterface;
Overwrites a header in the response

$response->setHeader("Content-Type", "text/plain");

public function setHeaders( HeadersInterface $headers ): ResponseInterface;
Sets a headers bag for the response externally

public function setJsonContent( mixed $content, int $jsonOptions = int, int $depth = int ): ResponseInterface;
Sets HTTP response body. The parameter is automatically converted to JSON and also sets default header: Content-Type: "application/json; charset=UTF-8"

$response->setJsonContent(
    [
        "status" => "OK",
    ]
);

public function setLastModified( DateTime $datetime ): ResponseInterface;
Sets Last-Modified header

$this->response->setLastModified(
    new DateTime()
);

public function setNotModified(): ResponseInterface;
Sends a Not-Modified response

public function setRawHeader( string $header ): ResponseInterface;
Send a raw header to the response

$response->setRawHeader("HTTP/1.1 404 Not Found");

public function setStatusCode( int $code, string $message = null ): ResponseInterface;
Sets the HTTP response code

$response->setStatusCode(404, "Not Found");

Http\Response\Cookies

Source on GitHub

  • Namespace

    • Phalcon\Http\Response
  • Uses

    • Phalcon\Di\AbstractInjectionAware
    • Phalcon\Di\DiInterface
    • Phalcon\Http\Cookie\CookieInterface
    • Phalcon\Http\Cookie\Exception
  • Extends

    AbstractInjectionAware

  • Implements

    • CookiesInterface

Phalcon\Http\Response\Cookies

This class is a bag to manage the cookies.

A cookies bag is automatically registered as part of the 'response' service in the DI. By default, cookies are automatically encrypted before being sent to the client and are decrypted when retrieved from the user. To set sign key used to generate a message authentication code use 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;
    }
);

Properties

/**
 * @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;

Methods

public function __construct( bool $useEncryption = bool, string $signKey = null );
Phalcon\Http\Response\Cookies constructor

public function delete( string $name ): bool;
Deletes a cookie by its name This method does not removes cookies from the _COOKIE superglobal

public function get( string $name ): CookieInterface;
Gets a cookie from the bag

public function getCookies(): array;
Gets all cookies from the bag

public function has( string $name ): bool;
Check if a cookie is defined in the bag or exists in the _COOKIE superglobal

public function isSent(): bool;
Returns if the headers have already been sent

public function isUsingEncryption(): bool;
Returns if the bag is automatically encrypting/decrypting cookies

public function reset(): CookiesInterface;
Reset set cookies

public function send(): bool;
Sends the cookies to the client Cookies aren't sent if headers are sent in the current request

public function set( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = null, string $domain = null, bool $httpOnly = null, array $options = [] ): CookiesInterface;
Sets a cookie to be sent at the end of the request.

This method overrides any cookie set before with the same name.

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'),
);

public function setSignKey( string $signKey = null ): CookiesInterface;
Sets the cookie's sign key.

The `$signKey' MUST be at least 32 characters long and generated using a cryptographically secure pseudo random generator.

Use NULL to disable cookie signing.

@see \Phalcon\Security\Random

public function useEncryption( bool $useEncryption ): CookiesInterface;
Set if cookies in the bag must be automatically encrypted/decrypted

Http\Response\CookiesInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Http\Response
  • Uses

    • Phalcon\Http\Cookie\CookieInterface
  • Extends

  • Implements

Phalcon\Http\Response\CookiesInterface

Interface for Phalcon\Http\Response\Cookies

Methods

public function delete( string $name ): bool;
Deletes a cookie by its name This method does not removes cookies from the _COOKIE superglobal

public function get( string $name ): CookieInterface;
Gets a cookie from the bag

public function has( string $name ): bool;
Check if a cookie is defined in the bag or exists in the _COOKIE superglobal

public function isUsingEncryption(): bool;
Returns if the bag is automatically encrypting/decrypting cookies

public function reset(): CookiesInterface;
Reset set cookies

public function send(): bool;
Sends the cookies to the client

public function set( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = null, string $domain = null, bool $httpOnly = null, array $options = [] ): CookiesInterface;
Sets a cookie to be sent at the end of the request

public function useEncryption( bool $useEncryption ): CookiesInterface;
Set if cookies in the bag must be automatically encrypted/decrypted

Http\Response\Exception

Source on GitHub

  • Namespace

    • Phalcon\Http\Response
  • Uses

  • Extends

    \Exception

  • Implements

Phalcon\Http\Response\Exception

Exceptions thrown in Phalcon\Http\Response will use this class.

Http\Response\Headers

Source on GitHub

  • Namespace

    • Phalcon\Http\Response
  • Uses

  • Extends

  • Implements

    • HeadersInterface

Phalcon\Http\Response\Headers

This class is a bag to manage the response headers

Properties

/**
 * @var array
 */
protected $headers;

/**
 * @var bool
 */
protected $isSent = false;

Methods

public function get( string $name ): string | bool;
Gets a header value from the internal bag

public function has( string $name ): bool;
Checks if a header exists

public function isSent(): bool;
Returns if the headers have already been sent

public function remove( string $header ): HeadersInterface;
Removes a header by its name

public function reset();
Reset set headers

public function send(): bool;
Sends the headers to the client

public function set( string $name, string $value ): HeadersInterface;
Sets a header to be sent at the end of the request

public function setRaw( string $header ): HeadersInterface;
Sets a raw header to be sent at the end of the request

public function toArray(): array;
Returns the current headers as an array

Http\Response\HeadersInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Http\Response
  • Uses

  • Extends

  • Implements

Phalcon\Http\Response\HeadersInterface

Interface for Phalcon\Http\Response\Headers compatible bags

Methods

public function get( string $name ): string | bool;
Gets a header value from the internal bag

public function has( string $name ): bool;
Checks if a header exists

public function reset();
Reset set headers

public function send(): bool;
Sends the headers to the client

public function set( string $name, string $value );
Sets a header to be sent at the end of the request

public function setRaw( string $header );
Sets a raw header to be sent at the end of the request

Http\ResponseInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Http
  • Uses

    • DateTime
    • Phalcon\Http\Response\HeadersInterface
  • Extends

  • Implements

Phalcon\Http\Response

Interface for Phalcon\Http\Response

Methods

public function appendContent( mixed $content ): ResponseInterface;
Appends a string to the HTTP response body

public function getContent(): string;
Gets the HTTP response body

public function getHeaders(): HeadersInterface;
Returns headers set by the user

public function getStatusCode(): int | null;
Returns the status code

public function hasHeader( string $name ): bool;
Checks if a header exists

public function isSent(): bool;
Checks if the response was already sent

public function redirect( mixed $location = null, bool $externalRedirect = bool, int $statusCode = int ): ResponseInterface;
Redirect by HTTP to another action or URL

public function resetHeaders(): ResponseInterface;
Resets all the established headers

public function send(): ResponseInterface;
Prints out HTTP response to the client

public function sendCookies(): ResponseInterface;
Sends cookies to the client

public function sendHeaders(): ResponseInterface | bool;
Sends headers to the client

public function setContent( string $content ): ResponseInterface;
Sets HTTP response body

public function setContentLength( int $contentLength ): ResponseInterface;
Sets the response content-length

public function setContentType( string $contentType, mixed $charset = null ): ResponseInterface;
Sets the response content-type mime, optionally the charset

public function setExpires( DateTime $datetime ): ResponseInterface;
Sets output expire time header

public function setFileToSend( string $filePath, mixed $attachmentName = null ): ResponseInterface;
Sets an attached file to be sent at the end of the request

public function setHeader( string $name, mixed $value ): ResponseInterface;
Overwrites a header in the response

public function setJsonContent( mixed $content ): ResponseInterface;
Sets HTTP response body. The parameter is automatically converted to JSON

$response->setJsonContent(
    [
        "status" => "OK",
    ]
);

public function setNotModified(): ResponseInterface;
Sends a Not-Modified response

public function setRawHeader( string $header ): ResponseInterface;
Send a raw header to the response

public function setStatusCode( int $code, string $message = null ): ResponseInterface;
Sets the HTTP response code