Vinkla\Climb\Composer::getInstalledPackages PHP Method

getInstalledPackages() public method

Get installed package versions.
public getInstalledPackages ( ) : array
return array
    public function getInstalledPackages()
    {
        $packages = [];
        $content = $this->getFileContents('composer.lock');
        foreach (['packages', 'packages-dev'] as $key) {
            if (!isset($content[$key])) {
                continue;
            }
            foreach ($content[$key] as $package) {
                $name = $package['name'];
                $packages[$name] = ['name' => $name, 'version' => $package['version'], 'devDependency' => $key === 'packages-dev'];
            }
        }
        if (empty($packages)) {
            throw new LogicException('We couldn\'t find any installed packages.');
        }
        return $packages;
    }

Usage Example

Example #1
0
 /**
  * Get outdated packages with their current and latest version.
  *
  * @return array
  */
 public function getOutdatedPackages()
 {
     // Get all installed and required packages.
     $installed = $this->composer->getInstalledPackages();
     $required = $this->composer->getRequiredPackages();
     $outdated = [];
     // Get the installed version number of the required packages.
     $packages = array_intersect_key($installed, $required);
     foreach ($packages as $name => $version) {
         $package = new Package($name, Version::normalize($version), $required[$name]);
         if ($package->isOutdated()) {
             $outdated[] = $package;
         }
     }
     return $outdated;
 }
All Usage Examples Of Vinkla\Climb\Composer::getInstalledPackages