cleaned up the code

This commit is contained in:
Fabien Potencier
2019-08-12 09:23:06 +02:00
parent d937ff1f91
commit ba8f7a5e4c
7 changed files with 16 additions and 65 deletions
+2 -3
View File
@@ -59,10 +59,9 @@ final class HtmlExtension extends AbstractExtension
$this->mimeTypes = new MimeTypes();
}
$tmp = tempnam(sys_get_temp_dir(), 'mime');
file_put_contents($tmp, $data);
try {
$tmp = tempnam(sys_get_temp_dir(), 'mime');
file_put_contents($tmp, $data);
if (null === $mime = $this->mimeTypes->guessMimeType($tmp)) {
$mime = 'text/plain';
}
@@ -1,29 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Extra\Inky\Bundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class TwigInkyExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('inky.xml');
}
}
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<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">
<services>
<defaults public="false" />
<service id="twig.extension.inky" class="Twig\Inky\InkyExtension">
<tag name="twig.extension" />
</service>
</services>
</container>
@@ -1,18 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Extra\Inky\Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class TwigInkyBundle extends Bundle
{
}
+2 -1
View File
@@ -12,6 +12,7 @@
namespace Twig\Extra\Inky;
use Pinky;
use Twig\Error\RuntimeError;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
@@ -27,5 +28,5 @@ class InkyExtension extends AbstractExtension
function twig_inky(string $body): string
{
return Pinky\transformString($body)->saveHTML();
return false === ($html = Pinky\transformString($body)->saveHTML()) ? '' : $html;
}
+8
View File
@@ -15,9 +15,17 @@
],
"require": {
"php": "^7.1.3",
"symfony/framework-bundle": "^4.3|^5.0",
"symfony/twig-bundle": "^4.3|^5.0",
"twig/twig": "^2.4|^3.0"
},
"require-dev": {
"twig/cssinliner-extra": "^2.12|^3.0@dev",
"twig/html-extra": "^2.12@dev|^3.0@dev",
"twig/inky-extra": "^2.12@dev|^3.0@dev",
"twig/intl-extra": "^2.12@dev|^3.0@dev",
"twig/markdown-extra": "^2.12@dev|^3.0@dev"
},
"autoload": {
"psr-4" : {
"Twig\\Extra\\TwigExtraBundle\\" : "src/"
@@ -34,6 +34,7 @@ final class Extensions
'class_name' => 'MarkdownExtension',
'package' => 'twig/markdown-extra',
'filters' => ['html_to_markdown', 'markdown_to_html'],
'functions' => [],
],
'intl' => [
'name' => 'intl',
@@ -45,6 +46,7 @@ final class Extensions
'format_percent_number', 'format_scientific_number', 'format_spellout_number', 'format_ordinal_number',
'format_duration_number', 'format_date', 'format_datetime', 'format_time',
],
'functions' => [],
],
'cssinliner' => [
'name' => 'cssinliner',
@@ -52,6 +54,7 @@ final class Extensions
'class_name' => 'CssInlinerExtension',
'package' => 'twig/cssinliner-extra',
'filters' => ['inline_css'],
'functions' => [],
],
'inky' => [
'name' => 'inky',
@@ -59,6 +62,7 @@ final class Extensions
'class_name' => 'InkyExtension',
'package' => 'twig/inky-extra',
'filters' => ['inky'],
'functions' => [],
],
];