sugatasei / bredala-http
PHP object-oriented layer for the HTTP specification
Installs: 23
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/sugatasei/bredala-http
Requires
- php: >=8.1.0
- ext-json: *
README
PHP object-oriented layer for the HTTP specification.
Request
Bredala\Http\Request helps to get HTTP request informations.
Server info
servers(): arrayReturns an array of server params.server(string $name)Returns a server params.time(): intReturns the request time in secondsmtime(): floatReturns the request time in seconds with more precision
HTTP method
method(): string Request method (CLI, GET, POST, DELETE, ...).
isGet(): bool Returns HTTP request's is using GET method.
isPost(): bool Returns HTTP request's is using POST method.
isPatch(): bool Returns HTTP request's is using PATCH method.
isDelete(): bool Returns HTTP request's is using DELETE method.
isClient(): bool Returns HTTP request's is using GET method.
isAjax(): bool Returns if the current request is an ajax request.
isSecure(): bool Returns if the request is using the HTTPS protocol.
uri(): string Returns the request URI.
HTTP Headers
cookies()Returns an array of cookies.cookie(string $name)Returns a cookie value.
Request data
queryParams(): arrayReturns an array of query params.queryParam(string $name)Returns a query value.bodyParams(): arrayReturns an array of form/json params.bodyParam(string $name)Returns a form/json value.attachements(): arrayReturns an array of uploaded files indexed by field name.attachement(string $name): arrayReturns an uploaded files.
Client
userAgent(): stringReturns the user agent.ip(): stringReturns the IP Address.
Response
Bredala\Http\Response helps to send HTTP response.
reset(): mixedReset the response.
HTTP status
getProtocolVersion(): stringReturns HTTP protocole version.setStatusCode(int $code, ?string $reason = null): staticSets HTTP status. If reason is null, a default reason corresponding to the HTTP status code is set.
HTTP headers
getHeaders(): arrayReturns HTTP headerssetHeader(string $name, string $value): staticSets HTTP header.addHeader(string $name, string $value): staticAdds HTTP header. Userfull for headers with multiple values.removeHeader(string $name): staticRemoves HTTP headersetContentType(string $mime, string $charset = "UTF-8"): staticSets content-type. File extension can be used for most of them.$res->setContentType('jpg'); $res->setContentType('image/jpeg');
addCookie(string $name, $value, int $expire = 0, $settings = []): staticAdds a cookie.removeCookie(string $name): staticRemoves cookie.redirect(string $url = "/", bool $temporary = true): staticHTTP redirection.cache(int $age = 86400): staticSets HTTP cache.noCache(): staticForces HTTP no-cache.cors(?string $origin = null, ?string $method = null): staticEnables CORS.
Http body
getBody(): Bredala\Http\Stream Returns body.
setBody(Bredala\Http\Stream|string $body = ""): static Sets body.
Rendering
emitHeaders() Sends headers.
emitBody(int $bufferLength = 0) Sends Content.
emit(int $bufferLength = 0) Sends headers & body.
Session
Bredala\Http\Session helps to work with HTTP response.
__construct(\SessionHandlerInterface $handler = NULL)The constructors can use an optionnal session handler.start(): staticStart the session.close(): staticWrites and closes current session.destroy(): staticDestroys session.reset(): staticRemoves all sessions vars.all()Returns all session data.has(string $name): boolReturns all session data.get(string $name, $default = null): mixedReturns session data by name.set(string $name, mixed $value): staticSets session data by name.
Flash data
Session data that will only be available for the next request, and is then automatically cleared.
setFlash(string $name, $value): staticmarkFlash(string $name): staticunmarkFlash(string $name): static
Temp data
Session data with a specific expiration time. After the value expires, or the session expires or is deleted, the value is automatically removed.
setTemp($name, $value, $time = 300)markTemp(string $name, int $time = 300)unmarkTemp(string $name)