This repository was archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTruncatedComposerRepository.php
68 lines (59 loc) · 1.85 KB
/
TruncatedComposerRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
/**
* Copyright (c) 2018-2020 Daniel Bannert
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/narrowspark/automatic
*/
namespace Narrowspark\Automatic\Prefetcher;
use Composer\Config;
use Composer\EventDispatcher\EventDispatcher;
use Composer\IO\IOInterface;
use Composer\Repository\ComposerRepository as BaseComposerRepository;
use Composer\Util\RemoteFilesystem;
use Narrowspark\Automatic\Prefetcher\Contract\LegacyTagsManager as LegacyTagsManagerContract;
/**
* Ported from symfony flex, see original.
*
* @see https://github.com/symfony/flex/blob/master/src/Cache.php
*
* (c) Nicolas Grekas <[email protected]>
*/
final class TruncatedComposerRepository extends BaseComposerRepository
{
/**
* {@inheritdoc}
*/
public function __construct(
array $repoConfig,
IOInterface $io,
Config $config,
?EventDispatcher $eventDispatcher = null,
?RemoteFilesystem $rfs = null
) {
parent::__construct($repoConfig, $io, $config, $eventDispatcher, $rfs);
$this->cache = new Cache(
$io,
$config->get('cache-repo-dir') . '/' . \preg_replace('{[^a-z0-9.]}i', '-', $this->url),
'a-z0-9.$'
);
}
/**
* Set a tags manager instance.
*/
public function setTagsManager(LegacyTagsManagerContract $tagsManager): void
{
$this->cache->setTagsManager($tagsManager);
}
/**
* {@inheritdoc}
*/
protected function fetchFile($filename, $cacheKey = null, $sha256 = null, $storeLastModifiedTime = false)
{
$data = parent::fetchFile($filename, $cacheKey, $sha256, $storeLastModifiedTime);
return \is_array($data) ? $this->cache->removeLegacyTags($data) : $data;
}
}