From 74a7f2e40411d94cdc6c48d2a7773965930964e0 Mon Sep 17 00:00:00 2001 From: Raaghu Date: Tue, 6 Jun 2017 12:36:08 +0530 Subject: [PATCH] added a method to find the config file for a given package --- composer.lock | 26 +++++++++--------- src/Config/Settings.php | 52 +++++++++++++++++++---------------- tests/Config/TestSettings.php | 1 - 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/composer.lock b/composer.lock index b1e9edb..1a559ab 100644 --- a/composer.lock +++ b/composer.lock @@ -758,23 +758,23 @@ }, { "name": "sebastian/diff", - "version": "1.4.1", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.8" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "type": "library", "extra": { @@ -806,7 +806,7 @@ "keywords": [ "diff" ], - "time": "2015-12-08T07:14:41+00:00" + "time": "2017-05-22T07:24:03+00:00" }, { "name": "sebastian/environment", @@ -1066,16 +1066,16 @@ }, { "name": "symfony/yaml", - "version": "v3.2.4", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "9724c684646fcb5387d579b4bfaa63ee0b0c64c8" + "reference": "885db865f6b2b918404a1fae28f9ac640f71f994" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/9724c684646fcb5387d579b4bfaa63ee0b0c64c8", - "reference": "9724c684646fcb5387d579b4bfaa63ee0b0c64c8", + "url": "https://api.github.com/repos/symfony/yaml/zipball/885db865f6b2b918404a1fae28f9ac640f71f994", + "reference": "885db865f6b2b918404a1fae28f9ac640f71f994", "shasum": "" }, "require": { @@ -1090,7 +1090,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "3.3-dev" } }, "autoload": { @@ -1117,7 +1117,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-02-16T22:46:52+00:00" + "time": "2017-05-28T10:56:20+00:00" }, { "name": "webmozart/assert", diff --git a/src/Config/Settings.php b/src/Config/Settings.php index 65793e7..f92bfd1 100644 --- a/src/Config/Settings.php +++ b/src/Config/Settings.php @@ -22,7 +22,6 @@ private static function getVendorDir(){ return $vendorDir; } - /** * this method retrieves settings of a package @@ -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); @@ -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; + } + } diff --git a/tests/Config/TestSettings.php b/tests/Config/TestSettings.php index 31ffaad..ee8dfaf 100644 --- a/tests/Config/TestSettings.php +++ b/tests/Config/TestSettings.php @@ -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{