Skip to content

Commit

Permalink
added a method to find the config file for a given package
Browse files Browse the repository at this point in the history
  • Loading branch information
Raaghu committed Jun 6, 2017
1 parent 4b59d45 commit 74a7f2e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 28 additions & 24 deletions src/Config/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ private static function getVendorDir(){
return $vendorDir;
}



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

$vendorDir = self::getVendorDir();

$packageConfigFile = $vendorDir.'/'.$package.'/config.json';

if(!file_exists($packageConfigFile)){
// if no config.json in vendor directory ,
// try to find the current package's config.json
$thisPackageRoot = dirname($vendorDir);
while(!file_exists($thisPackageRoot.'/composer.json')){
$thisPackageRoot_ = dirname($thisPackageRoot);
if($thisPackageRoot == $thisPackageRoot_){
throw new \Exception("No configuration found for the package $package");
}
$thisPackageRoot = $thisPackageRoot_;
}
$composerJson = json_decode(file_get_contents($thisPackageRoot.'/composer.json'),true);
if($composerJson["name"] == $package){
$packageConfigFile = $thisPackageRoot.'/config.json';
}
if(!file_exists($packageConfigFile)){
throw new \Exception("No configuration found for the package $package");
}
}
$packageConfigFile = self::getConfigFile($package);

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

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

}

public static function getConfigFile($package){
$vendorDir = self::getVendorDir();

$packageConfigFile = $vendorDir.'/'.$package.'/config.json';
if(!file_exists($packageConfigFile)){
// if no config.json in vendor directory ,
// try to find the current package's config.json
$thisPackageRoot = dirname($vendorDir);
while(!file_exists($thisPackageRoot.'/composer.json')){
$thisPackageRoot_ = dirname($thisPackageRoot);
if($thisPackageRoot == $thisPackageRoot_){
throw new \Exception("No configuration found for the package $package");
}
$thisPackageRoot = $thisPackageRoot_;
}
$composerJson = json_decode(file_get_contents($thisPackageRoot.'/composer.json'),true);
if($composerJson["name"] == $package){
$packageConfigFile = $thisPackageRoot.'/config.json';
}

if(!file_exists($packageConfigFile)){
throw new \Exception("No configuration found for the package $package");
}
}
return $packageConfigFile;
}

}

1 change: 0 additions & 1 deletion tests/Config/TestSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace PhpPlatform\Tests\Config;

use PhpPlatform\Config\Settings;
use Composer\Autoload\ClassLoader;
use PhpPlatform\Config\SettingsCache;

class TestSettings extends \PHPUnit_Framework_TestCase{
Expand Down

0 comments on commit 74a7f2e

Please sign in to comment.