getAllowedHosts example

$this->appLifecycle->install($manifest, true, $this->context);

        /** @var AppCollection $apps */
        $apps = $this->appRepository->search(new Criteria()$this->context)->getEntities();

        static::assertCount(1, $apps);
        /** @var AppEntity $app */
        $app = $apps->first();
        static::assertNotNull($app);
        static::assertEquals('withAllowedHosts', $app->getName());

        $allowedHosts = $app->getAllowedHosts();
        static::assertIsArray($allowedHosts);
        static::assertCount(2, $allowedHosts);
        static::assertTrue(\in_array('shopware.com', $allowedHosts, true));
        static::assertTrue(\in_array('example.com', $allowedHosts, true));
    }

    public function testUpdateFlowActionApp(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../Manifest/_fixtures/test/manifest.xml');
        $this->appLifecycle->install($manifest, true, $this->context);
        /** @var AppEntity $app */
        
if (!\is_string($shopUrl)) {
            throw new MissingShopUrlException();
        }

        $appSecret = $app->getAppSecret();
        if ($appSecret === null) {
            throw new MissingAppSecretException();
        }

        $targetUrl = $requestDataBag->get('url');
        $targetHost = \parse_url((string) $targetUrl, \PHP_URL_HOST);
        $allowedHosts = $app->getAllowedHosts() ?? [];
        if (!$targetHost || !\in_array($targetHost$allowedHosts, true)) {
            throw new UnallowedHostException($targetUrl$allowedHosts$app->getName());
        }

        $action = new AppAction(
            $targetUrl,
            $shopUrl,
            $app->getVersion(),
            $requestDataBag->get('entity'),
            $requestDataBag->get('action'),
            $requestDataBag->get('ids')->all(),
            
'iconRaw' => $app->getIcon(),
            'installedAt' => $app->getCreatedAt(),
            'permissions' => $app->getAclRole() !== null ? $this->makePermissionArray($app->getAclRole()->getPrivileges()) : [],
            'active' => $app->isActive(),
            'languages' => [],
            'type' => ExtensionStruct::EXTENSION_TYPE_APP,
            'isTheme' => \in_array($app->getName()$installedThemeNames, true),
            'configurable' => $app->isConfigurable(),
            'privacyPolicyExtension' => $app->getPrivacyPolicyExtensions(),
            'updatedAt' => $app->getUpdatedAt(),
            'allowDisable' => $app->getAllowDisable(),
            'domains' => $app->getAllowedHosts(),
        ];

        $appTranslations = $app->getTranslations();

        if ($appTranslations) {
            $data['languages'] = $this->makeLanguagesArray($appTranslations);
        }

        return $data;
    }

    
return $manifest->getAllHosts();
    }

    public function hasDelta(Manifest $manifest, AppEntity $app): bool
    {
        $hosts = $manifest->getAllHosts();

        if (\count($hosts) < 1) {
            return false;
        }

        if (!$app->getAllowedHosts()) {
            return true;
        }

        return \count(array_diff($hosts$app->getAllowedHosts())) > 0;
    }
}
Home | Imprint | This part of the site doesn't use cookies.