Skip to content

Commit

Permalink
Upgrade snappy to v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Albin Kerouanton committed Sep 20, 2017
1 parent 1d3a89d commit 2a959b5
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 47 deletions.
12 changes: 8 additions & 4 deletions DependencyInjection/KnpSnappyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,34 @@ public function load(array $configs, ContainerBuilder $container)

if ($config['pdf']['enabled']) {
$loader->load('pdf.xml');

$container->setParameter('knp_snappy.pdf.binary', $config['pdf']['binary']);
$container->setParameter('knp_snappy.pdf.options', $config['pdf']['options']);
$container->setParameter('knp_snappy.pdf.env', $config['pdf']['env']);

if (!empty($config['temporary_folder'])) {
$container->findDefinition('knp_snappy.pdf.internal_generator')
$container->findDefinition('knp_snappy.pdf')
->addMethodCall('setTemporaryFolder', [$config['temporary_folder']]);
}
if (!empty($config['process_timeout'])) {
$container->findDefinition('knp_snappy.pdf.internal_generator')
$container->findDefinition('knp_snappy.pdf')
->addMethodCall('setTimeout', [$config['process_timeout']]);
}
}

if ($config['image']['enabled']) {
$loader->load('image.xml');

$container->setParameter('knp_snappy.image.binary', $config['image']['binary']);
$container->setParameter('knp_snappy.image.options', $config['image']['options']);
$container->setParameter('knp_snappy.image.env', $config['image']['env']);

if (!empty($config['temporary_folder'])) {
$container->findDefinition('knp_snappy.image.internal_generator')
$container->findDefinition('knp_snappy.image')
->addMethodCall('setTemporaryFolder', [$config['temporary_folder']]);
}
if (!empty($config['process_timeout'])) {
$container->findDefinition('knp_snappy.image.internal_generator')
$container->findDefinition('knp_snappy.image')
->addMethodCall('setTimeout', [$config['process_timeout']]);
}
}
Expand Down
22 changes: 6 additions & 16 deletions Resources/config/image.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="knp_snappy.image.internal_generator.class">Knp\Snappy\Image</parameter>
<parameter key="knp_snappy.image.class">Knp\Bundle\SnappyBundle\Snappy\Generator\LoggableGenerator</parameter>
</parameters>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>

<service id="knp_snappy.image.internal_generator" class="%knp_snappy.image.internal_generator.class%" public="false">
<service id="knp_snappy.image" class="Knp\Snappy\Image" public="false">
<argument>%knp_snappy.image.binary%</argument>
<argument>%knp_snappy.image.options%</argument>
<argument>%knp_snappy.image.env%</argument>
</service>

<service id="knp_snappy.image" class="%knp_snappy.image.class%">
<argument type="service" id="knp_snappy.image.internal_generator" />
<argument type="service" id="logger" on-invalid="null" />
<call method="setLogger">
<argument type="service" id="logger" on-invalid="ignore" />
</call>
<tag name="monolog.logger" channel="snappy" />
</service>

</services>

</container>
18 changes: 4 additions & 14 deletions Resources/config/pdf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="knp_snappy.pdf.internal_generator.class">Knp\Snappy\Pdf</parameter>
<parameter key="knp_snappy.pdf.class">Knp\Bundle\SnappyBundle\Snappy\Generator\LoggableGenerator</parameter>
</parameters>

<services>

<service id="knp_snappy.pdf.internal_generator" class="%knp_snappy.pdf.internal_generator.class%" public="false">
<service id="knp_snappy.pdf" class="Knp\Snappy\Pdf" public="false">
<argument>%knp_snappy.pdf.binary%</argument>
<argument>%knp_snappy.pdf.options%</argument>
<argument>%knp_snappy.pdf.env%</argument>
</service>

<service id="knp_snappy.pdf" class="%knp_snappy.pdf.class%">
<argument type="service" id="knp_snappy.pdf.internal_generator" />
<argument type="service" id="logger" on-invalid="null" />
<call method="setLogger">
<argument type="service" id="logger" on-invalid="ignore" />
</call>
<tag name="monolog.logger" channel="snappy" />
</service>

</services>

</container>
23 changes: 12 additions & 11 deletions Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

class FunctionalTest extends \PHPUnit_Framework_TestCase
{
/** @var TestKernel */
private $kernel;

/** @var Filesystem */
private $filesystem;

public function setUp()
Expand All @@ -22,7 +25,7 @@ public function tearDown()
$this->filesystem->remove($this->kernel->getCacheDir());
}

