Skip to content

Commit

Permalink
Merge pull request #40 from pug-php/feature/symfony-4.4
Browse files Browse the repository at this point in the history
Allow Symfony 4.4
  • Loading branch information
kylekatarnls authored Nov 29, 2019
2 parents f3de94a + e92778a commit f2fbd29
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 125 deletions.
37 changes: 28 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,39 @@ matrix:
- php: 5.4
dist: trusty
env:
- PREFER_SOURCE="--prefer-source"
- REMOVE_PACKAGE="pug/installer"
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
- SYMFONY_VERSION='2.7.*'
- PUG_VERSION='^2.7.1'
- php: 5.6
env:
- REMOVE_PACKAGE="pug/installer"
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
- SYMFONY_VERSION='2.7.*'
- PUG_VERSION='^3.0.0'
- php: 5.6
env:
- REMOVE_PACKAGE="pug/installer"
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
- PREFER_SOURCE="--prefer-source"
- SYMFONY_VERSION='2.8.*'
- PUG_VERSION='^3.0.0'
- php: 5.6
env:
- REMOVE_PACKAGE="pug/installer"
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
- SYMFONY_VERSION='3.0.*'
- PUG_VERSION='^3.0.0'
- php: 5.6
env:
- REMOVE_PACKAGE="pug/installer"
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
- SYMFONY_VERSION='3.1.*'
- PUG_VERSION='^3.0.0'
- php: 5.6
env:
- REMOVE_PACKAGE="pug/installer"
- REMOVE_DEV_PACKAGE="codeclimate/php-test-reporter"
- SYMFONY_VERSION='3.2.*'
- PUG_VERSION='^3.0.0'
- php: 5.6
Expand Down Expand Up @@ -108,6 +119,10 @@ matrix:
env:
- SYMFONY_VERSION='4.2.*'
- PUG_VERSION='^3.0.0'
- php: 7.1
env:
- SYMFONY_VERSION='4.4.*'
- PUG_VERSION='^2.7.1'
- php: 7.2
env:
- SYMFONY_VERSION='2.7.*'
Expand Down Expand Up @@ -150,7 +165,7 @@ matrix:
- PUG_VERSION='^2.7.1'
- php: 7.2
env:
- SYMFONY_VERSION='4.3.x-dev'
- SYMFONY_VERSION='4.3.*'
- PUG_VERSION='^2.7.1'
- php: 7.2
env:
Expand Down Expand Up @@ -194,7 +209,7 @@ matrix:
- PUG_VERSION='^3.0.0'
- php: 7.2
env:
- SYMFONY_VERSION='4.3.x-dev'
- SYMFONY_VERSION='4.3.*'
- PUG_VERSION='^3.0.0'
- COVERAGE=true
- php: 7.3
Expand Down Expand Up @@ -239,7 +254,7 @@ matrix:
- PUG_VERSION='^2.7.1'
- php: 7.3
env:
- SYMFONY_VERSION='4.3.x-dev'
- SYMFONY_VERSION='4.3.*'
- PUG_VERSION='^2.7.1'
- php: 7.3
env:
Expand Down Expand Up @@ -283,17 +298,21 @@ matrix:
- PUG_VERSION='^3.0.0'
- php: 7.3
env:
- SYMFONY_VERSION='4.3.x-dev'
- SYMFONY_VERSION='4.3.*'
- PUG_VERSION='^3.0.0'
- php: 7.4snapshot
env:
- SYMFONY_VERSION='4.4.*'
- PUG_VERSION='^3.0.0'
before_script:
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php
- php -r "unlink('composer-setup.php');"
- if [ "$REMOVE_PACKAGE" != "" ]; then travis_retry composer remove --no-update -n ${REMOVE_PACKAGE}; fi;
- if [ "$REMOVE_DEV_PACKAGE" != "" ]; then travis_retry composer remove --dev --no-update -n ${REMOVE_DEV_PACKAGE}; fi;
- if [ "$SYMFONY_VERSION" != "" ]; then travis_retry composer require --no-update -n symfony/symfony=$SYMFONY_VERSION; fi;
- if [ "$SYMFONY_VERSION" = "3.0.*" ]; then travis_retry composer require --no-update -n twig/twig=^1; fi;
- if [ "$PUG_VERSION" != "" ]; then travis_retry composer require --no-update -n pug-php/pug=$PUG_VERSION; fi;
- if [ "$STABILITY" != "" ]; then travis_retry composer config minimum-stability ${STABILITY}; fi;
- 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;
- travis_retry php -d memory_limit=-1 composer.phar update -o --no-interaction --prefer-stable ${PREFER_SOURCE}
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update -o --no-interaction --prefer-stable
- if [ -f ~/xdebug.ini ]; then mv ~/xdebug.ini /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini; fi;
- chmod -R 0777 tests/project
script:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ option will install all settings automatically if possible.
It for any reason, you do not can or want to use it, here is how to do
a manual installation:

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

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

