Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit ead127c87b94890c519043118a975f060045f851 0 parents
Stefan Blanke authored
29 DependencyInjection/Configuration.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Spraed\PDFGeneratorBundle\DependencyInjection;
+
+use Symfony\Component\Config\Definition\Builder\TreeBuilder;
+use Symfony\Component\Config\Definition\ConfigurationInterface;
+
+/**
+ * This is the class that validates and merges configuration from your app/config files
+ *
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
+ */
+class Configuration implements ConfigurationInterface
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function getConfigTreeBuilder()
+ {
+ $treeBuilder = new TreeBuilder();
+ $rootNode = $treeBuilder->root('spraed_pdf_generator');
+
+ // Here you should define the parameters that are allowed to
+ // configure your bundle. See the documentation linked above for
+ // more information on that topic.
+
+ return $treeBuilder;
+ }
+}
31 DependencyInjection/SpraedPDFGeneratorExtension.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Spraed\PDFGeneratorBundle\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+use Symfony\Component\DependencyInjection\Loader;
+
+
+/**
+ * This is the class that loads and manages your bundle configuration
+ *
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
+ */
+class SpraedPDFGeneratorExtension extends Extension
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function load(array $configs, ContainerBuilder $container)
+ {
+ $configuration = new Configuration();
+ $config = $this->processConfiguration($configuration, $configs);
+
+ $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader->load('services.yml');
+
+
+ }
+}
43 PDFGenerator/PDFGenerator.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Spraed\PDFGeneratorBundle\PDFGenerator;
+class PDFGenerator {
+
+ public function generatePDF($html, $pdfFile = null) {
+
+ if ($pdfFile === null) {
+ $pdfFile = 'output';
+ }
+
+ $pdfFile = $this->createTemporaryFile($pdfFile, 'pdf');
+ $htmlFile = $this->createTemporaryFile('pdf_html', 'html', $html);
+
+ $command = $this->buildCommand($htmlFile, $pdfFile);
+
+ var_dump($command);
+ exit();
+
+ $result = $this->generate($htmlFile, $pdfFile);
+
+ unlink($htmlFile);
+ }
+
+ private function buildCommand($htmlFile, $pdfFile) {
+ $command = 'java -jar ';
+ $command .= __DIR__ . '/../Resources/java/spraed-pdf-generator.jar ';
+ $command .= $htmlFile . ' ' . $pdfFile;
+
+ return $command;
+ }
+
+ private function createTemporaryFile($filename, $extension, $content = null) {
+ $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid($filename)
+ . '.' . $extension;
+
+ if (null !== $content) {
+ file_put_contents($file, $content);
+ }
+
+ return $file;
+ }
+}
5 Resources/config/services.yml
@@ -0,0 +1,5 @@
+services:
+ spraed.pdf.generator:
+ class: Spraed\PDFGeneratorBundle\PDFGenerator\PdfGenerator
+
+
BIN  Resources/java/spraed-pdf-generator.jar
Binary file not shown
9 SpraedPDFGeneratorBundle.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Spraed\PDFGeneratorBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class SpraedPDFGeneratorBundle extends Bundle
+{
+}
Please sign in to comment.
Something went wrong with that request. Please try again.