Download the PHP package qiq/helper-sapien without Composer
On this page you can find all versions of the php package qiq/helper-sapien. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package helper-sapien
Qiq Helpers for Sapien
This package provides Qiq helpers for Sapien Request and Response objects. These helpers allow you to read from a Request, and build a Response, from inside a Qiq Template.
Read more about:
- the request helper
- the response helper
Installation
This package is installable via Composer as qiq/helpers-sapien:
Request Helper
Registration
To make the request helper available inside your Template, you need to register it with the Qiq HelperLocator. You can register the helper semi-automatically ...
... or you can do so more manually:
By default, the helper will construct a new internal Sapien Request object of its own. If you want to pass an existing Request object, you may do so:
Usage
Once the helper is registered, you can call it using the method name you registered it under. You can use Qiq syntax ...
... or PHP syntax:
The request helper proxies to its internal Sapien Request object, making all of the Request properties available.
To replace the proxied Request object, use the set()
method:
To get the proxied Request object directly, use the get()
method:
Response Helper
Registration
To make the response helper available inside your Template, you need to register it with the Qiq HelperLocator. You can register the helper semi-automatically ...
... or you can do so more manually:
By default, the helper will construct a new internal Sapien Response object of its own. If you want to pass an existing Response object, you may do so:
Usage
Once the helper is registered, you can call it using the method name you registered it under. You can use Qiq syntax ...
... or PHP syntax:
The response helper proxies to its internal Sapien Repsonse object, making all of the Response methods available.
To replace the proxied Response object, use the set()
method:
To get the proxied Response object directly, use the get()
method:
Rendering
With typical Template usage, the code calling a Template will set the rendered template results into a Response body ...
... as well as setting version, status, headers, and cookies on the Response.
With this helper, you instead call render()
on the helper itself, passing it
the Template object to be used for content, and get back a Response
object.
The returned Response will be the one built up inside the template, complete with the version, status, headers, and cookies that were set in the template code.
Content Replacement
When you call response()->render()
, the Response content will be whatever
was rendered from a normal Template invocation.
However, you can override this behavior by calling response()->setContent(...)
and setting the content directly from inside the template code. In the following
example, the Response content will be "Hello, world!":
Specialized Responses
While you can replace the internal Response using response()->set(...)
and
exert fine control over the replacement Response, the helper provides two
convenience methods to replace the Response with specialized Sapien
responses: one for FileResponse and one for JsonResponse.
To convert the Response to a FileResponse, call response()->setFile()
:
The setFile()
method mimics the identically-named method in
FileResponse.
To convert the Response to a JsonResponse, call response()->setJson()
. The
following example puts all the current Template data into a JsonResponse:
The setJson()
method mimics the identically-named method in
JsonResponse.
Note that these methods will override any output that would normally be rendered by the template code, replacing that output with the file output or JSON output, respectively.