GrumPHP\Util\Composer::loadRootPackageFromJson PHP Метод

loadRootPackageFromJson() публичный статический Метод

public static loadRootPackageFromJson ( string | Composer\Json\JsonFile $json, Composer\Config $config = null ) : Composer\Package\RootPackageInterface
$json string | Composer\Json\JsonFile
$config Composer\Config
Результат Composer\Package\RootPackageInterface
    public static function loadRootPackageFromJson($json, Config $config = null)
    {
        try {
            $config = null !== $config ? $config : self::loadConfiguration();
            $loader = new JsonLoader(new RootPackageLoader(RepositoryFactory::manager(new NullIO(), $config), $config));
            $package = $loader->load($json);
        } catch (Exception $e) {
            throw RuntimeException::fromAnyException($e);
        }
        return $package;
    }

Usage Example

Пример #1
0
 /**
  * @return Helper\ComposerHelper
  */
 protected function initializeComposerHelper()
 {
     if ($this->composerHelper) {
         return $this->composerHelper;
     }
     try {
         $composerFile = getcwd() . DIRECTORY_SEPARATOR . 'composer.json';
         $configuration = Composer::loadConfiguration();
         Composer::ensureProjectBinDirInSystemPath($configuration->get('bin-dir'));
         $rootPackage = Composer::loadRootPackageFromJson($composerFile, $configuration);
     } catch (RuntimeException $e) {
         $configuration = null;
         $rootPackage = null;
     }
     return $this->composerHelper = new Helper\ComposerHelper($configuration, $rootPackage);
 }