Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit 929b5e8

Browse files
Resolved Symfony 4 deprecations (#90)
* Resolved Symfony 4 deprecations
1 parent 9091fde commit 929b5e8

File tree

75 files changed

+490
-276
lines changed

Some content is hidden

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

75 files changed

+490
-276
lines changed

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
php:
1313
- '7.1'
1414
- '7.2'
15+
- '7.3'
1516
- nightly
1617

1718
matrix:
@@ -24,6 +25,10 @@ matrix:
2425
env: COMPOSER_FLAGS="--prefer-lowest"
2526
- php: 7.2
2627
env: COMPOSER_FLAGS=""
28+
- php: 7.3
29+
env: COMPOSER_FLAGS="--prefer-lowest"
30+
- php: 7.3
31+
env: COMPOSER_FLAGS=""
2732
allow_failures:
2833
- php: nightly
2934

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"twig/twig": "^2.7.2"
1212
},
1313
"require-dev": {
14-
"hostnet/phpcs-tool": "^8.3.2",
15-
"phpunit/phpunit": "^6.2.2",
14+
"hostnet/phpcs-tool": "^8.3.3",
15+
"phpunit/phpunit": "^7.5.9",
1616
"symfony/phpunit-bridge": "^3.3.2"
1717
},
1818
"conflict": {

src/Bundle/DependencyInjection/Configuration.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getConfigTreeBuilder()
6262
*
6363
* @param NodeBuilder $node
6464
*/
65-
private function addNodeJSConfiguration(NodeBuilder $node)
65+
private function addNodeJSConfiguration(NodeBuilder $node): void
6666
{
6767
$node
6868
->arrayNode('node')
@@ -102,7 +102,7 @@ private function addNodeJSConfiguration(NodeBuilder $node)
102102
*
103103
* @param NodeBuilder $node
104104
*/
105-
private function addParentConfiguration(NodeBuilder $node)
105+
private function addParentConfiguration(NodeBuilder $node): void
106106
{
107107
$this->applyConfigurationFromClass(ConfigInterface::class, $node);
108108
}
@@ -112,7 +112,7 @@ private function addParentConfiguration(NodeBuilder $node)
112112
*
113113
* @param NodeBuilder $node
114114
*/
115-
private function addBundleConfiguration(NodeBuilder $node)
115+
private function addBundleConfiguration(NodeBuilder $node): void
116116
{
117117
$node
118118
->arrayNode('bundles')
@@ -128,7 +128,7 @@ private function addBundleConfiguration(NodeBuilder $node)
128128
/**
129129
* @param NodeBuilder $node
130130
*/
131-
private function addPluginConfiguration(NodeBuilder $node)
131+
private function addPluginConfiguration(NodeBuilder $node): void
132132
{
133133
$children = $node
134134
->arrayNode('plugins')
@@ -144,7 +144,7 @@ private function addPluginConfiguration(NodeBuilder $node)
144144
*
145145
* @param NodeBuilder $node
146146
*/
147-
private function addLoaderConfiguration(NodeBuilder $node)
147+
private function addLoaderConfiguration(NodeBuilder $node): void
148148
{
149149
$children = $node
150150
->arrayNode('loaders')
@@ -159,7 +159,7 @@ private function addLoaderConfiguration(NodeBuilder $node)
159159
* @param string $interface
160160
* @param NodeBuilder $node_builder
161161
*/
162-
private function applyConfigurationFromClass($interface, NodeBuilder $node_builder)
162+
private function applyConfigurationFromClass($interface, NodeBuilder $node_builder): void
163163
{
164164
foreach ($this->plugins as $name => $class_name) {
165165
// Only accept plugins of type PluginInterface.

src/Bundle/DependencyInjection/WebpackExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function load(array $config, ContainerBuilder $container)
6868
* @codeCoverageIgnore The outcome and coverage of this method solely depends on which platform PHP is running on.
6969
* @return string
7070
*/
71-
private function getPlatformKey()
71+
private function getPlatformKey(): string
7272
{
7373
$platform = PHP_OS;
7474

src/Bundle/EventListener/RequestListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(CacheGuard $guard)
3434
*
3535
* @param GetResponseEvent $event the response to send to te browser, we don't we only ensure the cache is there.
3636
*/
37-
public function onRequest(GetResponseEvent $event)
37+
public function onRequest(GetResponseEvent $event): void
3838
{
3939
if (! $event->isMasterRequest()) {
4040
return;

src/Bundle/Resources/config/webpack.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ services:
2323
- '@Hostnet\Component\Webpack\Asset\Tracker'
2424
- '@logger'
2525

26+
Hostnet\Component\Webpack\Asset\TemplateFinder:
27+
arguments:
28+
- '@kernel'
29+
- '%kernel.root_dir%/Resources'
30+
2631
Hostnet\Component\Webpack\Asset\Tracker:
2732
public: true
2833
arguments:
2934
- '@Hostnet\Component\Webpack\Profiler\Profiler'
30-
- '@templating.finder'
35+
- '@Hostnet\Component\Webpack\Asset\TemplateFinder'
3136
- "%kernel.root_dir%"
3237
- "" # asset_path
3338
- "" # output dir

src/Bundle/Twig/Token/WebpackTokenParser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function parse(Token $token)
9999
* @param string $export_type
100100
* @return WebpackNode
101101
*/
102-
private function parseType(TokenStream $stream, $lineno, $export_type)
102+
private function parseType(TokenStream $stream, $lineno, $export_type): WebpackNode
103103
{
104104
$files = [];
105105
while (! $stream->isEOF() && ! $stream->getCurrent()->test(Token::BLOCK_END_TYPE)) {
@@ -127,7 +127,7 @@ private function parseType(TokenStream $stream, $lineno, $export_type)
127127
* @param int $lineno
128128
* @return WebpackInlineNode
129129
*/
130-
private function parseInline(TokenStream $stream, $lineno)
130+
private function parseInline(TokenStream $stream, $lineno): WebpackInlineNode
131131
{
132132
if ($stream->test(Token::NAME_TYPE)) {
133133
$stream->next();

src/Bundle/Twig/TwigExtension.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getFunctions()
9191
* @param string $asset
9292
* @return array
9393
*/
94-
public function webpackAsset($asset)
94+
public function webpackAsset($asset): array
9595
{
9696
$asset_id = $this->public_path . '/' . Compiler::getAliasId($asset);
9797
$full_asset_path = $this->web_dir . '/' . $asset_id;
@@ -119,7 +119,7 @@ public function webpackAsset($asset)
119119
* @param string $url
120120
* @return string
121121
*/
122-
public function webpackPublic($url)
122+
public function webpackPublic($url): string
123123
{
124124
$public_dir = '/' . ltrim($this->dump_path, '/');
125125

@@ -139,7 +139,7 @@ public function webpackPublic($url)
139139
*
140140
* @return string
141141
*/
142-
public function webpackCommonJs()
142+
public function webpackCommonJs(): string
143143
{
144144
$file = $this->web_dir . '/' . $this->common_js;
145145
$modified_time = file_exists($this->web_dir . '/' . $this->common_js) ? filemtime($file) : 0;
@@ -151,7 +151,7 @@ public function webpackCommonJs()
151151
*
152152
* @return string
153153
*/
154-
public function webpackCommonCss()
154+
public function webpackCommonCss(): string
155155
{
156156
$file = $this->web_dir . '/' . $this->common_css;
157157
$modified_time = file_exists($this->web_dir . '/' . $this->common_css) ? filemtime($file) : 0;

src/Component/Asset/CacheGuard.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(Compiler $compiler, Dumper $dumper, Tracker $tracker
6060
/**
6161
* Rebuild the cache, check to see if it's still valid and rebuild if it's outdated.
6262
*/
63-
public function rebuild()
63+
public function rebuild(): void
6464
{
6565
if ($this->tracker->isOutdated()) {
6666
$this->logger->info('[Webpack 1/2]: Compiling assets.');

src/Component/Asset/Compiler.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __construct(
8181
/**
8282
* @return string
8383
*/
84-
public function compile()
84+
public function compile(): string
8585
{
8686
$this->stopwatch->start('webpack.total');
8787
$this->stopwatch->start('webpack.prepare');
@@ -124,7 +124,7 @@ public function compile()
124124
/**
125125
* Adds root & alias configuration entries.
126126
*/
127-
private function addResolveConfig()
127+
private function addResolveConfig(): void
128128
{
129129
$aliases = $this->tracker->getAliases();
130130
$this->generator->addBlock(
@@ -135,7 +135,7 @@ private function addResolveConfig()
135135
/**
136136
* Add split points to the 'entry' section of the configuration.
137137
*/
138-
private function addSplitPoints()
138+
private function addSplitPoints(): void
139139
{
140140
$split_points = [];
141141
foreach ($this->tracker->getTemplates() as $template_file) {
@@ -155,7 +155,7 @@ private function addSplitPoints()
155155
* @param string $path
156156
* @return string
157157
*/
158-
public static function getAliasId($path)
158+
public static function getAliasId($path): string
159159
{
160160
return str_replace(
161161
['/', '\\'],

src/Component/Asset/Dumper.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
/**
3939
* Iterates through resources and dump all modified resources to the bundle directory in the public dir.
4040
*/
41-
public function dump()
41+
public function dump(): void
4242
{
4343
foreach ($this->bundle_paths as $name => $path) {
4444
if (file_exists($path . DIRECTORY_SEPARATOR . $this->public_res_path)) {
@@ -51,7 +51,7 @@ public function dump()
5151
* @param string $name
5252
* @param string $path
5353
*/
54-
private function dumpBundle($name, $path)
54+
private function dumpBundle($name, $path): void
5555
{
5656
$target_dir = $this->normalize($this->getTargetDir($name));
5757
$path = $this->normalize($path);
@@ -81,7 +81,7 @@ private function dumpBundle($name, $path)
8181
* @param string $name
8282
* @return string
8383
*/
84-
private function getTargetDir($name)
84+
private function getTargetDir($name): string
8585
{
8686
if (substr($name, \strlen($name) - 6) === 'Bundle') {
8787
$name = substr($name, 0, -6);
+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* @copyright 2019-present Hostnet B.V.
4+
*/
5+
declare(strict_types=1);
6+
7+
namespace Hostnet\Component\Webpack\Asset;
8+
9+
use Symfony\Component\Finder\Finder;
10+
use Symfony\Component\Finder\SplFileInfo;
11+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
12+
use Symfony\Component\HttpKernel\KernelInterface;
13+
use Symfony\Component\Templating\TemplateReferenceInterface;
14+
15+
class TemplateFinder
16+
{
17+
private $kernel;
18+
private $root_dir;
19+
private $templates;
20+
21+
public function __construct(KernelInterface $kernel, string $root_dir)
22+
{
23+
$this->kernel = $kernel;
24+
$this->root_dir = $root_dir;
25+
}
26+
27+
/**
28+
* @return TemplateReferenceInterface[]
29+
*/
30+
public function findAllTemplates(): array
31+
{
32+
if (null !== $this->templates) {
33+
return $this->templates;
34+
}
35+
36+
$templates = [];
37+
38+
foreach ($this->kernel->getBundles() as $bundle) {
39+
$templates = array_merge($templates, $this->findTemplatesInBundle($bundle));
40+
}
41+
42+
$templates = array_merge($templates, $this->findTemplatesInFolder($this->root_dir . '/views'));
43+
44+
return $this->templates = $templates;
45+
}
46+
47+
/**
48+
* @param string $directory
49+
*
50+
* @return TemplateReferenceInterface[]
51+
*/
52+
private function findTemplatesInFolder(string $directory): array
53+
{
54+
$templates = [];
55+
56+
if (false === is_dir($directory)) {
57+
return $templates;
58+
}
59+
60+
/** @var SplFileInfo $file */
61+
foreach ((new Finder())->files()->followLinks()->in($directory) as $file) {
62+
$template = $this->parse($file->getRelativePathname());
63+
if (false !== $template) {
64+
$templates[] = $template;
65+
}
66+
}
67+
68+
return $templates;
69+
}
70+
71+
/**
72+
* @param BundleInterface $bundle
73+
*
74+
* @return TemplateReferenceInterface[]
75+
*/
76+
private function findTemplatesInBundle(BundleInterface $bundle): array
77+
{
78+
$name = $bundle->getName();
79+
$templates = array_unique(array_merge(
80+
$this->findTemplatesInFolder($bundle->getPath() . '/Resources/views'),
81+
$this->findTemplatesInFolder($this->root_dir . '/' . $name . '/views')
82+
));
83+
84+
/** @var TemplateReferenceInterface $template */
85+
foreach ($templates as $i => $template) {
86+
$templates[$i] = $template->set('bundle', $name);
87+
}
88+
89+
return $templates;
90+
}
91+
92+
/**
93+
* @param string $file_name
94+
*
95+
* @return TemplateReference|false
96+
*/
97+
private function parse(string $file_name)
98+
{
99+
$parts = explode('/', str_replace('\\', '/', $file_name));
100+
101+
$elements = explode('.', array_pop($parts));
102+
if (3 > \count($elements)) {
103+
return false;
104+
}
105+
106+
$engine = array_pop($elements);
107+
$format = array_pop($elements);
108+
109+
return new TemplateReference('', implode('/', $parts), implode('.', $elements), $format, $engine);
110+
}
111+
}

0 commit comments

Comments
 (0)