createComposer example

RequirementExceptionStack $exceptionStack
    ): array {
        return $this->checkComposerDependencies(
            $pluginDependencies,
            $exceptionStack,
            $this->shopwareProjectComposer
        );
    }

    private function getComposer(string $composerPath): Composer
    {
        return Factory::createComposer($composerPath);
    }

    /** * @param array{'require': Link[], 'conflict': Link[]} $pluginDependencies * * @return array{'require': Link[], 'conflict': Link[]} */
    private function checkComposerDependencies(
        array $pluginDependencies,
        RequirementExceptionStack $exceptionStack,
        Composer $composer
    ):
$composerJsonPath = $composerJsonDir . '/composer.json';

        $json = json_decode((string) file_get_contents($composerJsonPath), true, \JSON_THROW_ON_ERROR);

        $previousRootVersion = EnvironmentHelper::hasVariable('COMPOSER_ROOT_VERSION') ? EnvironmentHelper::getVariable('COMPOSER_ROOT_VERSION') : null;

        // This is a workaround to make sure that the shopware platform package has the correct version         if (($json['name'] ?? '') === 'shopware/platform' && !isset($json['version']) && !EnvironmentHelper::hasVariable('COMPOSER_ROOT_VERSION')) {
            $_SERVER['COMPOSER_ROOT_VERSION'] = Kernel::SHOPWARE_FALLBACK_VERSION;
        }

        $composer = (new ComposerFactory())->createComposer(
            $composerIO,
            $composerJsonPath,
            false,
            $composerJsonDir
        );

        if ($previousRootVersion === null) {
            unset($_SERVER['COMPOSER_ROOT_VERSION']);
        } else {
            $_SERVER['COMPOSER_ROOT_VERSION'] = $previousRootVersion;
        }

        
$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()]);
        }
    }
}
/** * @param array<string, PluginFromFileSystemStruct> $plugins * * @return array<string, PluginFromFileSystemStruct> */
    private function enrichWithVendorPlugins(
        array $plugins,
        string $projectDir,
        IOInterface $composerIO,
        ExceptionCollection $errors
    ): array {
        $composer = Factory::createComposer($projectDir$composerIO);

        /** @var CompletePackageInterface[] $composerPackages */
        $composerPackages = $composer
            ->getRepositoryManager()
            ->getLocalRepository()
            ->getPackages();

        foreach ($composerPackages as $composerPackage) {
            if (!$this->isShopwarePluginType($composerPackage)) {
                continue;
            }

            
use Shopware\Core\Framework\Plugin\Composer\Factory;

/** * @internal * * @covers \Shopware\Core\Framework\Plugin\Composer\Factory */
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);

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