1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Satis; |
4
|
|
|
|
5
|
|
|
use App\Satis\Collections\PackageCollection; |
6
|
|
|
use App\Satis\Collections\RepositoryCollection; |
7
|
|
|
use App\Satis\Model\Repository; |
8
|
|
|
use JMS\Serializer\Serializer; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Lukas Homza <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class ConfigMirror { |
14
|
|
|
/** @var \App\Satis\Model\ConfigLock */ |
15
|
|
|
protected $serializer; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* ConfigMirror constructor. |
19
|
|
|
* @param \JMS\Serializer\Serializer $serializer |
20
|
|
|
*/ |
21
|
|
|
public function __construct(Serializer $serializer) { |
22
|
|
|
$this->serializer = $serializer; |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $config |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
public function getPublicMirror($config) { |
30
|
|
|
/** @var \App\Satis\Model\Config $publicConfig */ |
31
|
|
|
$publicConfig = $this->serializer->deserialize( |
|
|
|
|
32
|
|
|
$config, |
33
|
|
|
'App\Satis\Model\Config', |
34
|
|
|
'json' |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$repository = new Repository(); |
38
|
|
|
$repository->setType('composer'); |
39
|
|
|
$repository->setUrl('https://packagist.org/'); |
40
|
|
|
|
41
|
|
|
$homepage = $publicConfig->getHomepage(); |
42
|
|
|
|
43
|
|
|
$publicConfig->setHomepage(rtrim($homepage, '/') . '/' . config('satis.public_repository')) |
44
|
|
|
->setRequireAll(false) |
45
|
|
|
->setRepositories(new RepositoryCollection([$repository])); |
46
|
|
|
|
47
|
|
|
return $this->serializer->serialize($publicConfig, 'json'); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $config |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getPrivateMirror($config) { |
55
|
|
|
/** @var \App\Satis\Model\Config $privateConfig */ |
56
|
|
|
$privateConfig = $this->serializer->deserialize( |
|
|
|
|
57
|
|
|
$config, |
58
|
|
|
'App\Satis\Model\Config', |
59
|
|
|
'json' |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$homepage = $privateConfig->getHomepage(); |
63
|
|
|
|
64
|
|
|
$privateConfig->setHomepage(rtrim($homepage, '/') . '/' . config('satis.private_repository')) |
65
|
|
|
->setRequireAll(true) |
66
|
|
|
->setProviders(true) |
67
|
|
|
->setPackages(new PackageCollection()); |
68
|
|
|
|
69
|
|
|
return $this->serializer->serialize($privateConfig, 'json'); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..