diff --git a/Utils.php b/Utils.php index d6e6922e7dd4903606079e5cb6a36edb04bb9226..4d998347d891f0097eef73ebd4d0ce15d2b25c84 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]. *