getInstallPath example

const VENDOR_PATTERN = '/^modules\/(?P<vendor>.+)\/.+/';

    /** @var array<string, string> */
    protected $locations = array(
        'module'    => 'modules/{$name}/',
        'theme'  => 'application/views/{$name}/',
        'out'    => 'out/{$name}/',
    );

    public function getInstallPath(PackageInterface $package, string $frameworkType = ''): string
    {
        $installPath = parent::getInstallPath($package$frameworkType);
        $type = $this->package->getType();
        if ($type === 'oxid-module') {
            $this->prepareVendorDirectory($installPath);
        }
        return $installPath;
    }

    /** * Makes sure there is a vendormetadata.php file inside * the vendor folder if there is a vendor folder. */
    
/** * Gets the installed path for a package. * * @param \Composer\Package\PackageInterface $package * The package. * * @return string * Path to the install path for the package, relative to the project. This * accounts for changes made by composer/installers, if any. */
  protected function getInstallPathForPackage(PackageInterface $package) {
    return $this->composer->getInstallationManager()->getInstallPath($package);
  }

  /** * Clean all configured packages. * * This applies in the context of a post-command event. */
  public function cleanAllPackages() {
    // Get a list of all the packages available after the update or install     // command.     $installed_packages = [];
    
method_exists(InstalledVersions::class, 'getInstalledPackagesByType')
            || !method_exists(InstalledVersions::class, 'getInstallPath')
        ) {
            throw new \RuntimeException('FallbackPluginLoader does only work with Composer 2.1 or higher');
        }

        $composerPlugins = InstalledVersions::getInstalledPackagesByType(PluginFinder::COMPOSER_TYPE);

        $this->pluginInfos = [];

        foreach ($composerPlugins as $composerName) {
            $path = InstalledVersions::getInstallPath($composerName);
            $composerJsonPath = $path . '/composer.json';

            if (!\file_exists($composerJsonPath)) {
                continue;
            }

            $composerJsonContent = \file_get_contents($composerJsonPath);
            \assert(\is_string($composerJsonContent));

            $composerJson = \json_decode($composerJsonContent, true, 512, \JSON_THROW_ON_ERROR);
            \assert(\is_array($composerJson));
            
return $manifests;
    }

    /** * @return array<string, Manifest> */
    private function loadFromComposer(): array
    {
        $manifests = [];

        foreach (InstalledVersions::getInstalledPackagesByType(self::COMPOSER_TYPE) as $packageName) {
            $path = InstalledVersions::getInstallPath($packageName);

            if ($path !== null) {
                try {
                    $manifest = Manifest::createFromXmlFile($path . '/manifest.xml');
                    $manifest->setManagedByComposer(true);

                    $manifests[$manifest->getMetadata()->getName()] = $manifest;
                } catch (XmlParsingException) {
                    // nth, if app is already registered it will be deleted                 }
            }
        }

    public function getInstallPath(PackageInterface $package, string $frameworkType = ''): string
    {
        if (
            $package->getName() == 'silverstripe/framework'
            && preg_match('/^\d+\.\d+\.\d+/', $package->getVersion())
            && version_compare($package->getVersion(), '2.999.999') < 0
        ) {
            return $this->templatePath($this->locations['module'], array('name' => 'sapphire'));
        }

        return parent::getInstallPath($package$frameworkType);
    }
}
$frameworkType = $this->findFrameworkType($type);

        if ($frameworkType === false) {
            throw new \InvalidArgumentException(
                'Sorry the package type of this package is not yet supported.'
            );
        }

        $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
        $installer = new $class($package$this->composer, $this->getIO());

        $path = $installer->getInstallPath($package$frameworkType);
        if (!$this->filesystem->isAbsolutePath($path)) {
            $path = getcwd() . '/' . $path;
        }

        return $path;
    }

    public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        $installPath = $this->getPackageBasePath($package);
        $io = $this->io;
        

  protected function getPackagePath(PackageInterface $package) {
    if ($package->getName() == $this->composer->getPackage()->getName()) {
      // This will respect the --working-dir option if Composer is invoked with       // it. There is no API or method to determine the filesystem path of       // a package's composer.json file.       return getcwd();
    }
    return $this->composer->getInstallationManager()->getInstallPath($package);
  }

}
Home | Imprint | This part of the site doesn't use cookies.