Composer\Satis\PackageSelection\PackageSelection::load PHP Method

load() public method

Loads previously dumped Packages in order to merge with updates.
public load ( ) : Composer\Package\PackageInterface[]
return Composer\Package\PackageInterface[]
    public function load()
    {
        $packages = [];
        $repoJson = new JsonFile($this->filename);
        $dirName = dirname($this->filename);
        if ($repoJson->exists()) {
            $loader = new ArrayLoader();
            $packagesJson = $repoJson->read();
            $jsonIncludes = isset($packagesJson['includes']) && is_array($packagesJson['includes']) ? $packagesJson['includes'] : [];
            if (isset($packagesJson['providers']) && is_array($packagesJson['providers']) && isset($packagesJson['providers-url'])) {
                $baseUrl = $this->homepage ? parse_url(rtrim($this->homepage, '/'), PHP_URL_PATH) . '/' : null;
                $baseUrlLength = strlen($baseUrl);
                foreach ($packagesJson['providers'] as $packageName => $provider) {
                    $file = str_replace(['%package%', '%hash%'], [$packageName, $provider['sha256']], $packagesJson['providers-url']);
                    if ($baseUrl && substr($file, 0, $baseUrlLength) === $baseUrl) {
                        $file = substr($file, $baseUrlLength);
                    }
                    $jsonIncludes[$file] = $provider;
                }
            }
            foreach ($jsonIncludes as $includeFile => $includeConfig) {
                $includeJson = new JsonFile($dirName . '/' . $includeFile);
                if (!$includeJson->exists()) {
                    $this->output->writeln(sprintf('<error>File \'%s\' does not exist, defined in "includes" in \'%s\'</error>', $includeJson->getPath(), $repoJson->getPath()));
                    continue;
                }
                $jsonPackages = $includeJson->read();
                $jsonPackages = isset($jsonPackages['packages']) && is_array($jsonPackages['packages']) ? $jsonPackages['packages'] : [];
                foreach ($jsonPackages as $jsonPackage) {
                    if (is_array($jsonPackage)) {
                        foreach ($jsonPackage as $jsonVersion) {
                            if (is_array($jsonVersion)) {
                                if (isset($jsonVersion['name']) && in_array($jsonVersion['name'], $this->packagesFilter)) {
                                    continue;
                                }
                                $package = $loader->load($jsonVersion);
                                $packages[$package->getUniqueName()] = $package;
                            }
                        }
                    }
                }
            }
        }
        return $packages;
    }

Usage Example

Ejemplo n.º 1
0
 public function testPackageNotInFilter()
 {
     /*
      * json filename + filterPackages :
      *   package in json + not in filter => selected (to be merged as is)
      */
     $this->selection->setPackagesFilter(['othervendor/othername']);
     $this->assertNotEmpty($this->selection->load());
 }
All Usage Examples Of Composer\Satis\PackageSelection\PackageSelection::load