|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Zikula\ExtensionsModule\Helper; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
17
|
|
|
use Zikula\Bundle\CoreBundle\Composer\MetaData; |
|
18
|
|
|
use Zikula\Bundle\CoreBundle\Translation\TranslatorTrait; |
|
19
|
|
|
use Zikula\ExtensionsModule\Entity\Repository\ExtensionRepository; |
|
20
|
|
|
use Zikula\ExtensionsModule\Entity\RepositoryInterface\ExtensionRepositoryInterface; |
|
21
|
|
|
|
|
22
|
|
|
class MetaDataTranslatorHelper |
|
23
|
|
|
{ |
|
24
|
|
|
use TranslatorTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ExtensionRepository |
|
28
|
|
|
*/ |
|
29
|
|
|
private $extensionRepository; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var bool |
|
33
|
|
|
*/ |
|
34
|
|
|
private $installed; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct( |
|
37
|
|
|
TranslatorInterface $translator, |
|
38
|
|
|
ExtensionRepositoryInterface $extensionRepository, |
|
39
|
|
|
string $installed |
|
40
|
|
|
) { |
|
41
|
|
|
$this->setTranslator($translator); |
|
42
|
|
|
$this->extensionRepository = $extensionRepository; |
|
|
|
|
|
|
43
|
|
|
$this->installed = '0.0.0' !== $installed; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* overwrite composer.json settings with dynamic values from extension repository |
|
48
|
|
|
*/ |
|
49
|
|
|
public function translateMetaData(MetaData $metaData): MetaData |
|
50
|
|
|
{ |
|
51
|
|
|
if ($this->installed && isset($this->translator)) { |
|
52
|
|
|
$extensionEntity = $this->extensionRepository->get($metaData->getShortName()); |
|
53
|
|
|
if (null !== $extensionEntity) { |
|
54
|
|
|
$metaData->setTranslator($this->translator); |
|
55
|
|
|
$metaData->setUrl($extensionEntity->getUrl()); |
|
56
|
|
|
$metaData->setDisplayName($extensionEntity->getDisplayname()); |
|
57
|
|
|
$metaData->setDescription($extensionEntity->getDescription()); |
|
58
|
|
|
$metaData->setIcon($extensionEntity->getIcon()); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $metaData; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.