getSetup example


    protected function forEachInstalledApp(Context $context, callable $callback): void
    {
        $manifests = $this->appLoader->load();
        /** @var AppCollection $apps */
        $apps = $this->appRepository->search(new Criteria()$context)->getEntities();

        foreach ($manifests as $manifest) {
            $app = $this->getAppForManifest($manifest$apps);

            if (!$app || !$manifest->getSetup()) {
                continue;
            }

            $callback($manifest$app$context);
        }
    }

    protected function reRegisterApp(Manifest $manifest, AppEntity $app, Context $context): void
    {
        $secret = AccessKeyHelper::generateSecretAccessKey();

        
$appSecret = 'dont_tell';
        $appResponseBody = $this->buildAppResponse($manifest$appSecret);

        $this->appendNewResponse(new Response(200, []$appResponseBody));
        $this->appendNewResponse(new Response(200, []));

        $this->registrator->registerApp($manifest$id$secretAccessKey, Context::createDefaultContext());

        $registrationRequest = $this->getPastRequest(0);

        $setup = $manifest->getSetup();
        static::assertNotNull($setup);

        $uriWithoutQuery = $registrationRequest->getUri()->withQuery('');
        static::assertEquals($setup->getRegistrationUrl()(string) $uriWithoutQuery);
        static::assertNotEmpty($registrationRequest->getHeaderLine('sw-version'));
        static::assertNotEmpty($registrationRequest->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE));
        static::assertNotEmpty($registrationRequest->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE));

        $secret = $setup->getSecret();
        static::assertNotNull($secret);

        

    public function __construct(
        private readonly string $shopUrl,
        private readonly ShopIdProvider $shopIdProvider,
        private readonly StoreClient $storeClient,
        private readonly string $shopwareVersion
    ) {
    }

    public function create(Manifest $manifest): AppHandshakeInterface
    {
        $setup = $manifest->getSetup();
        $metadata = $manifest->getMetadata();
        $appName = $metadata->getName();

        if (!$setup) {
            throw AppException::registrationFailed(
                $appName,
                sprintf('No setup for registration provided in manifest for app "%s".', $metadata->getName())
            );
        }

        $privateSecret = $setup->getSecret();

        
$this->updateMetadata($metadata$context);

        $app = $this->loadApp($id$context);

        $this->updateCustomEntities($app->getId()$app->getPath()$manifest);

        $this->permissionPersister->updatePrivileges($manifest->getPermissions()$roleId);

        // If the app has no secret yet, but now specifies setup data we do a registration to get an app secret         // this mostly happens during install, but may happen in the update case if the app previously worked without an external server         if (!$app->getAppSecret() && $manifest->getSetup()) {
            try {
                $this->registrationService->registerApp($manifest$id$secretAccessKey$context);
            } catch (AppRegistrationException $e) {
                $this->removeAppAndRole($app$context);

                throw $e;
            }
        }

        // Refetch app to get secret after registration         $app = $this->loadApp($id$context);

        
private readonly HandshakeFactory $handshakeFactory,
        private readonly Client $httpClient,
        private readonly EntityRepository $appRepository,
        private readonly string $shopUrl,
        private readonly ShopIdProvider $shopIdProvider,
        private readonly string $shopwareVersion
    ) {
    }

    public function registerApp(Manifest $manifest, string $id, string $secretAccessKey, Context $context): void
    {
        if (!$manifest->getSetup()) {
            return;
        }

        try {
            $appName = $manifest->getMetadata()->getName();
            $appResponse = $this->registerWithApp($manifest$context);

            $secret = $appResponse['secret'];
            $confirmationUrl = $appResponse['confirmation_url'];

            $this->saveAppSecret($id$context$secret);

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