2017 © Pedro Peláez
 

library douglas

Douglas PHP library for running Jasper Reports using their report REST API (v2)

image

zacharyrankin/douglas

Douglas PHP library for running Jasper Reports using their report REST API (v2)

  • Tuesday, November 10, 2015
  • by zacharyrankin
  • Repository
  • 2 Watchers
  • 7 Stars
  • 13,112 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 6 Versions
  • 7 % Grown

The README.md

Douglas

Build Status Dependency Status, (*1)

Douglas PHP library for running Jasper Reports using their report REST API (v2), (*2)

Installing via Composer

I recommend you install Douglas using Composer., (*3)

# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add Douglas as a dependency
php composer.phar require zacharyrankin/Douglas:1.*

After installing, be sure to require Composer's autoload.php:, (*4)

require 'vendor/autoload.php';

Installing via phar

Downlad the latest phar and include it in your application, (*5)

<?php
require 'douglas.phar';

Usage

Here is an extensive example of how I use this, (*6)

<?php

use \Douglas\Request\Report as Report;
use \Douglas\Request\Asset as Asset;

// Add exception handling for invalid formats
$format = Report::getFormat($_GET['format']);

// I normally encrypt this and store it in the database and pass it around
$jasper_url = 'http://jasperadmin:jasperadmin@localhost:8443/jasperserver/';

// Create a new Report object that should point to a jasper report
$report = new Report(
    array(
        'jasper_url' => $jasper_url,
        // The report URL is the full resource path in Jasper
        'report_url' => '/organizations/demo/Reports/TestReport',
        // These parameters get passed automatically to your report, there 
        // are also some Jasper specific parameters you can pass as well
        'parameters' => array(
            'gender' => 'M',
            'year'   => 2014
        ),
        // This is the format you want the report to be returned as
        'format'     => $format,
    )
);

// This can be used for storing reports locally before giving them to the user
$file_name = "{$report->getPrettyUrl()}.{$format}";

// Make the request to Jasper
$report->send();

if ($report->getError()) {
    // Check to see if the request was successful or not
    // and do something nice with the error
}

if (Report::FORMAT_HTML === $format) {
    // This will request the HTML from jasper and run a callback on every
    // asset jasper returns.  This is REQUIRED because the urls that jasper
    // sends back are not web accessible and need to have the jsessionid 
    // cookie injected before being requested
    $html = $report->getHtml(
        function($asset_url, $jsessionid) use ($jasper_url) {

            // I like to request every asset from jasper, re-save them 
            // locally so I can do caching, reloading, etc and not have 
            // to rely on Jasper
            $asset = new Asset(
                array(
                    'jasper_url' => $jasper_url,
                    'jsessionid' => $jsessionid,
                    'asset_url'  => $asset_url,
                )
            );
            $asset->send();

            // I like to only save images, though Jasper will sometimes
            // send back javascript files like jquery
            if ($asset->getHeader('content-type') != 'image/png') {
                return false;
            }

            $asset_file_name = sprintf('jasper_report_asset_%s', uniqid());
            $full_asset_path = "../images/{$asset_file_name}";

            $asset_fh = fopen($full_asset_path, 'w');
            fwrite($asset_fh, $asset->getBody());
            fclose($asset_fh);
            return "/{$asset_file_name}.png";
        }
    );
} else {
    $body = $report->getBody();
    // Output the PDF or Excel here
}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Unit Testing

Install PHPUnit using composer php composer.phar install --dev and then you can run the tests using vendor/bin/phpunit, (*7)

Coding Standards

Stick to PSR-2, (*8)

I recommend running PHP Code Sniffer with PSR-2 Standards by running phpcs --standard=PSR2 ./, (*9)

The Versions

10/11 2015

dev-master

9999999-dev http://github.com/zacharyrankin/douglas

Douglas PHP library for running Jasper Reports using their report REST API (v2)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php report jasper jasperserver

10/11 2015

v1.2

1.2.0.0 http://github.com/zacharyrankin/douglas

Douglas PHP library for running Jasper Reports using their report REST API (v2)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php report jasper jasperserver

03/02 2015

v1.1.2

1.1.2.0 http://github.com/zacharyrankin/douglas

Douglas PHP library for running Jasper Reports using their report REST API (v2)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php report jasper jasperserver

23/03 2014

v1.1.1

1.1.1.0 http://github.com/zacharyrankin/douglas

Douglas PHP library for running Jasper Reports using their report REST API (v2)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php report jasper jasperserver

13/03 2014

v1.1.0

1.1.0.0 http://github.com/zacharyrankin/douglas

Douglas PHP library for running Jasper Reports using their report REST API (v2)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php report jasper jasperserver

01/11 2013

v1.0.0

1.0.0.0 http://github.com/zacharyrankin/douglas

Douglas PHP library for running Jasper Reports using their report REST API (v2)

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php report jasper jasperserver