1 | <?php |
||||||
2 | |||||||
3 | declare(strict_types=1); |
||||||
4 | |||||||
5 | namespace SixtyEightPublishers\Asset\DI; |
||||||
6 | |||||||
7 | use Latte; |
||||||
8 | use Nette; |
||||||
9 | use Symfony; |
||||||
10 | use SixtyEightPublishers; |
||||||
11 | |||||||
12 | final class AssetExtension extends Nette\DI\CompilerExtension |
||||||
13 | { |
||||||
14 | /** @var \SixtyEightPublishers\Asset\DI\PackageDefinitionFacade */ |
||||||
15 | private $packages; |
||||||
16 | |||||||
17 | /** @var \SixtyEightPublishers\Asset\DI\VersionDefinitionFacade */ |
||||||
18 | private $versions; |
||||||
19 | |||||||
20 | public function __construct() |
||||||
21 | { |
||||||
22 | 1 | $reference = new ReferenceFacade($this); |
|||||
23 | 1 | $this->packages = new PackageDefinitionFacade($reference); |
|||||
24 | 1 | $this->versions = new VersionDefinitionFacade($reference); |
|||||
25 | 1 | } |
|||||
26 | |||||||
27 | /** |
||||||
28 | * {@inheritdoc} |
||||||
29 | * |
||||||
30 | * @throws \Nette\Utils\AssertionException |
||||||
31 | */ |
||||||
32 | public function loadConfiguration(): void |
||||||
33 | { |
||||||
34 | 1 | $namedPackages = []; |
|||||
35 | 1 | $config = (new Config())->getConfig($this); |
|||||
36 | |||||||
37 | 1 | $defaultVersion = NULL !== $config['version_strategy'] |
|||||
38 | 1 | ? new Nette\DI\Statement($this->versions->getVersionDependencyReference($config['version_strategy'], '_default')) |
|||||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
The call to
Nette\DI\Statement::__construct() has too many arguments starting with $this->versions->getVers...strategy'], '_default') .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.
Loading history...
|
|||||||
39 | 1 | : $this->versions->createVersionStatement('_default', $config['version'], $config['version_format'], $config['json_manifest_path']); |
|||||
40 | |||||||
41 | 1 | $defaultPackage = $this->packages->createPackageStatement('_default', $config['base_path'], $config['base_urls'], $defaultVersion); |
|||||
42 | |||||||
43 | 1 | foreach ($config['packages'] as $name => $package) { |
|||||
44 | 1 | $namedPackages[$name] = $this->createPackage((string) $name, $package, $config, $defaultVersion); |
|||||
45 | } |
||||||
46 | |||||||
47 | 1 | $this->getContainerBuilder() |
|||||
48 | 1 | ->addDefinition($this->prefix('packages')) |
|||||
49 | 1 | ->setType(Symfony\Component\Asset\Packages::class) |
|||||
50 | 1 | ->setArguments([ |
|||||
51 | 1 | 'defaultPackage' => $defaultPackage, |
|||||
52 | 1 | 'packages' => $namedPackages, |
|||||
53 | ]); |
||||||
54 | 1 | } |
|||||
55 | |||||||
56 | /** |
||||||
57 | * {@inheritdoc} |
||||||
58 | */ |
||||||
59 | public function beforeCompile(): void |
||||||
60 | { |
||||||
61 | 1 | $builder = $this->getContainerBuilder(); |
|||||
62 | 1 | $latteFactory = $builder->getDefinition($builder->getByType(Latte\Engine::class) ?? 'nette.latteFactory'); |
|||||
63 | |||||||
64 | # asset filters |
||||||
65 | 1 | $latteFactory->getResultDefinition()->addSetup('addFilter', [ |
|||||
0 ignored issues
–
show
Are you sure the usage of
$latteFactory->getResultDefinition() targeting Nette\DI\Definitions\Definition::__call() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||||||
66 | 1 | 'name' => 'asset', |
|||||
67 | 1 | 'callback' => [ $this->prefix('@packages'), 'getUrl' ], |
|||||
68 | ]); |
||||||
69 | |||||||
70 | 1 | $latteFactory->getResultDefinition()->addSetup('addFilter', [ |
|||||
0 ignored issues
–
show
Are you sure the usage of
$latteFactory->getResultDefinition() targeting Nette\DI\Definitions\Definition::__call() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||||||
71 | 1 | 'name' => 'asset_version', |
|||||
72 | 1 | 'callback' => [ $this->prefix('@packages'), 'getVersion' ], |
|||||
73 | ]); |
||||||
74 | |||||||
75 | # asset macros |
||||||
76 | 1 | $latteFactory->getResultDefinition()->addSetup('addProvider', [ |
|||||
0 ignored issues
–
show
Are you sure the usage of
$latteFactory->getResultDefinition() targeting Nette\DI\Definitions\Definition::__call() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||||||
77 | 1 | 'name' => 'symfonyPackages', |
|||||
78 | 1 | 'value' => $this->prefix('@packages'), |
|||||
79 | ]); |
||||||
80 | |||||||
81 | 1 | $latteFactory->getResultDefinition()->addSetup('?->onCompile[] = function ($engine) { ?::install($engine->getCompiler()); }', [ |
|||||
0 ignored issues
–
show
Are you sure the usage of
$latteFactory->getResultDefinition() targeting Nette\DI\Definitions\Definition::__call() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||||||
82 | 1 | '@self', |
|||||
83 | 1 | new Nette\PhpGenerator\PhpLiteral(SixtyEightPublishers\Asset\Latte\AssetMacroSet::class), |
|||||
84 | ]); |
||||||
85 | 1 | } |
|||||
86 | |||||||
87 | /** |
||||||
88 | * @param string $name |
||||||
89 | * @param array $package |
||||||
90 | * @param array $config |
||||||
91 | * @param \Nette\DI\Statement $defaultVersion |
||||||
92 | * |
||||||
93 | * @return \Nette\DI\Statement |
||||||
94 | */ |
||||||
95 | 1 | private function createPackage(string $name, array $package, array $config, Nette\DI\Statement $defaultVersion): Nette\DI\Statement |
|||||
96 | { |
||||||
97 | 1 | if (NULL !== $package['version_strategy']) { |
|||||
98 | 1 | $version = new Nette\DI\Statement($this->versions->getVersionDependencyReference($package['version_strategy'], $name)); |
|||||
0 ignored issues
–
show
The class
Nette\DI\Statement has been deprecated: use Nette\DI\Definitions\Statement
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The call to
Nette\DI\Statement::__construct() has too many arguments starting with $this->versions->getVers...sion_strategy'], $name) .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.
Loading history...
|
|||||||
99 | 1 | } elseif (NULL === $package['version'] && NULL === $package['json_manifest_path']) { |
|||||
100 | // if neither version nor json_manifest_path are specified, use the default |
||||||
101 | 1 | $version = $defaultVersion; |
|||||
102 | } else { |
||||||
103 | // let format fallback to main version_format |
||||||
104 | 1 | $version = $this->versions->createVersionStatement($name, !empty($package['version']) ? $package['version'] : NULL, $package['version_format'] ?: $config['version_format'], $package['json_manifest_path']); |
|||||
105 | } |
||||||
106 | |||||||
107 | 1 | return $this->packages->createPackageStatement($name, $package['base_path'], $package['base_urls'], $version); |
|||||
108 | } |
||||||
109 | } |
||||||
110 |