Returns value from composer.json file

@param string $composerJsonPath Path of composer.json file
@param string $nodeName         Name of node who value should be returned
@return null|string
179455
public static function getValue($composerJsonPath, $nodeName)
    {
        $composerJsonString = is_string($composerJsonPath);
        $composerJsonReadable = false;

        if ($composerJsonString) {
            $composerJsonReadable = is_readable($composerJsonPath);
        }

        /*
         * Provided path or name of node are invalid?
         * The composer.json file doesn't exist or isn't readable?
         * Name of node is unknown?
         *
         * Nothing to do
         */
        if (!$composerJsonString || !is_string($nodeName) || !$composerJsonReadable || empty($nodeName)) {
            return null;
        }

        $content = file_get_contents($composerJsonPath);
        $data = json_decode($content);

        /*
         * Unknown data from the composer.json file or there is no node with given name?
         * Nothing to do
         */
        if (null === $data || !isset($data->{$nodeName})) {
            return null;
        }

        return $data->{$nodeName};
    }
626445
protected function saveComposerJson($composerJson)
    {
        $newComposerJson = json_encode(
            $composerJson,
            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
        );

        $composerJsonPath = $this->getComposerJsonPath();
        if (File::put($composerJsonPath, $newComposerJson) === false) {
            throw new RuntimeException("Cannot write to composer.json [$composerJsonPath]");
        }
    }
1099654
public static function getPackageVersion($composerName)
    {
        foreach (self::readComposerLock() as $composerLockData) {
            if (!isset($composerLockData['name'])) {
                continue;
            }
            if ($composerLockData['name'] === $composerName) {
                return preg_replace('/^v([0-9])/', '$1', $composerLockData['version'], 1);
            }
        }

        return '';
    }
912241
public static function getComposerJson( $directory ) {
		$composer_json = $directory . DIRECTORY_SEPARATOR . 'composer.json';

		if ( ! file_exists( $composer_json ) ) {
			return null;
		}

		$composer = @json_decode( file_get_contents( $composer_json ), true );

		if ( ! $composer ) {
			return null;
		}

		return $composer;
	}
998599
protected function composer($key = null)
    {
        if (! $this->composerJson) {
            $composerFile = $this->realPath().'/composer.json';
            if (! file_exists($composerFile)) {
                return null;
            }
            $this->composerJson = json_decode(file_get_contents($composerFile), true);
        }

        return $key ? array_get($this->composerJson, $key) : $this->composerJson;
    }
407510
public static function getValueFromXPath($path, \DOMXPath $xpath, \DomNode $context = null, $default = null)
    {
        $result = $xpath->query($path, $context);
        if (0 === $result->length) {
            return $default;
        }

        $item = $result->item(0);
        if (null === $item) {
            return $default;
        }

        return $item->nodeValue;
    }
967292
public function nodePathAvailableForNode($nodePath, NodeInterface $node)
    {
        /** @var NodeData $existingNodeData */
        $existingNodeDataObjects = $this->nodeDataRepository->findByPathWithoutReduce($nodePath, $node->getWorkspace(), true);
        foreach ($existingNodeDataObjects as $existingNodeData) {
            if ($existingNodeData->getMovedTo() !== null && $existingNodeData->getMovedTo() === $node->getNodeData()) {
                return true;
            }
        }
        return !$this->nodePathExistsInAnyContext($nodePath);
    }
627644
public static function whereAmI($hint, $composerFileName = self::COMPOSER_FILENAME)
    {

        $hint = static::determineHintLocation($hint);

        if (isset(static::$cachedLookups[$hint]))
        {
            return static::$cachedInstances[static::$cachedLookups[$hint]];
        }

        $packageInfo = new static($hint, $composerFileName);

        static::$cachedLookups[$hint] = $packageInfo->getComposerJsonFilename();

        // try again. could already have a hit
        if (isset(static::$cachedInstances[static::$cachedLookups[$hint]]))
        {
            return static::$cachedInstances[static::$cachedLookups[$hint]];
        }

        static::$cachedInstances[static::$cachedLookups[$hint]] = $packageInfo;

        return $packageInfo;
    }
850166
public function getValue($tsNodePath, $defaultValue = null)
    {
        $ret = $defaultValue;

        // extract TypoScript-path information
        $nodeFound     = true;
        $nodeSections  = explode('.', $tsNodePath);
        $nodeValueName = end($nodeSections);

        // remove last node from sections because we already got the node name
        unset($nodeSections[key($nodeSections)]);

        // walk though array to find node
        $nodeData = $this->tsData;
        if (!empty($nodeSections) && is_array($nodeSections)) {
            foreach ($nodeSections as $sectionName) {
                $sectionName .= '.';

                if (is_array($nodeData) && array_key_exists($sectionName, $nodeData)) {
                    $nodeData = $nodeData[$sectionName];
                } else {
                    $nodeFound = false;
                    break;
                }
            }
        }

        // check if we got the value of the node
        if ($nodeFound && is_array($nodeData) && array_key_exists($nodeValueName, $nodeData)) {
            $ret = $nodeData[$nodeValueName];
        }


        return $ret;
    }
