Skip to content

Commit 74a7f2e

Browse files
committed
added a method to find the config file for a given package
1 parent 4b59d45 commit 74a7f2e

File tree

3 files changed

+41
-38
lines changed

3 files changed

+41
-38
lines changed

composer.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Config/Settings.php

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ private static function getVendorDir(){
2222
return $vendorDir;
2323
}
2424

25-
2625

2726
/**
2827
* this method retrieves settings of a package
@@ -39,29 +38,7 @@ public static function getSettings($package,$setting = null){
3938
$settings = SettingsCache::getInstance()->getData($package_);
4039
if($settings === NULL){
4140

42-
$vendorDir = self::getVendorDir();
43-
44-
$packageConfigFile = $vendorDir.'/'.$package.'/config.json';
45-
46-
if(!file_exists($packageConfigFile)){
47-
// if no config.json in vendor directory ,
48-
// try to find the current package's config.json
49-
$thisPackageRoot = dirname($vendorDir);
50-
while(!file_exists($thisPackageRoot.'/composer.json')){
51-
$thisPackageRoot_ = dirname($thisPackageRoot);
52-
if($thisPackageRoot == $thisPackageRoot_){
53-
throw new \Exception("No configuration found for the package $package");
54-
}
55-
$thisPackageRoot = $thisPackageRoot_;
56-
}
57-
$composerJson = json_decode(file_get_contents($thisPackageRoot.'/composer.json'),true);
58-
if($composerJson["name"] == $package){
59-
$packageConfigFile = $thisPackageRoot.'/config.json';
60-
}
61-
if(!file_exists($packageConfigFile)){
62-
throw new \Exception("No configuration found for the package $package");
63-
}
64-
}
41+
$packageConfigFile = self::getConfigFile($package);
6542

6643
$settings = json_decode(file_get_contents($packageConfigFile),true);
6744

@@ -80,5 +57,32 @@ public static function getSettings($package,$setting = null){
8057

8158
}
8259

60+
public static function getConfigFile($package){
61+
$vendorDir = self::getVendorDir();
62+
63+
$packageConfigFile = $vendorDir.'/'.$package.'/config.json';
64+
if(!file_exists($packageConfigFile)){
65+
// if no config.json in vendor directory ,
66+
// try to find the current package's config.json
67+
$thisPackageRoot = dirname($vendorDir);
68+
while(!file_exists($thisPackageRoot.'/composer.json')){
69+
$thisPackageRoot_ = dirname($thisPackageRoot);
70+
if($thisPackageRoot == $thisPackageRoot_){
71+
throw new \Exception("No configuration found for the package $package");
72+
}
73+
$thisPackageRoot = $thisPackageRoot_;
74+
}
75+
$composerJson = json_decode(file_get_contents($thisPackageRoot.'/composer.json'),true);
76+
if($composerJson["name"] == $package){
77+
$packageConfigFile = $thisPackageRoot.'/config.json';
78+
}
79+
80+
if(!file_exists($packageConfigFile)){
81+
throw new \Exception("No configuration found for the package $package");
82+
}
83+
}
84+
return $packageConfigFile;
85+
}
86+
8387
}
8488

tests/Config/TestSettings.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace PhpPlatform\Tests\Config;
99

1010
use PhpPlatform\Config\Settings;
11-
use Composer\Autoload\ClassLoader;
1211
use PhpPlatform\Config\SettingsCache;
1312

1413
class TestSettings extends \PHPUnit_Framework_TestCase{

0 commit comments

Comments
 (0)