PHPackages                             qiq/helper-sapien - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. qiq/helper-sapien

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

qiq/helper-sapien
=================

Provides Qiq helpers for Sapien Request and Response objects.

2.0.1(1mo ago)2411MITPHPPHP ^8.1

Since Sep 22Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/qiqphp/helper-sapien)[ Packagist](https://packagist.org/packages/qiq/helper-sapien)[ Docs](https://github.com/qiqphp/helper-sapien)[ RSS](/packages/qiq-helper-sapien/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (6)Used By (1)

Qiq Helpers for Sapien
======================

[](#qiq-helpers-for-sapien)

This package provides [Qiq](https://qiqphp.com) helpers for [Sapien](https://sapienphp.com) *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](#request-helper)
- [the response helper](#response-helper)

Installation
------------

[](#installation)

This package is installable via Composer as [qiq/helpers-sapien](https://packagist.org/packages/qiq/helper-sapien):

```
composer require qiq/helpers-sapien ^1.0

```

Request Helper
--------------

[](#request-helper)

### Registration

[](#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 ...

```
use Qiq\Helper\Sapien\Request;
use Qiq\Template;

/** @var Template $template */
Request::register('request', $template);
```

... or you can do so more manually:

```
use Qiq\Helper\Sapien\Request;
use Qiq\Template;

/** @var Template $template */
$template->getHelperLocator()->set('request', function () {
    return new Request();
});
```

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:

```
use Qiq\Helper\Sapien\Request;
use Qiq\Template;
use Sapien\Request as SapienRequest;

/** @var Template $template */
/** @var SapienRequest $sapienRequest */
Request::register('request', $template, $sapienRequest);

// or:
$template->getHelperLocator()->set('request', function () use ($sapienRequest) {
    return new Request($sapienRequest);
});
```

### Usage

[](#usage)

Once the helper is registered, you can call it using the method name you registered it under. You can use Qiq syntax ...

```
{{ request()->... }}

```

... or PHP syntax:

```

```

The request helper proxies to its internal Sapien *Request* object, making all of the *Request* properties available.

```
The requested URL path is {{h request()->url->path }}

```

To replace the proxied *Request* object, use the `set()` method:

```
{{ request()->set(new \Sapien\Request()) }}

```

To get the proxied *Request* object directly, use the `get()` method:

```

```

Response Helper
---------------

[](#response-helper)

### Registration

[](#registration-1)

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 ...

```
use Qiq\Helper\Sapien\Response;
use Qiq\Template;

/** @var Template $template */
Response::register('response', $template);
```

... or you can do so more manually:

```
use Qiq\Helper\Sapien\Response;
use Qiq\Template;

/** @var Template $template */
$template->getHelperLocator()->set('response', function () {
    return new Response();
});
```

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:

```
use Qiq\Helper\Sapien\Response;
use Qiq\Template;
use Sapien\Response as SapienResponse;

/** @var Template $template */
/** @var SapienResponse $sapienResponse */
Response::register('response', $template, $sapienResponse);

// or:
$template->getHelperLocator()->set('response', function () use ($sapienResponse) {
    return new Response($sapienResponse);
});
```

### Usage

[](#usage-1)

Once the helper is registered, you can call it using the method name you registered it under. You can use Qiq syntax ...

```
{{ response()->... }}

```

... or PHP syntax:

```

```

The response helper proxies to its internal Sapien *Repsonse* object, making all of the *Response* methods available.

```
{{ response()->setVersion(...) }}
{{ response()->setCode(...) }}
{{ response()->setHeader(...) }}
{{ response()->setCookie(...) }}

```

To replace the proxied *Response* object, use the `set()` method:

```
{{ response()->set(new \Sapien\Response()) }}

```

To get the proxied *Response* object directly, use the `get()` method:

```

```

### Rendering

[](#rendering)

With typical *Template* usage, the code calling a *Template* will set the rendered template results into a *Response* body ...

```
/** @var \Qiq\Template $template */
$template->setData(...);
$template->setView(...);
$template->setLayout(...);
$content = $template();

/** @var \Sapien\Response $response */
$response->setContent($content);
```

... 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.

```
/** @var \Qiq\Template $template */
$template->setData(...);
$template->setView(...);
$template->setLayout(...);

/** @var \Sapien\Response $response */
$response = $template->response()->render($template);
```

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

[](#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!":

```
Goodbye, content!
{{ response()->setContent("Hello, world!") }}

```

### Specialized Responses

[](#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()`:

```
{{ response()->setFile('path/to/file.php') }}

```

The `setFile()` method mimics the identically-named method in [*FileResponse*](https://sapienphp.com/1.x/response/special.html#1-2-9-1).

To convert the *Response* to a *JsonResponse*, call `response()->setJson()`. The following example puts all the current *Template* data into a *JsonResponse*:

```
{{ response()->setJson($this->getData()) }}

```

The `setJson()` method mimics the identically-named method in [*JsonResponse*](https://sapienphp.com/1.x/response/special.html#1-2-9-2).

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.

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance91

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~320 days

Total

5

Last Release

44d ago

Major Versions

1.x-dev → 2.0.02023-06-30

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25754?v=4)[Paul M. Jones](/maintainers/pmjones)[@pmjones](https://github.com/pmjones)

---

Top Contributors

[![pmjones](https://avatars.githubusercontent.com/u/25754?v=4)](https://github.com/pmjones "pmjones (4 commits)")

---

Tags

responserequesthelpersapienqiq

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/qiq-helper-sapien/health.svg)

```
[![Health](https://phpackages.com/badges/qiq-helper-sapien/health.svg)](https://phpackages.com/packages/qiq-helper-sapien)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M686](/packages/barryvdh-laravel-ide-helper)[beste/json

A simple JSON helper to decode and encode JSON

4222.7M3](/packages/beste-json)[chillerlan/php-settings-container

A container class for immutable settings objects. Not a DI container.

3427.3M21](/packages/chillerlan-php-settings-container)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
