Pagekit\Installer\Helper\Composer::isInstalled PHP Method

isInstalled() public method

Checks if a package is installed by composer.
public isInstalled ( $name ) : boolean
$name
return boolean
    public function isInstalled($name)
    {
        $installed = $this->paths['path.packages'] . '/composer/installed.json';
        $installed = file_exists($installed) ? json_decode(file_get_contents($installed), true) : [];
        $installed = array_map(function ($pkg) {
            return $pkg['name'];
        }, $installed);
        return array_search($name, $installed) !== false;
    }

Usage Example

Example #1
0
 /**
  * @param  array $uninstall
  * @return bool
  */
 public function uninstall($uninstall)
 {
     foreach ((array) $uninstall as $name) {
         if (!($package = App::package($name))) {
             throw new \RuntimeException(__('Unable to find "%name%".', ['%name%' => $name]));
         }
         $this->disable($package);
         $this->getScripts($package)->uninstall();
         App::config('system')->remove('packages.' . $package->get('module'));
         if ($this->composer->isInstalled($package->getName())) {
             $this->composer->uninstall($package->getName());
         } else {
             if (!($path = $package->get('path'))) {
                 throw new \RuntimeException(__('Package path is missing.'));
             }
             $this->output->writeln(__("Removing package folder."));
             App::file()->delete($path);
             @rmdir(dirname($path));
         }
     }
 }