Skip to content

Commit e1d4738

Browse files
authored
Merge pull request #44 from pug-php/symfony-5
Allow Symfony 5
2 parents 1de7d58 + 03420ca commit e1d4738

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1158
-233
lines changed

.codeclimate.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
22
version: "2"
3+
exclude_patterns:
4+
- "tests/"
5+
- "templates/"
6+
- "genTravis.php"
37
plugins:
48
duplication:
59
enabled: true
6-
exclude_patterns:
7-
- "tests/"
8-
- "genTravis.php"
910
config:
1011
languages:
11-
- php
12+
- php
1213
fixme:
1314
enabled: true
1415
phpmd:

.travis.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,29 @@ matrix:
300300
env:
301301
- SYMFONY_VERSION='4.3.*'
302302
- PUG_VERSION='^3.0.0'
303-
- php: 7.4snapshot
303+
- php: 7.4
304304
env:
305305
- SYMFONY_VERSION='4.4.*'
306306
- PUG_VERSION='^3.0.0'
307+
- php: 7.4
308+
env:
309+
- STABILITY='dev'
310+
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
311+
- SYMFONY_VERSION='5.0.*'
312+
- TWIG_VERSION='^2.10.0'
313+
- PUG_VERSION='^3.0.0'
314+
- php: 7.4
315+
env:
316+
- STABILITY='dev'
317+
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
318+
- SYMFONY_VERSION='5.0.*'
319+
- TWIG_VERSION='^3.0.0'
320+
- PUG_VERSION='^3.0.0'
307321
before_script:
308322
- if [ "$REMOVE_PACKAGE" != "" ]; then travis_retry composer remove --no-update -n ${REMOVE_PACKAGE}; fi;
309323
- if [ "$REMOVE_DEV_PACKAGE" != "" ]; then travis_retry composer remove --dev --no-update -n ${REMOVE_DEV_PACKAGE}; fi;
310324
- if [ "$SYMFONY_VERSION" != "" ]; then travis_retry composer require --no-update -n symfony/symfony=$SYMFONY_VERSION; fi;
325+
- if [ "$TWIG_VERSION" != "" ]; then travis_retry composer require --no-update -n twig/twig=$TWIG_VERSION; fi;
311326
- if [ "$SYMFONY_VERSION" = "3.0.*" ]; then travis_retry composer require --no-update -n twig/twig=^1; fi;
312327
- if [ "$PUG_VERSION" != "" ]; then travis_retry composer require --no-update -n pug-php/pug=$PUG_VERSION; fi;
313328
- if [ "$STABILITY" != "" ]; then travis_retry composer config minimum-stability ${STABILITY}; fi;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
use Twig\Environment;
4+
use Twig\Source;
5+
use Twig\Template;
6+
7+
/* {{filename}} */
8+
class PugDebugTemplateTemplate extends Template
9+
{
10+
private $source;
11+
private $macros = [];
12+
13+
public function __construct(Environment $env)
14+
{
15+
parent::__construct($env);
16+
$this->source = $this->getSourceContext();
17+
$this->parent = false;
18+
$this->blocks = [];
19+
}
20+
21+
protected function doDisplay(array $context, array $blocks = [])
22+
{
23+
$macros = $this->macros;
24+
extract($context);
25+
26+
if (isset($this->extensions["Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension"])) {
27+
$__internal_1 = $this->extensions["Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension"];
28+
$__internal_1->enter($__internal_1_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template", "{{filename}}"));
29+
}
30+
31+
if (isset($this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"])) {
32+
$__internal_2 = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
33+
$__internal_2->enter($__internal_2_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template", "{{filename}}"));
34+
}
35+
36+
// {{code}}
37+
38+
if (isset($__internal_1)) {
39+
$__internal_1->leave($__internal_1_prof);
40+
}
41+
42+
if (isset($__internal_2)) {
43+
$__internal_2->leave($__internal_2_prof);
44+
}
45+
}
46+
47+
public function getTemplateName()
48+
{
49+
return "{{filename}}";
50+
}
51+
52+
public function isTraitable()
53+
{
54+
return false;
55+
}
56+
57+
public function getDebugInfo()
58+
{
59+
return [/* {{debugInfo}} */];
60+
}
61+
62+
public function getSourceContext()
63+
{
64+
return new Source("{{source}}", "{{filename}}", "{{path}}");
65+
}
66+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
use Twig\Environment;
4+
use Twig\Source;
5+
use Twig\Template;
6+
7+
/* {{filename}} */
8+
class PugTemplateTemplate extends Template
9+
{
10+
private $source;
11+
private $macros = [];
12+
13+
public function __construct(Environment $env)
14+
{
15+
parent::__construct($env);
16+
$this->source = $this->getSourceContext();
17+
$this->parent = false;
18+
$this->blocks = [];
19+
}
20+
21+
protected function doDisplay(array $context, array $blocks = [])
22+
{
23+
$macros = $this->macros;
24+
extract($context);
25+
// {{code}}
26+
}
27+
28+
public function getTemplateName()
29+
{
30+
return "{{filename}}";
31+
}
32+
33+
public function isTraitable()
34+
{
35+
return false;
36+
}
37+
38+
public function getDebugInfo()
39+
{
40+
return [/* {{debugInfo}} */];
41+
}
42+
43+
public function getSourceContext()
44+
{
45+
return new Source("", "{{filename}}", "{{path}}");
46+
}
47+
}

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
"pug/installer": "^0.1.0",
1111
"pug-php/pug": "^2.7.1 || ^3.0.0",
1212
"pug-php/pug-assets": "^1.0.1",
13-
"symfony/framework-bundle": "^2.7 || ^3.0 || ^4.0",
14-
"symfony/http-foundation": "^2.7 || ^3.0 || ^4.0",
15-
"symfony/http-kernel": "^2.7 || ^3.0 || ^4.0",
16-
"symfony/security-bundle": "^2.7 || ^3.0 || ^4.0",
17-
"symfony/templating": "^2.7 || ^3.0 || ^4.0",
18-
"symfony/twig-bridge": "^2.7 || ^3.0 || ^4.0"
13+
"symfony/framework-bundle": "^2.7 || ^3.0 || ^4.0 || ^5.0",
14+
"symfony/http-foundation": "^2.7 || ^3.0 || ^4.0 || ^5.0",
15+
"symfony/http-kernel": "^2.7 || ^3.0 || ^4.0 || ^5.0",
16+
"symfony/security-bundle": "^2.7 || ^3.0 || ^4.0 || ^5.0",
17+
"symfony/templating": "^2.7 || ^3.0 || ^4.0 || ^5.0",
18+
"symfony/twig-bridge": "^2.7 || ^3.0 || ^4.0 || ^5.0"
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^4.8.35 || ^5.7 || ~6.3.0",
2222
"symfony/phpunit-bridge": "^3.3.9, !=3.4.31",
23-
"symfony/symfony": "^2.7 || ^3.0 || ^4.0",
23+
"symfony/symfony": "^2.7 || ^3.0 || ^4.0 || ^5.0",
2424
"codeclimate/php-test-reporter": "dev-master",
2525
"composer/composer": ">=1.0.0"
2626
},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Pug\Twig;
4+
5+
/**
6+
* @codeCoverageIgnore
7+
*/
8+
class EnvironmentTwig1 extends EnvironmentBase
9+
{
10+
public function compileSource($source, $name = null)
11+
{
12+
return $this->compileSourceBase($source);
13+
}
14+
15+
public function render($name, array $context = [])
16+
{
17+
return $this->renderBase($name, array_merge($this->pugSymfonyEngine->getSharedVariables(), $context));
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Pug\Twig;
4+
5+
use Twig\Source;
6+
7+
/**
8+
* @codeCoverageIgnore
9+
*/
10+
class EnvironmentTwig2 extends EnvironmentBase
11+
{
12+
public function compileSource(Source $source)
13+
{
14+
return $this->compileSourceBase($source);
15+
}
16+
17+
public function render($name, array $context = [])
18+
{
19+
return $this->renderBase($name, array_merge($this->pugSymfonyEngine->getSharedVariables(), $context));
20+
}
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Pug\Twig;
4+
5+
use Twig\Source;
6+
use Twig\Template;
7+
8+
/**
9+
* @codeCoverageIgnore
10+
*/
11+
class EnvironmentTwig3 extends EnvironmentBase
12+
{
13+
/**
14+
* @var string[]
15+
*/
16+
protected $classNames = [];
17+
18+
public function compileSource(Source $source): string
19+
{
20+
return $this->compileSourceBase($source);
21+
}
22+
23+
public function loadTemplate(string $cls, string $name, int $index = null): Template
24+
{
25+
if ($index !== null) {
26+
$cls .= '___' . $index;
27+
}
28+
29+
$this->classNames[$name] = $cls;
30+
31+
return parent::loadTemplate($cls, $name, $index);
32+
}
33+
34+
public function render($name, array $context = []): string
35+
{
36+
return $this->renderBase($name, array_merge($this->pugSymfonyEngine->getSharedVariables(), $context));
37+
}
38+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Jade\Exceptions;
4+
5+
use RuntimeException;
6+
use Throwable;
7+
8+
class ReservedVariable extends RuntimeException
9+
{
10+
public function __construct($variableName, $code = 0, Throwable $previous = null)
11+
{
12+
parent::__construct("$variableName is a reserved variable name, you can't overwrite it.", $code, $previous);
13+
}
14+
}

src/Jade/JadeSymfonyBundle/Command/AssetsPublishCommand.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Output\OutputInterface;
88

9+
if (!class_exists('Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand')) {
10+
// @codeCoverageIgnoreStart
11+
class_alias('Jade\\JadeSymfonyBundle\\Command\\PugAwareCommand', 'Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand');
12+
// @codeCoverageIgnoreEnd
13+
}
14+
915
class AssetsPublishCommand extends ContainerAwareCommand
1016
{
1117
protected function configure()
@@ -27,6 +33,7 @@ protected function cacheTemplates($pug)
2733
$errors = 0;
2834
$errorDetails = [];
2935
$directories = [];
36+
3037
foreach ($pug->getOption('viewDirectories') as $viewDirectory) {
3138
if (is_dir($viewDirectory) && !in_array($viewDirectory, $directories)) {
3239
$directories[] = $viewDirectory;
@@ -42,17 +49,19 @@ protected function cacheTemplates($pug)
4249

4350
protected function execute(InputInterface $input, OutputInterface $output)
4451
{
45-
list($directories, $success, $errors, $errorDetails) = $this->cacheTemplates(
46-
$this->getContainer()->get('templating.engine.pug')->getEngine()
47-
);
52+
$symfonyEngine = isset($this->pugSymfonyEngine) ? $this->pugSymfonyEngine : $this->getContainer()->get('templating.engine.pug');
53+
list($directories, $success, $errors, $errorDetails) = $this->cacheTemplates($symfonyEngine->getEngine());
4854
$count = count($directories);
4955
$output->writeln($count . ' ' . ($count === 1 ? 'directory' : 'directories') . ' scanned: ' . implode(', ', $directories) . '.');
5056
$output->writeln($success . ' templates cached.');
5157
$output->writeln($errors . ' templates failed to be cached.');
58+
5259
foreach ($errorDetails as $index => $detail) {
5360
$output->writeln("\n" . ($index + 1) . ') ' . $detail['inputFile']);
5461
$output->writeln($detail['error']->getMessage());
5562
$output->writeln($detail['error']->getTraceAsString());
5663
}
64+
65+
return 0;
5766
}
5867
}

0 commit comments

Comments
 (0)