From 2a899647bb68c6f3388087474327e1ce67081d32 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Sun, 5 Nov 2017 14:47:34 +0100
Subject: [PATCH] Also work with composer.json files of other directories, not
 only project root Also work with sub-sub-sections

---
 Utils.php | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/Utils.php b/Utils.php
index d6e6922..4d99834 100644
--- a/Utils.php
+++ b/Utils.php
@@ -18,14 +18,14 @@ final class Utils {
   protected $composer;
 
   /**
-   * Content of the project's composer.json file.
+   * Content of the composer.json file.
    *
    * @var array
    */
   protected $content;
 
   /**
-   * The path of the root project's directory.
+   * The path of the directory of the composer.json file.
    *
    * @var string
    */
@@ -43,10 +43,14 @@ final class Utils {
    *
    * @param \Composer\Composer $composer
    *   The composer object running this session.
+   * @param string|null $sourcePath
+   *   The path name if not the project's root directory.
    */
-  public function __construct(Composer $composer) {
+  public function __construct(Composer $composer, $sourcePath = NULL) {
     $this->composer = $composer;
-    $this->sourcePath = getcwd() . $composer->getPackage()->getTargetDir();
+    $this->sourcePath = isset($sourcePath) ?
+      $sourcePath :
+      getcwd() . $composer->getPackage()->getTargetDir();
     $this->composerJsonPath = $this->sourcePath . '/composer.json';
     $this->read();
   }
@@ -112,6 +116,24 @@ final class Utils {
     return isset($section[$key2]) ? $section[$key2] : [];
   }
 
+  /**
+   * Get settings for [$key1][$key2][$key3].
+   *
+   * @param string $key1
+   *   The key for the section.
+   * @param string $key2
+   *   The key for the sub-section.
+   * @param string $key3
+   *   The key for the sub-sub-section.
+   *
+   * @return array|string
+   *   The settings of the key.
+   */
+  public function getSubSubSection($key1, $key2, $key3) {
+    $subSection = $this->getSubSection($key1, $key2);
+    return isset($subSection[$key3]) ? $subSection[$key3] : [];
+  }
+
   /**
    * Set settings for [$key].
    *
-- 
GitLab