44
55use CodedMonkey \Dirigent \Doctrine \Entity \Package ;
66use CodedMonkey \Dirigent \Doctrine \Entity \Registry ;
7+ use CodedMonkey \Dirigent \Doctrine \Entity \Version ;
78use Composer \Config ;
89use Composer \Factory ;
10+ use Composer \Installer \InstallationManager ;
911use Composer \IO \IOInterface ;
1012use Composer \IO \NullIO ;
13+ use Composer \Package \Locker ;
1114use Composer \Repository \ComposerRepository ;
1215use Composer \Repository \VcsRepository ;
1316use Composer \Util \HttpDownloader ;
17+ use Composer \Util \Loop ;
18+ use Composer \Util \ProcessExecutor ;
1419
1520class ComposerClient
1621{
@@ -19,10 +24,7 @@ public function createComposerRepository(Package|Registry $registry, ?IOInterfac
1924 $ registry = $ registry instanceof Package ? $ registry ->getMirrorRegistry () : $ registry ;
2025
2126 $ config ??= ConfigFactory::createForRegistry ($ registry );
22- if (!$ io ) {
23- $ io = new NullIO ();
24- $ io ->loadConfiguration ($ config );
25- }
27+ $ io ??= $ this ->createIo ($ io );
2628 $ httpDownloader = $ this ->createHttpDownloader ($ io , $ config );
2729
2830 return new ComposerRepository (['url ' => $ registry ->getUrl ()], $ io , $ config , $ httpDownloader );
@@ -33,10 +35,7 @@ public function createVcsRepository(Package $package, ?IOInterface $io = null, ?
3335 $ repoUrl = $ package ->getRepositoryUrl ();
3436
3537 $ config ??= ConfigFactory::createForVcsRepository ($ repoUrl , $ package ->getRepositoryCredentials ());
36- if (!$ io ) {
37- $ io = new NullIO ();
38- $ io ->loadConfiguration ($ config );
39- }
38+ $ io ??= $ this ->createIo ($ io );
4039 $ httpDownloader = $ this ->createHttpDownloader ($ io , $ config );
4140
4241 return new VcsRepository (['url ' => $ repoUrl ], $ io , $ config , $ httpDownloader );
@@ -45,14 +44,51 @@ public function createVcsRepository(Package $package, ?IOInterface $io = null, ?
4544 public function createHttpDownloader (?IOInterface $ io = null , ?Config $ config = null ): HttpDownloader
4645 {
4746 $ config ??= Factory::createConfig ();
48- if (!$ io ) {
49- $ io = new NullIO ();
50- $ io ->loadConfiguration ($ config );
51- }
47+ $ io ??= $ this ->createIo ($ io );
5248
5349 return new HttpDownloader ($ io , $ config , self ::getHttpDownloaderOptions ());
5450 }
5551
52+ public function createIo (?Config $ config = null ): IOInterface
53+ {
54+ $ io = new NullIO ();
55+ $ io ->loadConfiguration ($ config );
56+
57+ return $ io ;
58+ }
59+
60+ public function createLocker (Version $ version , ?IOInterface $ io = null , ?Config $ config = null ): ?Locker
61+ {
62+ $ package = $ version ->getPackage ();
63+
64+ $ config ??= ConfigFactory::createForVcsRepository ($ package ->getRepositoryUrl (), $ package ->getRepositoryCredentials ());
65+ $ io ??= $ this ->createIo ($ config );
66+ $ repository = $ this ->createVcsRepository ($ package , $ io , $ config );
67+ $ driver = $ repository ->getDriver ();
68+ $ process = $ this ->createProcessExecutor ($ io );
69+ $ httpDownloader = $ this ->createHttpDownloader ($ io , $ config );
70+ $ loop = new Loop ($ httpDownloader , $ process );
71+ $ installationManager = new InstallationManager ($ loop , $ io );
72+
73+ $ jsonSource = $ driver ->getFileContent ('composer.json ' , $ version ->getSource ()['reference ' ]);
74+ $ lockerSource = $ driver ->getFileContent ('composer.lock ' , $ version ->getSource ()['reference ' ]);
75+
76+ if (empty ($ lockerSource )) {
77+ return null ;
78+ }
79+
80+ $ lockerJsonFile = new InMemoryJsonFile ($ lockerSource );
81+
82+ return new Locker ($ io , $ lockerJsonFile , $ installationManager , $ jsonSource );
83+ }
84+
85+ public function createProcessExecutor (?IOInterface $ io = null ): ProcessExecutor
86+ {
87+ $ io ??= $ this ->createIo ($ io );
88+
89+ return new ProcessExecutor ($ io );
90+ }
91+
5692 public static function getHttpDownloaderOptions (): array
5793 {
5894 $ options ['http ' ]['header ' ][] = 'User-Agent: Dirigent (https://github.com/codedmonkey/dirigent) ' ;
0 commit comments