Merge branch '2.x' into 3.x

* 2.x:
  fixed wrong class usage
  made a class final
  added suggestions for extra extensions
  fixed path
  added missing dep
  fixed Travis config
  fixed config/ directory in extra bundle
  Revamping bundle structure to not mix source code with config files
  Fix PHPDoc of twig_get_attribute()
This commit is contained in:
Fabien Potencier
2019-08-10 14:59:35 +02:00
14 changed files with 109 additions and 12 deletions
+3 -1
View File
@@ -3,6 +3,7 @@ language: php
cache:
directories:
- vendor
- extra/*/vendor
- $HOME/.composer/cache/files
before_install:
@@ -11,11 +12,12 @@ before_install:
install:
- travis_retry composer install
- (cd extra/html-extra && travis_retry composer install)
- (cd extra/markdown-extra && travis_retry composer install)
script:
- ./vendor/bin/simple-phpunit
- (cd extra/html-extra && ./vendor/bin/simple-phpunit)
- (cd extra/markdown-extra && travis_retry composer install)
- (cd extra/markdown-extra && ./vendor/bin/simple-phpunit)
jobs:
fast_finish: true
@@ -15,7 +15,7 @@ use League\HTMLToMarkdown\HtmlConverter;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class MarkdownExtension extends AbstractExtension
final class MarkdownExtension extends AbstractExtension
{
public function getFilters()
{
+1 -1
View File
@@ -17,7 +17,7 @@ class MichelfMarkdown implements MarkdownInterface
{
private $converter;
public function __construct(CommonMarkConverter $converter = null)
public function __construct(MarkdownExtra $converter = null)
{
if (null === $converter) {
$converter = new MarkdownExtra();
+2 -1
View File
@@ -15,11 +15,12 @@
],
"require": {
"php": "^7.1.3",
"symfony/twig-bundle": "^4.3|^5.0",
"twig/twig": "^2.4|^3.0"
},
"autoload": {
"psr-4" : {
"Twig\\Extra\\TwigExtraBundle\\" : ""
"Twig\\Extra\\TwigExtraBundle\\" : "src/"
}
},
"autoload-dev": {
+2 -6
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
@@ -20,11 +20,7 @@
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
@@ -0,0 +1,29 @@
<?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\TwigExtraBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class MissingExtensionSuggestorPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if ($container->getParameter('kernel.debug')) {
$container->getDefinition('twig')
->addMethodCall('registerUndefinedFilterCallback', [[new Reference('twig.missing_extension_suggestor'), 'suggestFilter']])
->addMethodCall('registerUndefinedFunctionCallback', [[new Reference('twig.missing_extension_suggestor'), 'suggestFunction']])
;
}
}
}
@@ -23,10 +23,14 @@ class TwigExtraExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
if ($container->getParameter('kernel.debug')) {
$loader->load('suggestor.xml');
}
if ($this->isConfigEnabled($container, $config['html'])) {
$loader->load('html.xml');
}
@@ -0,0 +1,45 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Extra\TwigExtraBundle;
use Twig\Error\SyntaxError;
final class MissingExtensionSuggestor
{
private const FILTERS = [
'data_uri' => ['HtmlExtension', 'twig/html-extra'],
'markdown_to_html' => ['MarkdownExtension', 'twig/markdown-extra'],
'html_to_markdown' => ['MarkdownExtension', 'twig/markdown-extra'],
];
private const FUNCTIONS = [
'html_classes' => ['HtmlExtension', 'twig/html-extra'],
];
public function suggestFilter(string $name): bool
{
if (isset(self::FILTERS[$name])) {
throw new SyntaxError(sprintf('The "%s" filter is part of the %s, which is not installed/enabled; try running "composer require %s twig/extra-bundle".', $name, self::FILTERS[$name][0], self::FILTERS[$name][1]));
}
return false;
}
public function suggestFunction(string $name): bool
{
if (isset(self::FUNCTIONS[$name])) {
throw new SyntaxError(sprintf('The "%s" function is part of the %s, which is not installed/enabled; try running "composer require %s twig/extra-bundle".', $name, self::FILTERS[$name][0], self::FILTERS[$name][1]));
}
return false;
}
}
@@ -0,0 +1,12 @@
<?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.missing_extension_suggestor" class="Twig\Extra\TwigExtraBundle\MissingExtensionSuggestor" />
</services>
</container>
@@ -11,8 +11,16 @@
namespace Twig\Extra\TwigExtraBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Twig\Extra\TwigExtraBundle\DependencyInjection\Compiler\MissingExtensionSuggestorPass;
class TwigExtraBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new MissingExtensionSuggestorPass());
}
}
+1 -1
View File
@@ -1542,7 +1542,7 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar
*
* @param array|Traversable $array An array
* @param mixed $name The column name
* @param mixed îndex The column to use as the index/keys for the returned array
* @param mixed $index The column to use as the index/keys for the returned array
*
* @return array The array of values
*/