458750
public function getMandatoryParam($path)
    {
        $this->validatePath($path);

        $value = $this->translatePathElement($path, $this->params);

        if(null === $value)
        {
            throw new JsonException("Json mandatory param '$path' not found found.");
        }
        return $value;
    }
342382
private function getRootDir($checkPath)
    {
        $dir = $checkPath;
        while (!file_exists($dir . '/composer.json')) {
            if ($dir === dirname($dir)) {
                break;
            }
            $dir = dirname($dir);
        }

        return $dir;
    }
989559
public function get_config_json( $filename ) {
		if ( isset( $this->loaded[ $filename ] ) ) {
			return $this->loaded[ $filename ];
		}

		$config = $this->path . 'config/' . $filename . '.json';

		if ( ! file_exists( $config ) ) {
			return null;
		}

		$contents = file_get_contents( $config );

		if ( false === $contents ) {
			return null;
		}

		return $this->loaded[ $filename ] = json_decode( $contents, true );
	}
847813
public static function getValueFromPath($objectOrArray, $propertyPath, $throwIfNotFound = false)
    {
        if(null !== $value = self::getValue($objectOrArray, $propertyPath)) {
            return $value;
        }

        $paths = explode('.', $propertyPath);
        $lastPath = array_pop($paths);

        $pathReady = [];
        foreach ($paths as $path) {
            $pathReady[] = $path;

            $objectOrArray = self::getValue($objectOrArray, $path);

            if (null === $objectOrArray || is_scalar($objectOrArray)) {
                if ($throwIfNotFound) {
                    throw new \Exception(sprintf('path not found: %s', implode('.', $pathReady)));
                }

                return null;
            }
        }

        return self::getValue($objectOrArray, $lastPath);
    }
469237
protected function getCoreModulePath(string $moduleName, PathTransfer $pathTransfer): ?string
    {
        $path = $this->pathBuilder->getCoreModulePathByModuleName($moduleName, $pathTransfer);

        if (!file_exists($path)) {
            return null;
        }

        return $path;
    }
668389
private function getCommandNamespace(array $composer)
    {
        if(! $this->isset('autoload.psr-4', $composer)) {
            return null;
        }

        foreach($composer['autoload']['psr-4'] as $namespace => $folder) {
            if($folder === 'src/') return $namespace . 'Commands\\';
        }
        return null;
    }
165819
protected function parseComposerJsonFiles ()
    {
        // First find all composer.json files that match pattern vendor-dev/*/*/composer.json
        $composerJsonFiles = array();

        $DirRoot = new \DirectoryIterator($this->rootPath);
        foreach ($DirRoot as $FileInRoot) {
            // Ignore non-directories
            if (!$FileInRoot->isDir()) {
                continue;
            }
            if ($FileInRoot->isDot()) {
                continue;
            }

            // Check if composer.json is present here - if so, do not recurse deeper
            $composerFile = $FileInRoot->getPathname() .'/composer.json';
            if (file_exists($composerFile)) {
                $composerJsonFiles[$composerFile] = $composerFile;
                continue;
            }

            $DirVendor = new \DirectoryIterator($FileInRoot->getPathname());
            foreach ($DirVendor as $FileInVendor) {
                // Ignore non-directories
                if (!$FileInVendor->isDir()) {
                    continue;
                }
                if ($FileInVendor->isDot()) {
                    continue;
                }

                $composerFile = $FileInVendor->getPathname() .'/composer.json';
                if (file_exists($composerFile)) {
                    $composerJsonFiles[$composerFile] = $composerFile;
                }
            }
        }

        // Sort by path to get predictable results
        ksort($composerJsonFiles);

        // Now parse all composer.jsons and extract namespace information
        foreach ($composerJsonFiles as $cjfPath) {
            $cjf = json_decode(file_get_contents($cjfPath), true);

            // Signal invalid json
            if (NULL === $cjf) {
                throw new \Exception("Unparseable composer.json file: '$cjfPath'");
            }

            // Skip if no autoload or no psr-4 section is present
            if (!isset($cjf['autoload'])) {
                continue;
            }
            if (!isset($cjf['autoload']['psr-4'])) {
                continue;
            }

            foreach ($cjf['autoload']['psr-4'] as $namespace => $relPath) {
                $absPath = dirname($cjfPath) .'/'. $relPath;

                // Do not allow overlapping namespaces for now
                if (isset($this->nsData[$namespace])) {
                    throw new \Exception("VendorDevLoader error: duplicate namespace definition. First instance defined in '". $this->namespace2path[$namespace]["composerJsonPath"] ."', second instance found in '$cjfPath'");
                }

                $this->nsData[$namespace] = array(
                    'namespace'        => $namespace,
                    'relPath'          => $relPath,
                    'absPath'          => $absPath,
                    'composerJsonPath' => $cjfPath,
                );
            }
        }

        // Now reverse sort it, so that the most specific namespace definition gets evaluated first
        krsort($this->nsData);
    }
1278878
public function GetComposer() {

		$filepath = "{$this->ProjectRoot}/composer.json";

		try { $composer = new Nether\Project\Composer($filepath); }
		catch(Exception $e) {
			$this->ShowMessage($e->getMessage());
			exit(0);
		}

		return $composer;
	}