Skip to content

Commit

Permalink
Merge pull request FriendsOfSymfony#2028 from alexander-schranz/patch-1
Browse files Browse the repository at this point in the history
Use twig as templating engine when available
  • Loading branch information
Tobion authored Oct 31, 2019
2 parents 4a5b6f8 + 2eafea5 commit 7705fa0
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 12 deletions.
6 changes: 5 additions & 1 deletion DependencyInjection/Compiler/ConfigurationCheckPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public function process(ContainerBuilder $container)
}

if (!$container->has((string) $container->getAlias('fos_rest.templating'))) {
$container->removeAlias('fos_rest.templating');
if ($container->has('twig')) {
$container->setAlias('fos_rest.templating', 'twig');
} else {
$container->removeAlias('fos_rest.templating');
}
}
}
}
10 changes: 9 additions & 1 deletion Tests/Functional/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ public function testDisabledTemplating()
$this->assertFalse($container->has('fos_rest.templating'));
}

public function testEnabledTemplatingWithTwig()
{
$kernel = self::bootKernel(['test_case' => 'ConfigurationWithTwig']);
$container = $kernel->getContainer();

$this->assertTrue($container->has('fos_rest.templating'));
}

public function testToolbar()
{
$client = $this->createClient(['test_case' => 'Configuration']);
$client = $this->createClient(['test_case' => 'ConfigurationWithTwig']);
$client->request(
'GET',
'/_profiler/empty/search/results?limit=10',
Expand Down
11 changes: 10 additions & 1 deletion Tests/Functional/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

use Psr\Log\NullLogger;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Kernel;
Expand All @@ -49,7 +50,7 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class AppKernel extends Kernel
class AppKernel extends Kernel implements CompilerPassInterface
{
private $testCase;
private $rootConfig;
Expand Down Expand Up @@ -121,4 +122,12 @@ protected function getKernelParameters()

return $parameters;
}

public function process(ContainerBuilder $container)
{
// Avoid inlining of fos_rest.templating service to test if service really exist
if ($container->has('fos_rest.templating')) {
$container->getAlias('fos_rest.templating')->setPublic(true);
}
}
}
2 changes: 0 additions & 2 deletions Tests/Functional/app/Configuration/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(),
new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
new \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new \FOS\RestBundle\FOSRestBundle(),
Expand Down
8 changes: 1 addition & 7 deletions Tests/Functional/app/Configuration/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ framework:
fos_rest:
view:
mime_types: true
view_response_listener: true
view_response_listener: false
param_fetcher_listener: true
disable_csrf_role: foo
allowed_methods_listener: true
Expand All @@ -26,9 +26,3 @@ fos_rest:
rules:
- { path: '^/', priorities: ['xml'], fallback_format: ~ }
versioning: true

web_profiler:
toolbar: true

twig:
strict_variables: '%kernel.debug%'
20 changes: 20 additions & 0 deletions Tests/Functional/app/ConfigurationWithTwig/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(),
new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
new \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new \FOS\RestBundle\FOSRestBundle(),
new \FOS\RestBundle\Tests\Functional\Bundle\TestBundle\TestBundle(),
];
12 changes: 12 additions & 0 deletions Tests/Functional/app/ConfigurationWithTwig/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
imports:
- { resource: ../Configuration/config.yml }

fos_rest:
view:
view_response_listener: true

web_profiler:
toolbar: false

twig:
strict_variables: '%kernel.debug%'
7 changes: 7 additions & 0 deletions Tests/Functional/app/ConfigurationWithTwig/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_wdt:
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt

_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
23 changes: 23 additions & 0 deletions Tests/Functional/app/ConfigurationWithTwig/security.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\Controller\UserValueResolver;

$defaultFirewall = [
'anonymous' => null,
];

if (method_exists(Security::class, 'getUser') && !class_exists(UserValueResolver::class)) {
$defaultFirewall['logout_on_user_change'] = true;
}

$container->loadFromExtension('security', [
'providers' => [
'in_memory' => [
'memory' => null,
],
],
'firewalls' => [
'default' => $defaultFirewall,
],
]);

0 comments on commit 7705fa0

Please sign in to comment.