PHPackages                             panda/jar - 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. panda/jar

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

panda/jar
=========

The Panda Jar Package.

v4.0.2(1y ago)21.5k↓100%MITPHPPHP ^8.3

Since Jun 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/PandaPlatform/jar)[ Packagist](https://packagist.org/packages/panda/jar)[ Docs](http://pandaphp.org)[ RSS](/packages/panda-jar/feed)WikiDiscussions 4.0 Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (21)Used By (0)

Panda Json API Responses (JAR) Package
======================================

[](#panda-json-api-responses-jar-package)

This is the Panda Json API Responses Package.

[![StyleCI](https://camo.githubusercontent.com/7ad0d2f7a313347d9f41a3586ea84ce53200e030c9a4de11fc4bda60dc3a8c17/68747470733a2f2f7374796c6563692e696f2f7265706f732f36313434363236382f736869656c64)](https://styleci.io/repos/61446268)[![Latest Stable Version](https://camo.githubusercontent.com/a42589d5c081dc644978492963c251016a3d71f76ca54c7096c5a683afd16fbf/68747470733a2f2f706f7365722e707567782e6f72672f70616e64612f6a61722f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/panda/jar)[![Total Downloads](https://camo.githubusercontent.com/5d738e8a2548d21e25f64e9c6bfa448c3e1503593556771fb512c4adce7d544b/68747470733a2f2f706f7365722e707567782e6f72672f70616e64612f6a61722f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/panda/jar)[![License](https://camo.githubusercontent.com/18def81faa74f70a903483b8ef41fdb9ddbba840b312ca6c7ff78e8021d07c5a/68747470733a2f2f706f7365722e707567782e6f72672f70616e64612f6a61722f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/panda/jar)

- [Introduction](#introduction)
- [Installation](#installation)
    - [Through the composer](#through-the-composer)
- [Target Audience](#target-audience)
- [Content Models](#content-models)
    - [JsonContent](#jsoncontent)
    - [EventContent](#eventcontent)
    - [XmlContent](#xmlcontent)
    - [HtmlContent](#htmlcontent)
- [Distinguishing response content](#distinguishing-response-content)

Introduction
------------

[](#introduction)

The base response object consists of a list of headers and a list of content objects. The AsyncResponse base object offers an interface for adding headers and content.

However, it does not generate the response output. The output can be json (which is also the purpose of this component) but can also be something else, like xml.

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

[](#installation)

This package is part of the [Panda Framework](https://github.com/PandaPlatform/framework) but it's also available as a single package.

### Through the composer

[](#through-the-composer)

Add the following line to your `composer.json` file:

```
"panda/jar": "^4.0"

```

Target Audience
---------------

[](#target-audience)

This library was created to facilitate the development of web applications where the ui is generated on the backend. This way we can freely build the ui using any library we need and simply push it to the frontend through the `jar` library.

The library provides the flexibility to allow the Javascript client to be dummy and have a standard response handler for all the cases. This way, we are free to determine how the content will be handled from the backend without writing any Javascript code.

The only way where we need to write some Javascript will be to handle backend-generated events towards the frontend. In this case, we have to build the frontend client to listen for specific events and include a callback.

Content Models
--------------

[](#content-models)

The jar package support a set of models that can be either `JsonContent` or `XmlContent`, which supports specific xml parsers.

Based on the needs of each application, you can use a content model that suits best for your occasion.

### JsonContent

[](#jsoncontent)

JsonContent should be used when we want to deliver simple json string to the client. The client should know how to parse the content accordingly.

Example:

```
use \Panda\Jar\Http\Response;
use \Panda\Jar\Model\Content\JsonContent;

// Create a new response
$response = new Response();

// Add Json Content
$content = (new JsonContent())->setPayload('json_payload');
$response->addResponseContent($content, 'response_content_key');
```

The above output would be something like this:

```
{
  "headers": {},
  "content": {
    "response_content_key": {
      "type": "json",
      "payload": "json_payload"
    }
  }
}
```

### EventContent

[](#eventcontent)

EventContent is a special type of JsonContent that represents an event that should be triggered to the frontend client. We can use EventContents to trigger a specific event like a redirect or any javascript action.

EventContent has two attributes:

- A name, which will be the event name
- A payload, in json format, which will be the event payload

Example:

```
use \Panda\Jar\Http\Response;
use \Panda\Jar\Model\Content\EventContent;

// Create a new response
$response = new Response();

// Add an page reload event
$content = (new EventContent())->setName('window.reload');
$response->addResponseContent($content);
```

The above output would be something like this:

```
{
  "headers": {},
  "content": {
    "0": {
      "type": "event",
      "payload": {
        "name": "window.reload",
        "value": ""
      }
    }
  }
}
```

You can catch the above event using `jQuery` like this:

```
$(document).on('window.reload', function(ev) {
    location.reload();
});
```

Or you can use an EventContent with a value and use the value as attribute to the event:

```
use \Panda\Jar\Http\Response;
use \Panda\Jar\Model\Content\EventContent;

// Create a new response
$response = new Response();

// Add a redirect event with target url
$content = (new EventContent())
    ->setName('window.redirect')
    ->setValue('https://pandaphp.org');
$response->addResponseContent($content);
```

The above output would be something like this:

```
{
  "headers": {},
  "content": {
    "0": {
      "type": "event",
      "payload": {
        "name": "window.redirect",
        "value": "https://pandaphp.org"
      }
    }
  }
}
```

You can catch the above event using `jQuery` like this:

```
$(document).on('window.redirect', function(ev, value) {
    window.location = value;
});
```

### XmlContent

[](#xmlcontent)

XmlContent is a special type of content which supports parsing DOMElements. The use of the XmlContent model is to transfer xml through json so that the client can handle it accordingly.

### HtmlContent

[](#htmlcontent)

HtmlContent is a special type of XmlContent which transfers html. It uses the same parser as the XmlContent to convert html to string and to transfer it to the client.

The HtmlContent has some extra parameters that can be set to facilitate html handling on the client side:

- A **holder**, which is a CSS selector to point out where this html is going to be placed
- A **method**, which will describe how the html will be placed into the holder
    - **Append**: it will append the html in the end of the placeholder contents
    - **Prepend**: it will prepend the html in the beginning of the placeholder contents
    - **Replace**: it will replace the placeholder's html with the given html

Example:

```
use \Panda\Jar\Http\Response;
use \Panda\Jar\Model\Content\HtmlContent;

// Create a new response
$response = new Response();

// Create DOMElement to add to the response
// The DOMElement must be assigned to a DOMDocument for parsing
$document = new DOMDocument();
$element = new DOMElement('div', 'value');
$document->appendChild($element);
$element->setAttribute('class', 'test');

// Set DOMElement payload
$htmlContent = (new HtmlContent())
    ->setMethod(HtmlContent::METHOD_APPEND)
    ->setHolder('.holder_class')
    ->setDOMElementPayload($element);

// Add content to response
$this->response->addResponseContent($htmlContent, 'b_content');
```

The above output would be something like this:

```
{
  "headers": {},
  "content": {
    "html_content": {
      "method": "append",
      "holder": ".holder_class",
      "type": "html",
      "payload": "value"
    }
  }
}
```

You can use any ui library to generate the HtmlContent. If you have access to DOMElement, it will be much easier Otherwise, you can simply provide the html as string using the `setPayload()` function.

Distinguishing response content
-------------------------------

[](#distinguishing-response-content)

The client side should be able to distinguish the content in the response from the `type` attribute. Each content should have a different type value to separate the behavior of the client's javascript code.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance42

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 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 ~165 days

Recently: every ~397 days

Total

20

Last Release

465d ago

Major Versions

v1.1.4 → v2.0.02017-05-15

v2.0.1 → v3.0.02017-10-21

v3.1.0 → v4.0.02024-10-25

PHP version history (3 changes)v1.0PHP &gt;=5.5.9

2.0.x-devPHP ^7.0

v4.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/753e0ad67caebf12b98c1f6db52014667aaa22d5c7c5b87f68f70875e9399135?d=identicon)[ioannis-papikas](/maintainers/ioannis-papikas)

---

Top Contributors

[![ioannis-papikas](https://avatars.githubusercontent.com/u/2780884?v=4)](https://github.com/ioannis-papikas "ioannis-papikas (46 commits)")

---

Tags

json-responsepanda-frameworkphp7request-response-processing

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/panda-jar/health.svg)

```
[![Health](https://phpackages.com/badges/panda-jar/health.svg)](https://phpackages.com/packages/panda-jar)
```

###  Alternatives

[illuminate/cookie

The Illuminate Cookie package.

224.3M120](/packages/illuminate-cookie)[codefog/contao-news_categories

News Categories bundle for Contao Open Source CMS

3183.3k6](/packages/codefog-contao-news-categories)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)[leapt/core-bundle

Symfony LeaptCoreBundle

2529.1k4](/packages/leapt-core-bundle)[robole/sulu-ai-translator-bundle

Translate any type of content using DeepL

181.3k](/packages/robole-sulu-ai-translator-bundle)[numero2/contao-storelocator

Contao Plugin for managing stores (or in common address data) and providing a frontend-search based on geo data

121.5k](/packages/numero2-contao-storelocator)

PHPackages © 2026

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