Initial commit
This commit is contained in:
commit
2ab3df4ba8
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/composer.lock
|
||||||
|
/vendor
|
26
composer.json
Normal file
26
composer.json
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"name": "noccylabs/gd-label-bundle",
|
||||||
|
"description": "Bundle to integrate noccylabs/gd-label with symfony 3",
|
||||||
|
"type": "bundle",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Christopher Vagnetoft",
|
||||||
|
"email": "cvagnetoft@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"noccylabs/gd-label": "@dev"
|
||||||
|
},
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "composer",
|
||||||
|
"url": "https://packages.noccylabs.info/composer/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"NoccyLabs\\GdLabelBundle\\": "src/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
src/Command/RenderCommand.php
Normal file
34
src/Command/RenderCommand.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Bundle\GdLabelBundle\Command;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
|
||||||
|
class RenderCommand extends ContainerAwareCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName("label:render");
|
||||||
|
$this->setDescription("Render a label");
|
||||||
|
$this->addOption("define", "D", InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, "key=value pairs to pass to use in the template");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$renderer = $this->getContainer()->get("gdlabel.renderer");
|
||||||
|
|
||||||
|
$params = [];
|
||||||
|
foreach ($input->getOption("define") as $opt) {
|
||||||
|
list ($key, $value) = explode("=", $opt, 2);
|
||||||
|
$params[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $renderer->renderToData("@InventoryBundle/Resources/labels/inventoryreceipt.xml", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
src/DependencyInjection/Configuration.php
Normal file
29
src/DependencyInjection/Configuration.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Bundle\GdLabelBundle\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/configuration.html}
|
||||||
|
*/
|
||||||
|
class Configuration implements ConfigurationInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getConfigTreeBuilder()
|
||||||
|
{
|
||||||
|
$treeBuilder = new TreeBuilder();
|
||||||
|
$rootNode = $treeBuilder->root('noccy_labs_gd_label');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
28
src/DependencyInjection/NoccyLabsGdLabelExtension.php
Normal file
28
src/DependencyInjection/NoccyLabsGdLabelExtension.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Bundle\GdLabelBundle\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.
|
||||||
|
*
|
||||||
|
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
|
||||||
|
*/
|
||||||
|
class NoccyLabsGdLabelExtension 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');
|
||||||
|
}
|
||||||
|
}
|
48
src/GdLabel/LabelRendererService.php
Normal file
48
src/GdLabel/LabelRendererService.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Bundle\GdLabelBundle\GdLabel;
|
||||||
|
|
||||||
|
use NoccyLabs\GdLabel\Renderer;
|
||||||
|
|
||||||
|
class LabelRendererService
|
||||||
|
{
|
||||||
|
/** @var object */
|
||||||
|
protected $kernel;
|
||||||
|
/** @var Renderer */
|
||||||
|
protected $renderer;
|
||||||
|
|
||||||
|
public function __construct($kernel)
|
||||||
|
{
|
||||||
|
$this->kernel = $kernel;
|
||||||
|
$this->renderer = new Renderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderToData($template, array $params=[])
|
||||||
|
{
|
||||||
|
$path = $this->kernel->locateResource($template);
|
||||||
|
|
||||||
|
$wd = getcwd();
|
||||||
|
chdir(dirname($path));
|
||||||
|
$gd = $this->renderer->renderFile($path, $params);
|
||||||
|
chdir($wd);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
imagepng($gd);
|
||||||
|
$binary = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$data = base64_encode($binary);
|
||||||
|
return sprintf("data:%s;%s,%s", "image/png", "base64", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderToFile($template, $output, array $params=[])
|
||||||
|
{
|
||||||
|
$path = $this->kernel->locateResource($template);
|
||||||
|
|
||||||
|
$wd = getcwd();
|
||||||
|
chdir(dirname($path));
|
||||||
|
$this->renderer->renderFile($path, $params, $output);
|
||||||
|
chdir($wd);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
9
src/NoccyLabsGdLabelBundle.php
Normal file
9
src/NoccyLabsGdLabelBundle.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Bundle\GdLabelBundle;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
|
|
||||||
|
class NoccyLabsGdLabelBundle extends Bundle
|
||||||
|
{
|
||||||
|
}
|
7
src/Resources/config/services.yml
Normal file
7
src/Resources/config/services.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
gdlabel.renderer:
|
||||||
|
class: NoccyLabs\Bundle\GdLabelBundle\GdLabel\LabelRendererService
|
||||||
|
arguments: [ "@kernel" ]
|
||||||
|
# noccy_labs_gd_label.example:
|
||||||
|
# class: NoccyLabs\Bundle\GdLabelBundle\Example
|
||||||
|
# arguments: ["@service_id", "plain_value", "%parameter%"]
|
Loading…
Reference in New Issue
Block a user