start pdf generation workflow

This commit is contained in:
Manuel Raynaud
2013-10-02 15:21:18 +02:00
parent 46e23c2708
commit 0116cb2891
6 changed files with 224 additions and 2 deletions

View File

@@ -38,7 +38,8 @@
"imagine/imagine": "dev-master", "imagine/imagine": "dev-master",
"symfony/icu": "1.0", "symfony/icu": "1.0",
"swiftmailer/swiftmailer": "5.0.*", "swiftmailer/swiftmailer": "5.0.*",
"symfony/serializer": "2.3.*" "symfony/serializer": "2.3.*",
"dompdf/dompdf": "dev-master"
}, },
"require-dev" : { "require-dev" : {
"phpunit/phpunit": "3.7.*", "phpunit/phpunit": "3.7.*",

78
composer.lock generated
View File

@@ -3,8 +3,49 @@
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
], ],
"hash": "097481390dc87b3482d895b3b6a65479", "hash": "39e5fa13bfa3de21f03854c90a076713",
"packages": [ "packages": [
{
"name": "dompdf/dompdf",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/dompdf/dompdf.git",
"reference": "3a8a09240159ac084f0c4b607eb12ca83ddbe318"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/3a8a09240159ac084f0c4b607eb12ca83ddbe318",
"reference": "3a8a09240159ac084f0c4b607eb12ca83ddbe318",
"shasum": ""
},
"require": {
"phenx/php-font-lib": "0.2.*"
},
"type": "library",
"autoload": {
"classmap": [
"include/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
},
{
"name": "Brian Sweeney",
"email": "eclecticgeek@gmail.com"
}
],
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
"homepage": "https://github.com/dompdf/dompdf",
"time": "2013-09-04 20:59:58"
},
{ {
"name": "imagine/imagine", "name": "imagine/imagine",
"version": "dev-master", "version": "dev-master",
@@ -208,6 +249,40 @@
"homepage": "http://leafo.net/lessphp/", "homepage": "http://leafo.net/lessphp/",
"time": "2013-08-09 17:09:19" "time": "2013-08-09 17:09:19"
}, },
{
"name": "phenx/php-font-lib",
"version": "0.2.1",
"source": {
"type": "git",
"url": "https://github.com/PhenX/php-font-lib.git",
"reference": "42a1ca6d19f14076911a118705b771c3a5a8b179"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/42a1ca6d19f14076911a118705b771c3a5a8b179",
"reference": "42a1ca6d19f14076911a118705b771c3a5a8b179",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"classes/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
}
],
"description": "A library to read, parse, export and make subsets of different types of font files.",
"homepage": "https://github.com/PhenX/php-font-lib",
"time": "2013-02-22 23:30:49"
},
{ {
"name": "propel/propel", "name": "propel/propel",
"version": "dev-master", "version": "dev-master",
@@ -2143,6 +2218,7 @@
"ptachoire/cssembed": 20, "ptachoire/cssembed": 20,
"simplepie/simplepie": 20, "simplepie/simplepie": 20,
"imagine/imagine": 20, "imagine/imagine": 20,
"dompdf/dompdf": 20,
"fzaninotto/faker": 20, "fzaninotto/faker": 20,
"maximebf/debugbar": 20 "maximebf/debugbar": 20
}, },

View File

@@ -12,6 +12,7 @@ define('THELIA_MODULE_DIR' , THELIA_LOCAL_DIR . 'modules/');
define('THELIA_WEB_DIR' , THELIA_ROOT . 'web/'); define('THELIA_WEB_DIR' , THELIA_ROOT . 'web/');
define('THELIA_TEMPLATE_DIR' , THELIA_ROOT . 'templates/'); define('THELIA_TEMPLATE_DIR' , THELIA_ROOT . 'templates/');
define('DS', DIRECTORY_SEPARATOR); define('DS', DIRECTORY_SEPARATOR);
define('DOMPDF_ENABLE_AUTOLOAD', false);
$loader = require __DIR__ . "/vendor/autoload.php"; $loader = require __DIR__ . "/vendor/autoload.php";

View File

@@ -0,0 +1,74 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\PdfEvent;
use Thelia\Core\Event\TheliaEvents;
/**
* Class Pdf
* @package Thelia\Action
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class Pdf extends BaseAction implements EventSubscriberInterface
{
public function generatePdf(PdfEvent $event)
{
require_once THELIA_ROOT . '/core/vendor/dompdf/dompdf/dompdf_config.inc.php';
$domPdf = new \DOMPDF();
$domPdf->load_html($event->getContent());
$event->setPdf($domPdf->output());
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
array(
TheliaEvents::GENERATE_PDF => array("generatePdf", 128)
);
}
}

View File

@@ -0,0 +1,68 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
/**
* Class PdfEvent
* @package Thelia\Core\Event
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class PdfEvent extends ActionEvent
{
protected $content;
protected $pdf;
public function __construct($content)
{
$this->content = $content;
}
/**
* @param mixed $content
*/
public function setContent($content)
{
$this->content = $content;
}
/**
* @return mixed
*/
public function getContent()
{
return $this->content;
}
public function setPdf($pdf)
{
$this->pdf = $pdf;
}
public function getPdf()
{
return $this->pdf;
}
}

View File

@@ -597,4 +597,6 @@ final class TheliaEvents
*/ */
const GENERATE_REWRITTENURL = 'action.generate_rewritenurl'; const GENERATE_REWRITTENURL = 'action.generate_rewritenurl';
const GENERATE_PDF = 'thelia.generatePdf';
} }