In production, you better have to pre-render all your templates to improve performances. To do that, you have
`Pug\PugSymfonyBundle\PugSymfonyBundle` in your registered bundles. It should be already done if you
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),
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),
[add bundle in Symfony 2 and 3](https://github.com/pug-php/pug-symfony/wiki/Symfony-2-and-3-manual-installation#appappkenelphp))

This will make the `assets:publish` command available, now each time you deploy your app, enter the command below:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"codeclimate/php-test-reporter": "dev-master",
"composer/composer": ">=1.0.0"
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"license": "MIT",
"authors": [
{
Expand Down
114 changes: 114 additions & 0 deletions polyfill/Jade/Symfony/MixedLoaderTwig2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace Jade\Symfony;

use Twig_Error_Loader;
use Twig_LoaderInterface;
use Twig_Source;

class MixedLoaderTwig2 implements Twig_LoaderInterface
{
/**
* @var Twig_LoaderInterface
*/
protected $base;

/**
* @var array
*/
protected $extraTemplates = [];

public function __construct(Twig_LoaderInterface $base)
{
$this->base = $base;
}

public function uniqueTemplate($template)
{
$name = uniqid();
$this->setTemplateSource($name, $template);

return $name;
}

public function setTemplateSource($name, $template)
{
$this->extraTemplates[$name] = $template;
}

public function getSourceContext($name)
{
if (isset($this->extraTemplates[$name])) {
return new Twig_Source($this->extraTemplates[$name], $name);
}

return $this->base->getSourceContext($name);
}

// @codeCoverageIgnoreStart
public function getSource($name)
{
return $this->getSourceContext($name)->getCode();
}

// @codeCoverageIgnoreEnd

public function __call($name, $arguments)
{
return call_user_func_array([$this->base, $name], $arguments);
}

/**
* Gets the cache key to use for the cache for a given template name.
*
* @param string $name The name of the template to load
*
* @throws Twig_Error_Loader When $name is not found
*
* @return string The cache key
*/
public function getCacheKey($name)
{
if (isset($this->extraTemplates[$name])) {
return $name;
}

return $this->base->getCacheKey($name);
}

/**
* Returns true if the template is still fresh.
*
* @param string $name The template name
* @param int $time Timestamp of the last modification time of the
* cached template
*
* @throws Twig_Error_Loader When $name is not found
*
* @return bool true if the template is fresh, false otherwise
*/
public function isFresh($name, $time)
{
if (isset($this->extraTemplates[$name])) {
return true;
}

return $this->base->isFresh($name, $time);
}

/**
* Check if we have the source code of a template, given its name.
*
* @param string $name The name of the template to check if we can load
*
* @return bool If the template source code is handled by this loader or not
*/
public function exists($name)
{
if (isset($this->extraTemplates[$name])) {
return true;
}

return $this->base->exists($name);
}
}
118 changes: 118 additions & 0 deletions polyfill/Jade/Symfony/MixedLoaderTwig3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace Jade\Symfony;

use Twig\Source;
use Twig_Error_Loader;
use Twig_LoaderInterface;

if (!class_exists('Twig\\Environment')) {
return;
}

class MixedLoaderTwig3 implements Twig_LoaderInterface
{
/**
* @var Twig_LoaderInterface
*/
protected $base;

/**
* @var array
*/
protected $extraTemplates = [];

public function __construct(Twig_LoaderInterface $base)
{
$this->base = $base;
}

public function uniqueTemplate($template)
{
$name = uniqid();
$this->setTemplateSource($name, $template);

return $name;
}

public function setTemplateSource($name, $template)
{
$this->extraTemplates[$name] = $template;
}

public function getSourceContext(string $name): Source
{
if (isset($this->extraTemplates[$name])) {
return new Source($this->extraTemplates[$name], $name);
}

return $this->base->getSourceContext($name);
}

// @codeCoverageIgnoreStart
public function getSource($name)
{
return $this->getSourceContext($name)->getCode();
}

// @codeCoverageIgnoreEnd

public function __call($name, $arguments)
{
return call_user_func_array([$this->base, $name], $arguments);
}

/**
* Gets the cache key to use for the cache for a given template name.
*
* @param string $name The name of the template to load
*
* @throws Twig_Error_Loader When $name is not found
*
* @return string The cache key
*/
public function getCacheKey(string $name): string
{
if (isset($this->extraTemplates[$name])) {
return $name;
}

return $this->base->getCacheKey($name);
}

/**
* Returns true if the template is still fresh.
*
* @param string $name The template name
* @param int $time Timestamp of the last modification time of the
* cached template
*
* @throws Twig_Error_Loader When $name is not found
*
* @return bool true if the template is fresh, false otherwise
*/
public function isFresh(string $name, $time): bool
{
if (isset($this->extraTemplates[$name])) {
return true;
}

return $this->base->isFresh($name, $time);
}

/**
* Check if we have the source code of a template, given its name.
*
* @param string $name The name of the template to check if we can load
*
* @return bool If the template source code is handled by this loader or not
*/
public function exists(string $name)
{
if (isset($this->extraTemplates[$name])) {
return true;
}

return $this->base->exists($name);
}
}
5 changes: 3 additions & 2 deletions src/Jade/JadeSymfonyEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ public function __construct($kernel)
$rootDir = dirname($appDir);
$assetsDirectories = [$appDir . '/Resources/assets'];
$viewDirectories = [$appDir . '/Resources/views'];
if ($container->has('twig') &&
($twig = $container->get('twig')) instanceof \Twig_Environment &&

if (($twig = $this->getTwig($container)) &&
($loader = $twig->getLoader()) instanceof FilesystemLoader &&
is_array($paths = $loader->getPaths()) &&
isset($paths[0])
) {
$viewDirectories[] = $paths[0];
}

$this->defaultTemplateDirectory = end($viewDirectories);
$srcDir = $rootDir . '/src';
$webDir = $rootDir . '/web';
Expand Down
Loading

0 comments on commit f2fbd29

Please sign in to comment.