Skip to content

Commit f2fbd29

Browse files
authored
Merge pull request #40 from pug-php/feature/symfony-4.4
Allow Symfony 4.4
2 parents f3de94a + e92778a commit f2fbd29

File tree

10 files changed

+362
-125
lines changed

10 files changed

+362
-125
lines changed

Diff for: .travis.yml

+28-9
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,39 @@ matrix:
88
- php: 5.4
99
dist: trusty
1010
env:
11-
- PREFER_SOURCE="--prefer-source"
11+
- REMOVE_PACKAGE="pug/installer"
12+
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
1213
- SYMFONY_VERSION='2.7.*'
1314
- PUG_VERSION='^2.7.1'
1415
- php: 5.6
1516
env:
17+
- REMOVE_PACKAGE="pug/installer"
18+
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
1619
- SYMFONY_VERSION='2.7.*'
1720
- PUG_VERSION='^3.0.0'
1821
- php: 5.6
1922
env:
23+
- REMOVE_PACKAGE="pug/installer"
24+
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
2025
- PREFER_SOURCE="--prefer-source"
2126
- SYMFONY_VERSION='2.8.*'
2227
- PUG_VERSION='^3.0.0'
2328
- php: 5.6
2429
env:
30+
- REMOVE_PACKAGE="pug/installer"
31+
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
2532
- SYMFONY_VERSION='3.0.*'
2633
- PUG_VERSION='^3.0.0'
2734
- php: 5.6
2835
env:
36+
- REMOVE_PACKAGE="pug/installer"
37+
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
2938
- SYMFONY_VERSION='3.1.*'
3039
- PUG_VERSION='^3.0.0'
3140
- php: 5.6
3241
env:
42+
- REMOVE_PACKAGE="pug/installer"
43+
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
3344
- SYMFONY_VERSION='3.2.*'
3445
- PUG_VERSION='^3.0.0'
3546
- php: 5.6
@@ -108,6 +119,10 @@ matrix:
108119
env:
109120
- SYMFONY_VERSION='4.2.*'
110121
- PUG_VERSION='^3.0.0'
122+
- php: 7.1
123+
env:
124+
- SYMFONY_VERSION='4.4.*'
125+
- PUG_VERSION='^2.7.1'
111126
- php: 7.2
112127
env:
113128
- SYMFONY_VERSION='2.7.*'
@@ -150,7 +165,7 @@ matrix:
150165
- PUG_VERSION='^2.7.1'
151166
- php: 7.2
152167
env:
153-
- SYMFONY_VERSION='4.3.x-dev'
168+
- SYMFONY_VERSION='4.3.*'
154169
- PUG_VERSION='^2.7.1'
155170
- php: 7.2
156171
env:
@@ -194,7 +209,7 @@ matrix:
194209
- PUG_VERSION='^3.0.0'
195210
- php: 7.2
196211
env:
197-
- SYMFONY_VERSION='4.3.x-dev'
212+
- SYMFONY_VERSION='4.3.*'
198213
- PUG_VERSION='^3.0.0'
199214
- COVERAGE=true
200215
- php: 7.3
@@ -239,7 +254,7 @@ matrix:
239254
- PUG_VERSION='^2.7.1'
240255
- php: 7.3
241256
env:
242-
- SYMFONY_VERSION='4.3.x-dev'
257+
- SYMFONY_VERSION='4.3.*'
243258
- PUG_VERSION='^2.7.1'
244259
- php: 7.3
245260
env:
@@ -283,17 +298,21 @@ matrix:
283298
- PUG_VERSION='^3.0.0'
284299
- php: 7.3
285300
env:
286-
- SYMFONY_VERSION='4.3.x-dev'
301+
- SYMFONY_VERSION='4.3.*'
302+
- PUG_VERSION='^3.0.0'
303+
- php: 7.4snapshot
304+
env:
305+
- SYMFONY_VERSION='4.4.*'
287306
- PUG_VERSION='^3.0.0'
288307
before_script:
289-
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
290-
- php composer-setup.php
291-
- php -r "unlink('composer-setup.php');"
308+
- if [ "$REMOVE_PACKAGE" != "" ]; then travis_retry composer remove --no-update -n ${REMOVE_PACKAGE}; fi;
309+
- if [ "$REMOVE_DEV_PACKAGE" != "" ]; then travis_retry composer remove --dev --no-update -n ${REMOVE_DEV_PACKAGE}; fi;
292310
- if [ "$SYMFONY_VERSION" != "" ]; then travis_retry composer require --no-update -n symfony/symfony=$SYMFONY_VERSION; fi;
293311
- if [ "$SYMFONY_VERSION" = "3.0.*" ]; then travis_retry composer require --no-update -n twig/twig=^1; fi;
294312
- if [ "$PUG_VERSION" != "" ]; then travis_retry composer require --no-update -n pug-php/pug=$PUG_VERSION; fi;
313+
- if [ "$STABILITY" != "" ]; then travis_retry composer config minimum-stability ${STABILITY}; fi;
295314
- if [ -f /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then mv /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ~/xdebug.ini; fi;
296-
- travis_retry php -d memory_limit=-1 composer.phar update -o --no-interaction --prefer-stable ${PREFER_SOURCE}
315+
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update -o --no-interaction --prefer-stable
297316
- if [ -f ~/xdebug.ini ]; then mv ~/xdebug.ini /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini; fi;
298317
- chmod -R 0777 tests/project
299318
script:

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ option will install all settings automatically if possible.
2020
It for any reason, you do not can or want to use it, here is how to do
2121
a manual installation:
2222

23-
- [Symfony 4 manual installation](https://github.com/pug-php/pug-symfony/wiki/Symfony-4-manual-installation)
23+
- [Symfony 4+ manual installation](https://github.com/pug-php/pug-symfony/wiki/Symfony-4-manual-installation)
2424
- [Symfony 2 and 3 manual installation](https://github.com/pug-php/pug-symfony/wiki/Symfony-2-and-3-manual-installation)
2525

2626
If you installed Symfony in a custom way, you might be warned about
@@ -84,7 +84,7 @@ public function contactAction()
8484

8585
In production, you better have to pre-render all your templates to improve performances. To do that, you have
8686
`Pug\PugSymfonyBundle\PugSymfonyBundle` in your registered bundles. It should be already done if you
87-
followed the automated install with success. Else check installation instructions ([add bundle in Symfony 4](https://github.com/pug-php/pug-symfony/wiki/Symfony-4-manual-installation#configbundlesphp),
87+
followed the automated install with success. Else check installation instructions ([add bundle in Symfony 4+](https://github.com/pug-php/pug-symfony/wiki/Symfony-4-manual-installation#configbundlesphp),
8888
[add bundle in Symfony 2 and 3](https://github.com/pug-php/pug-symfony/wiki/Symfony-2-and-3-manual-installation#appappkenelphp))
8989

9090
This will make the `assets:publish` command available, now each time you deploy your app, enter the command below:

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"codeclimate/php-test-reporter": "dev-master",
2525
"composer/composer": ">=1.0.0"
2626
},
27-
"minimum-stability": "dev",
27+
"minimum-stability": "stable",
2828
"license": "MIT",
2929
"authors": [
3030
{

Diff for: polyfill/Jade/Symfony/MixedLoaderTwig2.php

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
namespace Jade\Symfony;
4+
5+
use Twig_Error_Loader;
6+
use Twig_LoaderInterface;
7+
use Twig_Source;
8+
9+
class MixedLoaderTwig2 implements Twig_LoaderInterface
10+
{
11+
/**
12+
* @var Twig_LoaderInterface
13+
*/
14+
protected $base;
15+
16+
/**
17+
* @var array
18+
*/
19+
protected $extraTemplates = [];
20+
21+
public function __construct(Twig_LoaderInterface $base)
22+
{
23+
$this->base = $base;
24+
}
25+
26+
public function uniqueTemplate($template)
27+
{
28+
$name = uniqid();
29+
$this->setTemplateSource($name, $template);
30+
31+
return $name;
32+
}
33+
34+
public function setTemplateSource($name, $template)
35+
{
36+
$this->extraTemplates[$name] = $template;
37+
}
38+
39+
public function getSourceContext($name)
40+
{
41+
if (isset($this->extraTemplates[$name])) {
42+
return new Twig_Source($this->extraTemplates[$name], $name);
43+
}
44+
45+
return $this->base->getSourceContext($name);
46+
}
47+
48+
// @codeCoverageIgnoreStart
49+
public function getSource($name)
50+
{
51+
return $this->getSourceContext($name)->getCode();
52+
}
53+
54+
// @codeCoverageIgnoreEnd
55+
56+
public function __call($name, $arguments)
57+
{
58+
return call_user_func_array([$this->base, $name], $arguments);
59+
}
60+
61+
/**
62+
* Gets the cache key to use for the cache for a given template name.
63+
*
64+
* @param string $name The name of the template to load
65+
*
66+
* @throws Twig_Error_Loader When $name is not found
67+
*
68+
* @return string The cache key
69+
*/
70+
public function getCacheKey($name)
71+
{
72+
if (isset($this->extraTemplates[$name])) {
73+
return $name;
74+
}
75+
76+
return $this->base->getCacheKey($name);
77+
}
78+
79+
/**
80+
* Returns true if the template is still fresh.
81+
*
82+
* @param string $name The template name
83+
* @param int $time Timestamp of the last modification time of the
84+
* cached template
85+
*
86+
* @throws Twig_Error_Loader When $name is not found
87+
*
88+
* @return bool true if the template is fresh, false otherwise
89+
*/
90+
public function isFresh($name, $time)
91+
{
92+
if (isset($this->extraTemplates[$name])) {
93+
return true;
94+
}
95+
96+
return $this->base->isFresh($name, $time);
97+
}
98+
99+
/**
100+
* Check if we have the source code of a template, given its name.
101+
*
102+
* @param string $name The name of the template to check if we can load
103+
*
104+
* @return bool If the template source code is handled by this loader or not
105+
*/
106+
public function exists($name)
107+
{
108+
if (isset($this->extraTemplates[$name])) {
109+
return true;
110+
}
111+
112+
return $this->base->exists($name);
113+
}
114+
}

Diff for: polyfill/Jade/Symfony/MixedLoaderTwig3.php

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
namespace Jade\Symfony;
4+
5+
use Twig\Source;
6+
use Twig_Error_Loader;
7+
use Twig_LoaderInterface;
8+
9+
if (!class_exists('Twig\\Environment')) {
10+
return;
11+
}
12+
13+
class MixedLoaderTwig3 implements Twig_LoaderInterface
14+
{
15+
/**
16+
* @var Twig_LoaderInterface
17+
*/
18+
protected $base;
19+
20+
/**
21+
* @var array
22+
*/
23+
protected $extraTemplates = [];
24+
25+
public function __construct(Twig_LoaderInterface $base)
26+
{
27+
$this->base = $base;
28+
}
29+
30+
public function uniqueTemplate($template)
31+
{
32+
$name = uniqid();
33+
$this->setTemplateSource($name, $template);
34+
35+
return $name;
36+
}
37+
38+
public function setTemplateSource($name, $template)
39+
{
40+
$this->extraTemplates[$name] = $template;
41+
}
42+
43+
public function getSourceContext(string $name): Source
44+
{
45+
if (isset($this->extraTemplates[$name])) {
46+
return new Source($this->extraTemplates[$name], $name);
47+
}
48+
49+
return $this->base->getSourceContext($name);
50+
}
51+
52+
// @codeCoverageIgnoreStart
53+
public function getSource($name)
54+
{
55+
return $this->getSourceContext($name)->getCode();
56+
}
57+
58+
// @codeCoverageIgnoreEnd
59+
60+
public function __call($name, $arguments)
61+
{
62+
return call_user_func_array([$this->base, $name], $arguments);
63+
}
64+
65+
/**
66+
* Gets the cache key to use for the cache for a given template name.
67+
*
68+
* @param string $name The name of the template to load
69+
*
70+
* @throws Twig_Error_Loader When $name is not found
71+
*
72+
* @return string The cache key
73+
*/
74+
public function getCacheKey(string $name): string
75+
{
76+
if (isset($this->extraTemplates[$name])) {
77+
return $name;
78+
}
79+
80+
return $this->base->getCacheKey($name);
81+
}
82+
83+
/**
84+
* Returns true if the template is still fresh.
85+
*
86+
* @param string $name The template name
87+
* @param int $time Timestamp of the last modification time of the
88+
* cached template
89+
*
90+
* @throws Twig_Error_Loader When $name is not found
91+
*
92+
* @return bool true if the template is fresh, false otherwise
93+
*/
94+
public function isFresh(string $name, $time): bool
95+
{
96+
if (isset($this->extraTemplates[$name])) {
97+
return true;
98+
}
99+
100+
return $this->base->isFresh($name, $time);
101+
}
102+
103+
/**
104+
* Check if we have the source code of a template, given its name.
105+
*
106+
* @param string $name The name of the template to check if we can load
107+
*
108+
* @return bool If the template source code is handled by this loader or not
109+
*/
110+
public function exists(string $name)
111+
{
112+
if (isset($this->extraTemplates[$name])) {
113+
return true;
114+
}
115+
116+
return $this->base->exists($name);
117+
}
118+
}

Diff for: src/Jade/JadeSymfonyEngine.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ public function __construct($kernel)
6969
$rootDir = dirname($appDir);
7070
$assetsDirectories = [$appDir . '/Resources/assets'];
7171
$viewDirectories = [$appDir . '/Resources/views'];
72-
if ($container->has('twig') &&
73-
($twig = $container->get('twig')) instanceof \Twig_Environment &&
72+
73+
if (($twig = $this->getTwig($container)) &&
7474
($loader = $twig->getLoader()) instanceof FilesystemLoader &&
7575
is_array($paths = $loader->getPaths()) &&
7676
isset($paths[0])
7777
) {
7878
$viewDirectories[] = $paths[0];
7979
}
80+
8081
$this->defaultTemplateDirectory = end($viewDirectories);
8182
$srcDir = $rootDir . '/src';
8283
$webDir = $rootDir . '/web';

0 commit comments

Comments
 (0)