Commit eb6a14be authored by Julien Neuhart's avatar Julien Neuhart
Browse files

first commit

parents
# Gotenberg demo
## Quick start
```bash
$ docker-compose up -d
```
Go to http://gotenberg-demo.localhost/vendor/mouf/mouf and configure your Mouf instance.
Voilà :metal:
vendor
\ No newline at end of file
<IfModule !mod_rewrite.c>
# Use an error page as index file. It makes sure a proper error is displayed if
# mod_rewrite is not available. Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex vendor/mouf/mvc.splash/src/rewrite_missing.php
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# .htaccess RewriteBase related tips courtesy of Symfony 2's skeleton app.
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the base directory and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# If the requested filename exists, and has an allowed extension, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .*((\.(js|ico|gif|jpg|png|css|woff|ttf|svg|eot|map)$)|^vendor) - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/vendor/mouf/mvc.splash/src/splash.php [L]
</IfModule>
\ No newline at end of file
{
"require": {
"mouf/mouf": "^2.0",
"mouf/mvc.splash": "^8.2",
"http-interop/http-middleware": "^0.4",
"mouf/database.tdbm": "^5",
"mouf/database.patcher": "^2.5",
"php-http/guzzle6-adapter": "^1.1",
"thecodingmachine/gotenberg-php-client": "^2.0.1",
"mouf/html.widgets.messageservice": "^3"
},
"prefer-stable": true,
"minimum-stability": "dev",
"autoload": {
"psr-4": { "GotenbergDemo\\": "src/" }
}
}
This diff is collapsed.
<?php
/**
* This is a file automatically generated by the Mouf framework. Do not put any code except 'define' operations
* as it could be overwritten.
* Instead, use the Mouf User Interface to set all your constants: http://[server]/vendor/mouf/mouf/mouf/config
*/
/**
* Set to true to enable debug/development mode.
*/
define('DEBUG', getenv('DEBUG') !== false?getenv('DEBUG'):true);
/**
* A random string. It should be different for any application deployed.
*/
define('SECRET', getenv('SECRET') !== false?getenv('SECRET'):'uEN1cRdnhytVnMUg9MJh');
/**
* The database host (the IP address or URL of the database server).
*/
define('DB_HOST', getenv('DB_HOST') !== false?getenv('DB_HOST'):'mysql');
/**
* The database port (the port of the database server, keep empty to use default port).
*/
define('DB_PORT', getenv('DB_PORT') !== false?getenv('DB_PORT'):'3306');
/**
* The name of your database.
*/
define('DB_NAME', getenv('DB_NAME') !== false?getenv('DB_NAME'):'gotenberg_demo');
/**
* The username to access the database.
*/
define('DB_USERNAME', getenv('DB_USERNAME') !== false?getenv('DB_USERNAME'):'demo');
/**
* The password to access the database.
*/
define('DB_PASSWORD', getenv('DB_PASSWORD') !== false?getenv('DB_PASSWORD'):'demo');
DROP TABLE document;
\ No newline at end of file
CREATE TABLE document (id INT AUTO_INCREMENT NOT NULL, file LONGBLOB NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
\ No newline at end of file
<?php
define('ROOT_PATH', realpath(__DIR__.'/..').DIRECTORY_SEPARATOR);
require_once __DIR__.'/../config.php';
if (defined('ROOT_URL')) {
define('MOUF_URL', ROOT_URL.'vendor/mouf/mouf/');
}
require_once __DIR__.'/../vendor/autoload.php';
require_once 'MoufComponents.php';
?>
\ No newline at end of file
This diff is collapsed.
<?php
/**
* This is a file automatically generated by the Mouf framework. Do not modify it, as it could be overwritten.
*/
// Files declared in the extra:mouf:adminRequire section.
require_once __DIR__.'/../vendor/mouf/database.doctrine-dbal-wrapper/src/DBALConnectionAdmin.php';
require_once __DIR__.'/../vendor/mouf/utils.patcher/src/PatchAdmin.php';
require_once __DIR__.'/../vendor/mouf/database.patcher/src/DBPatchAdmin.php';
require_once __DIR__.'/../vendor/mouf/utils.cache.cache-interface/CacheAdmin.php';
require_once __DIR__.'/../vendor/mouf/database.tdbm/src/TdbmAdmin.php';
require_once __DIR__.'/../vendor/mouf/html.utils.weblibrarymanager/src/WebLibraryAdmin.php';
require_once __DIR__.'/../vendor/mouf/mvc.splash-ui/src/SplashUiAdmin.php';
require_once __DIR__.'/../vendor/mouf/utils.cache.psr6-ui/CacheAdmin.php';
require_once __DIR__.'/../vendor/mouf/mvc.splash/src/SplashAdmin.php';
require_once __DIR__.'/../vendor/mouf/mvc.splash/src/Mouf/Mvc/Splash/SplashGenerateService.php';
require_once __DIR__.'/../vendor/mouf/mvc.splash/src/Mouf/Mvc/Splash/Controllers/Admin/SplashPurgeCacheController.php';
require_once __DIR__.'/../vendor/mouf/mvc.splash/src/Mouf/Mvc/Splash/Controllers/Admin/SplashAdminApacheConfigureController.php';
require_once __DIR__.'/../vendor/mouf/mvc.splash/src/Mouf/Mvc/Splash/Controllers/Admin/SplashInstallController.php';
?>
\ No newline at end of file
<?php
/**
* This is a file automatically generated by the Mouf framework. Do not modify it, as it could be overwritten.
* This file contains the status of all Mouf global installation processes for packages you have installed.
* If you are working with a source repository, this file should be commited.
*/
return array (
0 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Utils\\Constants\\DebugInstaller',
'package' => 'mouf/utils.constants.debug',
),
1 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Html\\Renderer\\Twig\\MoufTwigEnvironmentInstaller2',
'package' => 'mouf/html.renderer.twig-extensions',
),
2 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Utils\\Constants\\SecretInstaller',
'package' => 'mouf/utils.constants.secret',
),
3 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Utils\\Cache\\FileCacheInstaller',
'package' => 'mouf/utils.cache.file-cache',
),
4 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Utils\\Log\\Psr\\ErrorLogLoggerInstaller',
'package' => 'mouf/utils.log.psr.errorlog_logger',
),
5 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Utils\\Cache\\ApcCacheInstaller',
'package' => 'mouf/utils.cache.apc-cache',
),
6 =>
array (
'status' => 'done',
'type' => 'file',
'file' => 'src/install.php',
'package' => 'mouf/html.renderer',
),
7 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Html\\Utils\\WebLibraryManager\\WebLibraryManagerInstaller',
'package' => 'mouf/html.utils.weblibrarymanager',
),
8 =>
array (
'status' => 'done',
'type' => 'file',
'file' => 'src/install.php',
'package' => 'mouf/html.widgets.menu',
),
9 =>
array (
'status' => 'done',
'type' => 'file',
'file' => 'src/install.php',
'package' => 'mouf/utils.session.session-manager',
),
10 =>
array (
'status' => 'done',
'type' => 'file',
'file' => 'src/install.php',
'package' => 'mouf/html.widgets.messageservice',
),
11 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Html\\Template\\BootstrapTemplateInstaller',
'package' => 'mouf/html.template.bootstrap',
),
12 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Utils\\Common\\Doctrine\\Cache\\CacheInstaller',
'package' => 'mouf/utils.common.doctrine-cache-wrapper',
),
13 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Utils\\Common\\Doctrine\\Annotations\\AnnotationReaderInstaller',
'package' => 'mouf/utils.common.doctrine-annotations-wrapper',
),
14 =>
array (
'status' => 'done',
'type' => 'url',
'url' => 'splash82install/',
'package' => 'mouf/mvc.splash',
),
15 =>
array (
'status' => 'done',
'type' => 'url',
'url' => 'splash82install/writeHtAccess',
'package' => 'mouf/mvc.splash',
),
16 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Console\\ConsoleInstaller',
'package' => 'mouf/utils.console',
),
17 =>
array (
'status' => 'done',
'type' => 'url',
'url' => 'dbalconnectioninstall/',
'package' => 'mouf/database.doctrine-dbal-wrapper',
),
18 =>
array (
'status' => 'done',
'type' => 'url',
'url' => 'tdbminstall3/',
'package' => 'mouf/database.tdbm',
),
19 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Utils\\Patcher\\PatchInstaller3',
'package' => 'mouf/utils.patcher',
),
20 =>
array (
'status' => 'done',
'type' => 'class',
'class' => 'Mouf\\Database\\Patcher\\DatabasePatchInstaller3',
'package' => 'mouf/database.patcher',
),
);
\ No newline at end of file
<?php
/**
* This contains the users allowed to access the Mouf framework.
*/
$users['admin'] = array('password'=>'d033e22ae348aeb5660fc2140aec35850c4da997', 'options'=>null);
?>
\ No newline at end of file
<?php
/**
* This is a file automatically generated by the Mouf framework. Do not modify it, as it could be overwritten.
* This file contains the status of all Mouf local installation processes for packages you have installed.
* If you are working with a source repository, this file should NOT be commited.
*/
return array (
);
\ No newline at end of file
<?php
namespace GotenbergDemo\Controllers;
use GotenbergDemo\Services\GotenbergService;
use Mouf\Html\Widgets\MessageService\Service\UserMessageInterface;
use Mouf\Mvc\Splash\Annotations\Get;
use Mouf\Mvc\Splash\Annotations\Post;
use Mouf\Mvc\Splash\Annotations\Put;
use Mouf\Mvc\Splash\Annotations\Delete;
use Mouf\Mvc\Splash\Annotations\URL;
use Mouf\Html\Template\TemplateInterface;
use Mouf\Html\HtmlElement\HtmlBlock;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TheCodingMachine\Gotenberg\ClientException;
use \Twig_Environment;
use Mouf\Html\Renderer\Twig\TwigTemplate;
use Mouf\Mvc\Splash\HtmlResponse;
use Zend\Diactoros\Response\RedirectResponse;
class RootController {
/**
* The template used by this controller.
* @var TemplateInterface
*/
private $template;
/**
* The main content block of the page.
* @var HtmlBlock
*/
private $content;
/**
* The Twig environment (used to render Twig templates).
* @var Twig_Environment
*/
private $twig;
/** @var GotenbergService */
private $gotenbergService;
/**
* Controller's constructor.
* @param TemplateInterface $template The template used by this controller
* @param HtmlBlock $content The main content block of the page
* @param Twig_Environment $twig The Twig environment (used to render Twig templates)
* @param GotenbergService $gotenbergService
*/
public function __construct(TemplateInterface $template, HtmlBlock $content, Twig_Environment $twig, GotenbergService $gotenbergService)
{
$this->template = $template;
$this->content = $content;
$this->twig = $twig;
$this->gotenbergService = $gotenbergService;
}
/**
* @URL("/")
*/
public function index()
{
$this->content->addHtmlElement(new TwigTemplate($this->twig, 'views/root/index.twig'));
return new HtmlResponse($this->template);
}
/**
* @URL("/store-document")
* @Post()
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function store(ServerRequestInterface $request): ResponseInterface
{
try {
$documents = $this->gotenbergService->createDocumentsFromRequest($request);
$filePath = $this->gotenbergService->store($documents);
set_user_message("Resulting PDF was save in $filePath", UserMessageInterface::SUCCESS);
} catch (\Exception $e) {
set_user_message($e->getCode() . ' - ' . $e->getMessage(), UserMessageInterface::ERROR);
} catch (\Http\Client\Exception $e) {
set_user_message($e->getCode() . ' - ' . $e->getMessage(), UserMessageInterface::ERROR);
}
return new RedirectResponse(ROOT_URL);
}
/**
* @URL("/store-document-in-db")
* @Post()
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function storeInDB(ServerRequestInterface $request): ResponseInterface
{
try {
$documents = $this->gotenbergService->createDocumentsFromRequest($request);
$id = $this->gotenbergService->storeInDB($documents);
set_user_message("Resulting PDF was save in table document with id = $id", UserMessageInterface::SUCCESS);
} catch (\Exception $e) {
set_user_message($e->getCode() . ' - ' . $e->getMessage(), UserMessageInterface::ERROR);
} catch (\Http\Client\Exception $e) {
set_user_message($e->getCode() . ' - ' . $e->getMessage(), UserMessageInterface::ERROR);
}
return new RedirectResponse(ROOT_URL);
}
/**
* @URL("/forward")
* @Post()
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function forward(ServerRequestInterface $request): ResponseInterface
{
try {
$documents = $this->gotenbergService->createDocumentsFromRequest($request);
return $response = $this->gotenbergService->forward($documents);
} catch (\Exception $e) {
set_user_message($e->getCode() . ' - ' . $e->getMessage(), UserMessageInterface::ERROR);
} catch (\Http\Client\Exception $e) {
set_user_message($e->getCode() . ' - ' . $e->getMessage(), UserMessageInterface::ERROR);
}
return new RedirectResponse(ROOT_URL);
}
}
<?php
/*
* This file has been automatically generated by TDBM.
* You can edit this file as it will not be overwritten.
*/
declare(strict_types=1);
namespace GotenbergDemo\Dao\Bean;
use GotenbergDemo\Dao\Bean\Generated\DocumentBaseBean;
/**
* The DocumentBean class maps the 'document' table in database.
*/
class DocumentBean extends DocumentBaseBean
{
}
<?php
declare(strict_types=1);
namespace GotenbergDemo\Dao\Bean\Generated;
use TheCodingMachine\TDBM\ResultIterator;
use TheCodingMachine\TDBM\AlterableResultIterator;
use Ramsey\Uuid\Uuid;
use TheCodingMachine\TDBM\AbstractTDBMObject;
/*
* This file has been automatically generated by TDBM.
* DO NOT edit this file, as it might be overwritten.
* If you need to perform changes, edit the DocumentBean class instead!
*/
/**
* The DocumentBaseBean class maps the 'document' table in database.
*/
abstract class DocumentBaseBean extends AbstractTDBMObject implements \JsonSerializable
{
/**
* The constructor takes all compulsory arguments.
*
* @param resource $file
*/
public function __construct($file)
{
parent::__construct();
$this->setFile($file);
}
/**
* The getter for the "id" column.
*
* @return int|null
*/
public function getId() : ?int
{
return $this->get('id', 'document');
}
/**
* The setter for the "id" column.
*
* @param int $id
*/
public function setId(int $id) : void
{
$this->set('id', $id, 'document');
}
/**
* The getter for the "file" column.
*
* @return resource
*/
public function getFile()
{
return $this->get('file', 'document');
}
/**
* The setter for the "file" column.
*
* @param resource $file
*/
public function setFile($file) : void
{
if (!\is_resource($file)) {
throw \TheCodingMachine\TDBM\TDBMInvalidArgumentException::badType('resource', $file, __METHOD__);
}
$this->set('file', $file, 'document');
}
/**
* Serializes the object for JSON encoding.
*
* @param bool $stopRecursion Parameter used internally by TDBM to stop embedded objects from embedding other objects.
* @return array
*/
public function jsonSerialize($stopRecursion = false)
{
$array = [];
$array['id'] = $this->getId();
return $array;
}
/**
* Returns an array of used tables by this bean (from parent to child relationship).
*
* @return string[]
*/
protected function getUsedTables() : array
{
return [ 'document' ];
}
}
<?php
/*
* This file has been automatically generated by TDBM.
* You can edit this file as it will not be overwritten.
*/
declare(strict_types=1);
namespace GotenbergDemo\Dao;
use GotenbergDemo\Dao\Generated\DocumentBaseDao;
/**
* The DocumentDao class will maintain the persistence of DocumentBean class into the document table.
*/
class DocumentDao extends DocumentBaseDao
{
}
<?php
declare(strict_types=1);
/*
* This file has been automatically generated by TDBM.
* DO NOT edit this file, as it might be overwritten.
*/
namespace GotenbergDemo\Dao\Generated;
use GotenbergDemo\Dao\DocumentDao;
/**
* The DaoFactory provides an easy access to all DAOs generated by TDBM.
*
*/
class DaoFactory
{
/**
* @var DocumentDao
*/
private $documentDao;