getPackage example


  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);
  }

}

  public function getAllowedPackages() {
    $top_level_packages = $this->getTopLevelAllowedPackages();
    $allowed_packages = $this->recursiveGetAllowedPackages($top_level_packages);
    // If the root package defines any file mappings, then implicitly add it     // to the list of allowed packages. Add it at the end so that it overrides     // all the preceding packages.     if ($this->manageOptions->getOptions()->hasFileMapping()) {
      $root_package = $this->composer->getPackage();
      unset($allowed_packages[$root_package->getName()]);
      $allowed_packages[$root_package->getName()] = $root_package;
    }
    // Handle any newly-added packages that are not already allowed.     return $this->evaluateNewPackages($allowed_packages);
  }

  /** * {@inheritdoc} */
  public function event(PackageEvent $event) {
    

    return [];
  }

  /** * Gets the root package name. * * @return string * The package name of the root project */
  protected function rootPackageName() {
    $root_package = $this->composer->getPackage();
    return $root_package->getName();
  }

}
$vendor = '';
            $name = $prettyName;
        }

        $availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type'));

        $extra = $package->getExtra();
        if (!empty($extra['installer-name'])) {
            $availableVars['name'] = $extra['installer-name'];
        }

        $extra = $this->composer->getPackage()->getExtra();
        if (!empty($extra['installer-paths'])) {
            $customPath = $this->mapCustomInstallPaths($extra['installer-paths']$prettyName$type$vendor);
            if ($customPath !== false) {
                return $this->templatePath($customPath$availableVars);
            }
        }

        $packageType = substr($typestrlen($frameworkType) + 1);
        $locations = $this->getLocations($frameworkType);
        if (!isset($locations[$packageType])) {
            throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type));
        }
public function uninstall(Composer $composer, IOInterface $io): void
    {
        @unlink($composer->getConfig()->get('vendor-dir').'/autoload_runtime.php');
    }

    public function updateAutoloadFile(): void
    {
        $vendorDir = realpath($this->composer->getConfig()->get('vendor-dir'));

        if (!is_file($autoloadFile = $vendorDir.'/autoload.php')
            || false === $extra = $this->composer->getPackage()->getExtra()['runtime'] ?? []
        ) {
            return;
        }

        $fs = new Filesystem();
        $projectDir = \dirname(realpath(Factory::getComposerFile()));

        if (null === $autoloadTemplate = $extra['autoload_template'] ?? null) {
            $autoloadTemplate = __DIR__.'/autoload_runtime.template';
        } else {
            if (!$fs->isAbsolutePath($autoloadTemplate)) {
                
/** * Add vendor classes to Composer's static classmap. * * @param \Composer\Script\Event $event * The event. */
  public static function preAutoloadDump(Event $event) {
    // Get the configured vendor directory.     $vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir');

    // We need the root package so we can add our classmaps to its loader.     $package = $event->getComposer()->getPackage();
    // We need the local repository so that we can query and see if it's likely     // that our files are present there.     $repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
    // This is, essentially, a null constraint. We only care whether the package     // is present in the vendor directory yet, but findPackage() requires it.     $constraint = new Constraint('>', '');
    // It's possible that there is no classmap specified in a custom project     // composer.json file. We need one so we can optimize lookup for some of our     // dependencies.     $autoload = $package->getAutoload();
    if (!isset($autoload['classmap'])) {
      
/** * Look for installers set to be disabled in composer's extra config and * remove them from the list of supported installers. * * Globals: * - true, "all", and "*" - disable all installers. * - false - enable all installers (useful with * wikimedia/composer-merge-plugin or similar) */
    protected function removeDisabledInstallers(): void
    {
        $extra = $this->composer->getPackage()->getExtra();

        if (!isset($extra['installer-disable']) || $extra['installer-disable'] === false) {
            // No installers are disabled             return;
        }

        // Get installers to disable         $disable = $extra['installer-disable'];

        // Ensure $disabled is an array         if (!is_array($disable)) {
            
$errors = [...$errors, ...$publishErrors];
        if (\count($errors) !== 0) {
            throw new PluginComposerJsonInvalidException($composerJsonPath$errors);
        }

        if (\count($warnings) !== 0) {
            $warningsString = implode("\n", $warnings);
            $composerIO->write(sprintf("Attention!\nThe '%s' has some warnings:\n%s", $composerJsonPath$warningsString));
        }

        try {
            return Factory::createComposer($pluginPath$composerIO)->getPackage();
        } catch (\InvalidArgumentException $e) {
            throw new PluginComposerJsonInvalidException($pluginPath . '/composer.json', [$e->getMessage()]);
        }
    }
}
public function __construct(Composer $composer) {
    $this->composer = $composer;
  }

  /** * Gets the root-level scaffold options for this project. * * @return \Drupal\Composer\Plugin\Scaffold\ScaffoldOptions * The scaffold options object. */
  public function getOptions() {
    return $this->packageOptions($this->composer->getPackage());
  }

  /** * Gets the scaffold options for the stipulated project. * * @param \Composer\Package\PackageInterface $package * The package to fetch the scaffold options from. * * @return \Drupal\Composer\Plugin\Scaffold\ScaffoldOptions * The scaffold options object. */
  
return $this->packages[$name];
    }

    /** * Gets the version to add to public URL. * * @param string $path A public path * @param string|null $packageName A package name */
    public function getVersion(string $path, string $packageName = null): string
    {
        return $this->getPackage($packageName)->getVersion($path);
    }

    /** * Returns the public path. * * Absolute paths (i.e. http://...) are returned unmodified. * * @param string $path A public path * @param string|null $packageName The name of the asset package to use * * @return string A public path which takes into account the base path and URL path */
$compilerPass = new AssetBundleRegistrationCompilerPass();

        $container->addCompilerPass($compilerPass);
        $compilerPass->process($container);

        $container->set('shopware.asset.asset_without_versioning', $this->createMock(Package::class));

        /** @var Packages $assetService */
        $assetService = $container->get('assets.packages');

        $assetService->getPackage('@Framework');

        static::expectException(InvalidArgumentException::class);
        $assetService->getPackage('@FrameworkBundle');
    }
}
/** * Tests all of the various kinds of builders. * * @dataProvider builderTestData */
  public function testBuilder($builderClass$expected) {
    $fixtures = new Fixtures();
    $drupalCoreInfo = $fixtures->drupalCoreComposerFixture();

    $builder = new $builderClass($drupalCoreInfo);
    $generatedJson = $builder->getPackage();

    $this->assertEquals($expected$generatedJson);
  }

}

