Skip to content
Snippets Groups Projects
Commit 2a899647 authored by jurgenhaas's avatar jurgenhaas
Browse files

Also work with composer.json files of other directories, not only project root

Also work with sub-sub-sections
parent d90a4806
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -18,14 +18,14 @@ final class Utils { ...@@ -18,14 +18,14 @@ final class Utils {
protected $composer; protected $composer;
/** /**
* Content of the project's composer.json file. * Content of the composer.json file.
* *
* @var array * @var array
*/ */
protected $content; protected $content;
/** /**
* The path of the root project's directory. * The path of the directory of the composer.json file.
* *
* @var string * @var string
*/ */
...@@ -43,10 +43,14 @@ final class Utils { ...@@ -43,10 +43,14 @@ final class Utils {
* *
* @param \Composer\Composer $composer * @param \Composer\Composer $composer
* The composer object running this session. * 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->composer = $composer;
$this->sourcePath = getcwd() . $composer->getPackage()->getTargetDir(); $this->sourcePath = isset($sourcePath) ?
$sourcePath :
getcwd() . $composer->getPackage()->getTargetDir();
$this->composerJsonPath = $this->sourcePath . '/composer.json'; $this->composerJsonPath = $this->sourcePath . '/composer.json';
$this->read(); $this->read();
} }
...@@ -112,6 +116,24 @@ final class Utils { ...@@ -112,6 +116,24 @@ final class Utils {
return isset($section[$key2]) ? $section[$key2] : []; 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]. * Set settings for [$key].
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment