44
55use Catalyst \Entity \CatalystEntity ;
66use Catalyst \Exception \PackageNotFoundException ;
7+ use Catalyst \Exception \UnresolveableDependenciesException ;
78use Catalyst \Model \Repository ;
89use Composer \Semver \Semver ;
9- use Ramsey \Uuid \Exception \UnsatisfiedDependencyException ;
1010
1111class PackageService
1212{
@@ -16,9 +16,6 @@ class PackageService
1616 public function __construct ()
1717 {
1818 // Add default repositories
19- //new Repository(Repository::REPO_DIRECTORY, 'C:\Users\PC\Documents\GameMakerStudio2\Catalyst\tests')
20- //new Repository(Repository::REPO_catalyst, 'https://raw.githubusercontent.com/GameMakerHub/packages/master/packages.json')
21- //new Repository(Repository::REPO_VCS, 'git@github.com:DukeSoft/extended-functions.git')
2219 $ this ->addRepository (new Repository (Repository::REPO_CATALYST , 'http://repo.gamemakerhub.net ' ));
2320 }
2421
@@ -53,7 +50,7 @@ public function packageExists(string $package, string $version): bool
5350 }
5451 }
5552
56- throw new PackageNotFoundException ( $ package , $ version ) ;
53+ return false ;
5754 }
5855
5956 public function getPackageDependencies (string $ package , string $ version ): array
@@ -73,24 +70,33 @@ public function getSatisfiableVersions(string $package, string $version): array
7370 $ versions = [];
7471
7572 foreach ($ this ->repositories as $ repository ) {
76- $ versions += $ repository ->getSatisfiableVersions ($ package , $ version );
73+ try {
74+ $ versions += $ repository ->getSatisfiableVersions ($ package , $ version );
75+ } catch (PackageNotFoundException $ e ) {
76+ // Ignore
77+ }
7778 }
7879
7980 return $ versions ;
8081 }
8182
83+ private function addRepositoriesFromCatalyst (CatalystEntity $ project )
84+ {
85+ foreach ($ project ->repositories () as $ location => $ type ) {
86+ $ this ->addRepository (new Repository ($ type , $ location ));
87+ }
88+ }
89+
8290 public function solveDependencies (CatalystEntity $ project , $ finalPackages = [])
8391 {
8492 $ requirements = $ project ->require ();
85- foreach ($ project ->repositories () as $ repository ) {
86- $ this ->addRepository ($ repository );
87- }
93+ $ this ->addRepositoriesFromCatalyst ($ project );
8894
8995 // First find all available versions of all required packages
9096 foreach ($ requirements as $ package => $ version ) {
9197 $ finalPackages [$ package ] = $ this ->getSatisfiableVersions ($ package , $ version );
9298 if (count ($ finalPackages [$ package ]) == 0 ) {
93- throw new UnsatisfiedDependencyException (
99+ throw new UnresolveableDependenciesException (
94100 sprintf ('No version for constraint "%s" for package "%s" can be found ' , $ version , $ package )
95101 );
96102 }
@@ -102,7 +108,7 @@ public function solveDependencies(CatalystEntity $project, $finalPackages = [])
102108 $ addedNewPackage = false ;
103109 foreach ($ finalPackages as $ package => $ versions ) {
104110 if (count ($ versions ) == 0 ) {
105- throw new UnsatisfiedDependencyException (
111+ throw new UnresolveableDependenciesException (
106112 $ package . ' cant be satisfied, due to a dependency constraint '
107113 );
108114 }
@@ -113,7 +119,7 @@ public function solveDependencies(CatalystEntity $project, $finalPackages = [])
113119 //Apply constraint on current list
114120 $ finalPackages [$ depPackage ] = Semver::satisfiedBy ($ finalPackages [$ depPackage ], $ depVersionConstraint );
115121 } else {
116- //Add new pacakge to list
122+ //Add new package to list
117123 $ finalPackages [$ depPackage ] = $ this ->getSatisfiableVersions ($ depPackage , $ depVersionConstraint );
118124 $ addedNewPackage = true ;
119125 }
@@ -125,7 +131,7 @@ public function solveDependencies(CatalystEntity $project, $finalPackages = [])
125131 $ result = [];
126132 foreach ($ finalPackages as $ package => $ versions ) {
127133 if (count ($ versions ) == 0 ) {
128- throw new UnsatisfiedDependencyException (
134+ throw new UnresolveableDependenciesException (
129135 $ package . ' cant be satisfied, due to a dependency constraint '
130136 );
131137 }
0 commit comments