public function testServicesAreBothAvailableOutOfTheBox()
public function testServiceIsAvailableOutOfTheBox()
{
$this->kernel->setConfigurationFilename(__DIR__ . '/fixtures/config/out_of_the_box.yml');
$this->kernel->boot();
Expand All @@ -33,17 +36,15 @@ public function testServicesAreBothAvailableOutOfTheBox()

$pdf = $container->get('knp_snappy.pdf');

$this->assertInstanceof('Knp\Bundle\SnappyBundle\Snappy\Generator\LoggableGenerator', $pdf);
$this->assertInstanceof('Knp\Snappy\Pdf', $pdf->getInternalGenerator());
$this->assertEquals('wkhtmltopdf', $pdf->getInternalGenerator()->getBinary());
$this->assertInstanceof('Knp\Snappy\Pdf', $pdf);
$this->assertEquals('wkhtmltopdf', $pdf->getBinary());

$this->assertTrue($container->has('knp_snappy.image'), 'The image service is available.');

$image = $container->get('knp_snappy.image');

$this->assertInstanceof('Knp\Bundle\SnappyBundle\Snappy\Generator\LoggableGenerator', $image);
$this->assertInstanceof('Knp\Snappy\Image', $image->getInternalGenerator());
$this->assertEquals('wkhtmltoimage', $image->getInternalGenerator()->getBinary());
$this->assertInstanceof('Knp\Snappy\Image', $image);
$this->assertEquals('wkhtmltoimage', $image->getBinary());
}

public function testChangeBinaries()
Expand All @@ -57,13 +58,13 @@ public function testChangeBinaries()

$pdf = $container->get('knp_snappy.pdf');

$this->assertEquals('/custom/binary/for/wkhtmltopdf', $pdf->getInternalGenerator()->getBinary());
$this->assertEquals('/custom/binary/for/wkhtmltopdf', $pdf->getBinary());

$this->assertTrue($container->has('knp_snappy.image'));

$image = $container->get('knp_snappy.image');

$this->assertEquals('/custom/binary/for/wkhtmltoimage', $image->getInternalGenerator()->getBinary());
$this->assertEquals('/custom/binary/for/wkhtmltoimage', $image->getBinary());
}

public function testChangeTemporaryFolder()
Expand All @@ -74,10 +75,10 @@ public function testChangeTemporaryFolder()
$container = $this->kernel->getContainer();

$pdf = $container->get('knp_snappy.pdf');
$this->assertEquals('/path/to/the/tmp', $pdf->getInternalGenerator()->getTemporaryFolder());
$this->assertEquals('/path/to/the/tmp', $pdf->getTemporaryFolder());

$image = $container->get('knp_snappy.image');
$this->assertEquals('/path/to/the/tmp', $image->getInternalGenerator()->getTemporaryFolder());
$this->assertEquals('/path/to/the/tmp', $image->getTemporaryFolder());
}

public function testDisablePdf()
Expand Down
3 changes: 3 additions & 0 deletions Tests/Snappy/Generator/LoggableGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Knp\Bundle\SnappyBundle\Snappy\Generator\LoggableGenerator;

/**
* @group legacy
*/
class LoggableGeneratorTest extends \PHPUnit_Framework_TestCase
{
public function testGenerate()
Expand Down
21 changes: 20 additions & 1 deletion Tests/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Knp\Bundle\SnappyBundle\Tests;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

class TestKernel extends Kernel
class TestKernel extends Kernel implements CompilerPassInterface
{
private $configurationFilename;

Expand Down Expand Up @@ -37,4 +39,21 @@ public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->configurationFilename);
}

protected function prepareContainer(ContainerBuilder $container)
{
parent::prepareContainer($container);

$container->addCompilerPass($this);
}

public function process(ContainerBuilder $container)
{
if ($container->has('knp_snappy.pdf')) {
$container->findDefinition('knp_snappy.pdf')->setPublic(true);
}
if ($container->has('knp_snappy.image')) {
$container->findDefinition('knp_snappy.image')->setPublic(true);
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require": {
"php": ">=5.6",
"symfony/framework-bundle": "~2.7|~3.0",
"knplabs/knp-snappy": "~0.1"
"knplabs/knp-snappy": "~1.0"
},

"require-dev": {
Expand Down

3 comments on commit 2a959b5

@LiSinCin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question.
You switch knp-snappy from ~0.1 to ~1.0, which is major I think.
And wrapper library have only minor version change.
Is normal practice? Is there some reason for that?

reagards,

@Einenlum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LiSinCin. It actually depends if your own API (in this case, the API of the bundle) changes. If not, no need of a major release. Semver is pretty clear about this case: http://semver.org/#what-should-i-do-if-i-update-my-own-dependencies-without-changing-the-public-api

@akerouanton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no major changes in the library, but we thought it was time to release the first stable version ever because pretty much nothing has changed in the past two years. As said by @Einenlum, no BC change on the bundle was needed so a minor version is fine. But I disallowed knp-snappy < 1.0 to be used with the v1.5 of the bundle because I moved the logging capability to the generators and have deprecated LoggableGenerator.

Please sign in to comment.