findSnippets example


    public function findSnippets(string $locale): array
    {
        $cacheKey = $this->getCacheKey($locale);
        $item = $this->cache->getItem($cacheKey);

        if ($item->isHit()) {
            return $item->get();
        }

        $snippets = $this->snippetFinder->findSnippets($locale);

        $item->set($snippets);
        $item->tag(self::CACHE_TAG);
        $this->cache->save($item);

        return $snippets;
    }

    private function getCacheKey(string $locale): string
    {
        return 'admin_snippet_' . $locale;
    }
'cspNonce' => $request->attributes->get(PlatformRequest::ATTRIBUTE_CSP_NONCE),
            'adminEsEnable' => $this->esAdministrationEnabled,
            'storefrontEsEnable' => $this->esStorefrontEnabled,
        ]);
    }

    #[Route(path: '/api/_admin/snippets', name: 'api.admin.snippets', methods: ['GET'])]     public function snippets(Request $request): Response
    {
        $snippets = [];
        $locale = $request->query->get('locale', 'en-GB');
        $snippets[$locale] = $this->snippetFinder->findSnippets((string) $locale);

        if ($locale !== 'en-GB') {
            $snippets['en-GB'] = $this->snippetFinder->findSnippets('en-GB');
        }

        return new JsonResponse($snippets);
    }

    #[Route(path: '/api/_admin/known-ips', name: 'api.admin.known-ips', methods: ['GET'])]     public function knownIps(Request $request): Response
    {
        

class SnippetFinderTest extends TestCase
{
    public function testFindSnippetsFromAppNoSnippetsAdded(): void
    {
        $snippetFinder = new SnippetFinder(
            $this->getKernelWithNoPlugins(),
            $this->getConnectionMock('en-GB', [])
        );

        $snippets = $snippetFinder->findSnippets('en-GB');
        static::assertArrayNotHasKey('my-custom-snippet-key', $snippets);
    }

    public function testFindSnippetsFromApp(): void
    {
        $snippetFinder = new SnippetFinder(
            $this->getKernelWithNoPlugins(),
            $this->getConnectionMock('en-GB', $this->getSnippetFixtures())
        );

        $snippets = $snippetFinder->findSnippets('en-GB');

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