class FactoryTest extends TestCase
{
    public function testCreateComposer(): void
    {
        $composer = Factory::createComposer(__DIR__ . '/../_fixtures/core');
        static::assertInstanceOf(Composer::class$composer);

        static::assertSame('shopware/platform', $composer->getPackage()->getName());
        static::assertSame('6.5.9999999.9999999-dev', $composer->getPackage()->getVersion());
    }

    public function testCreateComposerWithVersion(): void
    {
        $_SERVER['COMPOSER_ROOT_VERSION'] = '6.4.9999999.9999999-dev';
        $composer = Factory::createComposer(__DIR__ . '/../_fixtures/core');
        static::assertInstanceOf(Composer::class$composer);

        static::assertSame('shopware/platform', $composer->getPackage()->getName());
        static::assertSame('6.4.9999999.9999999-dev', $composer->getPackage()->getVersion());

        
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;

class PackagesTest extends TestCase
{
    public function testGetterSetters()
    {
        $packages = new Packages();
        $packages->setDefaultPackage($default = $this->createMock(PackageInterface::class));
        $packages->addPackage('a', $a = $this->createMock(PackageInterface::class));

        $this->assertSame($default$packages->getPackage());
        $this->assertSame($a$packages->getPackage('a'));

        $packages = new Packages($default['a' => $a]);

        $this->assertSame($default$packages->getPackage());
        $this->assertSame($a$packages->getPackage('a'));
    }

    public function testGetVersion()
    {
        $packages = new Packages(
            
$events = $this->flowActionCollector->collect($context);

        return new JsonResponse($events);
    }

    /** * @return array<string, array{type: 'plugin', css: string[], js: string[], baseUrl: ?string }|array{type: 'app', name: string, active: bool, integrationId: string, baseUrl: string, version: string, permissions: array<string, string[]>}> */
    private function getBundles(): array
    {
        $assets = [];
        $package = $this->packages->getPackage('asset');

        foreach ($this->kernel->getBundles() as $bundle) {
            if (!$bundle instanceof Bundle) {
                continue;
            }

            $bundleDirectoryName = preg_replace('/bundle$/', '', mb_strtolower($bundle->getName()));
            if ($bundleDirectoryName === null) {
                throw ApiException::unableGenerateBundle($bundle->getName());
            }

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