PHP code example of panda / jar

1. Go to this page and download the library: Download panda/jar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

panda / jar example snippets


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

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

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

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