Skip to content

Commit

Permalink
EZP-31220: Migrated codebase to Symfony 5 (#26)
Browse files Browse the repository at this point in the history
* Symfony 5 compatibility

* Symfony 5 compatibility

* Changed kernel.root_dir -> kernel.project_dir

* Aligned to interface changes in TwigDataCollector

* Aligned to interface changes in TwigThemeLoader

* Added symfony-cmf/routing fork

* Removed obsolete repositories

* Fixed TemplatePathRegistryTest unit test

* Fixed code style

* Prepared composer.json for release
  • Loading branch information
webhdx authored Mar 18, 2020
1 parent c06474d commit 2373144
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bundle/DataCollector/TwigDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private function getTemplatePathRegistry()
return $this->templatePathRegistry;
}

public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
parent::collect($request, $response, $exception);
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getConfigTreeBuilder()
->booleanNode('enabled')->defaultValue('%kernel.debug%')->info('Activates PHPStorm support')->end()
->scalarNode('twig_config_path')
->info('Path where to store PHPStorm configuration file for additional Twig namespaces (ide-twig.json).')
->defaultValue('%kernel.root_dir%/..')
->defaultValue('%kernel.project_dir%')
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
namespace EzSystems\EzPlatformDesignEngineBundle\DependencyInjection;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class EzPlatformDesignEngineExtension extends Extension
{
Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:

ezdesign.template_path_registry:
class: EzSystems\EzPlatformDesignEngine\Templating\TemplatePathRegistry
arguments: ["%kernel.root_dir%"]
arguments: ["%kernel.project_dir%"]

ezdesign.twig_theme_loader:
class: EzSystems\EzPlatformDesignEngine\Templating\Twig\TwigThemeLoader
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
}
],
"require": {
"ezsystems/doctrine-dbal-schema": "^1.0@dev",
"ezsystems/ezpublish-kernel": "^8.0@dev",
"twig/twig": "^2.11",
"symfony/dependency-injection": "^4.3",
"symfony/http-kernel": "^4.3",
"symfony/http-foundation": "^4.3",
"symfony/config": "^4.3",
"symfony/finder": "^4.3",
"symfony/filesystem": "^4.3",
"symfony/asset": "^4.3",
"symfony/templating": "^4.3"
"twig/twig": "^3.0",
"symfony/dependency-injection": "^5.0",
"symfony/http-kernel": "^5.0",
"symfony/http-foundation": "^5.0",
"symfony/config": "^5.0",
"symfony/finder": "^5.0",
"symfony/filesystem": "^5.0",
"symfony/asset": "^5.0",
"symfony/templating": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^8.1",
Expand Down
8 changes: 4 additions & 4 deletions doc/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ezdesign:
templates_theme_paths:
# FOSUserBundle templates will be part of "my_theme" theme
my_theme:
- '%kernel.root_dir%/../vendor/friendsofsymfony/user-bundle/Resources/views'
- '%kernel.project_dir%/vendor/friendsofsymfony/user-bundle/Resources/views'
```

> **Paths precedence**: Directories following the convention will **always** have precedence over the ones defined
Expand All @@ -78,7 +78,7 @@ It is possible to add additional global override directories.
```yaml
ezdesign:
templates_override_paths:
- "%kernel.root_dir%/another_override_directory"
- "%kernel.project_dir%/another_override_directory"
- "/some/other/directory"
```

Expand All @@ -90,7 +90,7 @@ for `goto` actions.
`EzPlatformDesignEngine` will generate a `ide-twig.json` file which will contain all detected theme paths for templates in your project.
It is activated by default in debug mode (`%kernel.debug%`).

By default, this config file will be stored at your project root (`%kernel.root_dir%/..`), but you can customize the path
By default, this config file will be stored at your project root (`%kernel.project_dir%`), but you can customize the path
if your PHPStorm project root doesn't match your Symfony project root.

> Note: `ide-twig.json` **must** be stored at your PHPStorm project root.
Expand All @@ -104,5 +104,5 @@ ezdesign:
enabled: '%kernel.debug%'
# Path where to store PHPStorm configuration file for additional Twig namespaces (ide-twig.json).
twig_config_path: '%kernel.root_dir%/..'
twig_config_path: '%kernel.project_dir%'
```
2 changes: 1 addition & 1 deletion doc/upgrade/UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ However, if still needed, it can be achieved by the following configuration:
```yaml
ezdesign:
templates_override_paths:
- '%kernel.root_dir%/app/Resources/views'
- '%kernel.project_dir%%/templates'
```
1 change: 0 additions & 1 deletion lib/Asset/AssetPathProvisionerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface AssetPathProvisionerInterface
* Returns an map with asset logical path as key and its resolved path (relative to webroot dir) as value.
* Example => ['images/foo.png' => 'asset/themes/some_theme/images/foo.png'].
*
* @param array $assetsPaths
* @param string $design
*
* @return array
Expand Down
2 changes: 1 addition & 1 deletion lib/Templating/TemplatePathRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($kernelRootDir)

public function mapTemplatePath($templateName, $path)
{
$this->pathMap[$templateName] = str_replace(\dirname($this->kernelRootDir) . '/', '', $path);
$this->pathMap[$templateName] = str_replace($this->kernelRootDir . '/', '', $path);
}

public function getTemplatePath($templateName)
Expand Down
10 changes: 5 additions & 5 deletions lib/Templating/Twig/TwigThemeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
use EzSystems\EzPlatformDesignEngine\Templating\TemplatePathRegistryInterface;
use Twig\Loader\FilesystemLoader;
use Twig\Loader\LoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\Source;

/**
* Decorates regular Twig FilesystemLoader.
* It resolves generic @ezdesign namespace to the actual current namespace.
*/
class TwigThemeLoader implements LoaderInterface, SourceContextLoaderInterface
class TwigThemeLoader implements LoaderInterface
{
/**
* @var TemplateNameResolverInterface
Expand Down Expand Up @@ -56,20 +56,20 @@ public function getSource($name)
return $this->innerFilesystemLoader->getSource($this->nameResolver->resolveTemplateName($name));
}

public function getSourceContext($name)
public function getSourceContext(string $name): Source
{
$source = $this->innerFilesystemLoader->getSourceContext($this->nameResolver->resolveTemplateName((string)$name));
$this->pathRegistry->mapTemplatePath($source->getName(), $source->getPath());

return $source;
}

public function getCacheKey($name)
public function getCacheKey(string $name): string
{
return $this->innerFilesystemLoader->getCacheKey($this->nameResolver->resolveTemplateName($name));
}

public function isFresh($name, $time)
public function isFresh(string $name, int $time): bool
{
return $this->innerFilesystemLoader->isFresh($this->nameResolver->resolveTemplateName($name), $time);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Asset/AssetPathResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

use EzSystems\EzPlatformDesignEngine\Asset\AssetPathResolver;
use EzSystems\EzPlatformDesignEngine\Exception\InvalidDesignException;
use PHPUnit\Framework\TestCase;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class AssetPathResolverTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Templating/TemplatePathRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TemplatePathRegistryTest extends TestCase
{
private function getExpectedRelativePath($templateFullPath, $kernelRootDir)
{
return str_replace(\dirname($kernelRootDir) . '/', '', $templateFullPath);
return str_replace($kernelRootDir . '/', '', $templateFullPath);
}

public function testMapTemplatePath()
Expand Down

0 comments on commit 2373144

Please sign in to comment.