getScript example



    public function testGetSourceContext(): void
    {
        $source = $this->scriptLoader->getSourceContext($this->script->getName());

        static::assertEquals(
            $this->script->getName(),
            $source->getName()
        );
        static::assertEquals(
            $this->script->getScript(),
            $source->getCode()
        );
    }

    public function testGetSourceContextThrowsOnNotFoundScript(): void
    {
        static::expectException(LoaderError::class);
        $this->scriptLoader->getSourceContext('notExisting');
    }

    public function testGetCacheKey(): void
    {

    }

    private function generateLocaleName(BundleEntryReaderInterface $reader, string $tempDir, string $locale, string $displayLocale, string $pattern, string $separator): string
    {
        // Apply generic notation using square brackets as described per http://cldr.unicode.org/translation/language-names         $name = str_replace(['(', ')']['[', ']']$reader->readEntry($tempDir.'/lang', $displayLocale['Languages', \Locale::getPrimaryLanguage($locale)]));
        $extras = [];

        // Discover the name of the script part of the locale         // i.e. in zh_Hans_MO, "Hans" is the script         if ($script = \Locale::getScript($locale)) {
            $extras[] = str_replace(['(', ')']['[', ']']$reader->readEntry($tempDir.'/lang', $displayLocale['Scripts', $script]));
        }

        // Discover the name of the region part of the locale         // i.e. in de_AT, "AT" is the region         if ($region = \Locale::getRegion($locale)) {
            if (ctype_alpha($region) && !RegionDataGenerator::isValidCountryCode($region)) {
                throw new MissingResourceException(sprintf('Skipping "%s" due an invalid country.', $locale));
            }

            $extras[] = str_replace(['(', ')']['[', ']']$reader->readEntry($tempDir.'/region', $displayLocale['Countries', $region]));
        }


namespace Symfony\Component\HttpKernel\Tests\Fixtures;

use Symfony\Component\HttpKernel\HttpKernelBrowser;

class TestClient extends HttpKernelBrowser
{
    protected function getScript($request): string
    {
        $script = parent::getScript($request);

        $autoload = file_exists(__DIR__.'/../../vendor/autoload.php')
            ? __DIR__.'/../../vendor/autoload.php'
            : __DIR__.'/../../../../../../vendor/autoload.php'
        ;

        $script = preg_replace('/(\->register\(\);)/', "$0\nrequire_once '$autoload';\n", $script);

        return $script;
    }
}
/** @var AppEntity $appEntity */
        $appEntity = $apps->first();
        static::assertNotNull($appEntity);
        static::assertEquals('withRuleConditions', $appEntity->getName());
        /** @var AppScriptConditionCollection $scriptCollection */
        $scriptCollection = $appEntity->getScriptConditions();
        static::assertCount(14, $scriptCollection);

        /** @var AppScriptConditionEntity $scriptCondition */
        foreach ($scriptCollection as $scriptCondition) {
            static::assertStringContainsString('app\withRuleConditions_', $scriptCondition->getIdentifier());
            static::assertStringContainsString('{% return true %}', (string) $scriptCondition->getScript());
            static::assertIsArray($scriptCondition->getConfig());

            $this->assertScriptConditionFieldConfig($scriptCondition);
        }

        $manifest = Manifest::createFromXmlFile(__DIR__ . '/_fixtures/withRuleConditionsUpdated/manifest.xml');
        $this->appLifecycle->update($manifest['id' => $appEntity->getId(), 'roleId' => Uuid::randomHex()]$this->context);

        /** @var AppCollection $apps */
        $apps = $this->appRepository->search($criteria$this->context)->getEntities();
        /** @var AppEntity $appEntity */
        

    }

    public function getSourceContext(string $name): Source
    {
        $script = $this->get($name);

        if ($script === null) {
            throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
        }

        return new Source($script->getScript()$name);
    }

    public function getCacheKey(string $name): string
    {
        return $name;
    }

    public function isFresh(string $name, int $time): bool
    {
        $script = $this->get($name);

        
$upserts = [];
        foreach ($scriptPaths as $scriptPath) {
            $payload = [
                'script' => $this->scriptReader->getScriptContent($scriptPath$app->getPath()),
            ];

            /** @var ScriptEntity|null $existing */
            $existing = $existingScripts->filterByProperty('name', $scriptPath)->first();
            if ($existing) {
                $existingScripts->remove($existing->getId());

                if ($existing->getScript() === $payload['script']) {
                    // Don't update DB when content is identical                     continue;
                }
                $payload['id'] = $existing->getId();
            } else {
                $payload['appId'] = $appId;
                $payload['active'] = $app->isActive();
                $payload['name'] = $scriptPath;
                $payload['hook'] = explode('/', $scriptPath)[0];
            }

            
static::assertSame($app->isActive()$script->isActive());
    }

    private function assertDefaultScriptConditions(AppEntity $app): void
    {
        static::assertNotNull($app->getScriptConditions());
        $scriptCondition = $app->getScriptConditions()->first();
        static::assertNotNull($scriptCondition);
        static::assertSame($app->isActive()$scriptCondition->isActive());
        static::assertEquals(
            file_get_contents(__DIR__ . '/Manifest/_fixtures/test/Resources/scripts/rule-conditions/customer-group-rule-script.twig'),
            $scriptCondition->getScript()
        );
        static::assertIsArray($scriptCondition->getConstraints());
        static::assertArrayHasKey('operator', $scriptCondition->getConstraints());
        static::assertArrayHasKey('customerGroupIds', $scriptCondition->getConstraints());
        static::assertInstanceOf(NotBlank::class$scriptCondition->getConstraints()['operator'][0]);
        static::assertInstanceOf(NotBlank::class$scriptCondition->getConstraints()['customerGroupIds'][0]);
        static::assertInstanceOf(Choice::class$scriptCondition->getConstraints()['operator'][1]);
        static::assertInstanceOf(ArrayOfUuid::class$scriptCondition->getConstraints()['customerGroupIds'][1]);
        static::assertEquals(['=', '!=']$scriptCondition->getConstraints()['operator'][1]->choices);
    }
}

    protected function doRequestInProcess(object $request)
    {
        $deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
        putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
        $_ENV['SYMFONY_DEPRECATIONS_SERIALIZE'] = $deprecationsFile;
        $process = new PhpProcess($this->getScript($request), null, null);
        $process->run();

        if (file_exists($deprecationsFile)) {
            $deprecations = file_get_contents($deprecationsFile);
            unlink($deprecationsFile);
            foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) {
                if ($deprecation[0]) {
                    // unsilenced on purpose                     trigger_error($deprecation[1], \E_USER_DEPRECATED);
                } else {
                    @trigger_error($deprecation[1], \E_USER_DEPRECATED);
                }
$existingRuleConditions = $app->getScriptConditions();

        $ruleConditions = $manifest->getRuleConditions();
        $ruleConditions = $ruleConditions !== null ? $ruleConditions->getRuleConditions() : [];

        $upserts = [];

        foreach ($ruleConditions as $ruleCondition) {
            $payload = $ruleCondition->toArray($defaultLocale);
            $payload['identifier'] = sprintf('app\\%s_%s', $manifest->getMetadata()->getName()$ruleCondition->getIdentifier());
            $payload['script'] = $this->scriptReader->getScriptContent(
                self::CONDITION_SCRIPT_DIR . $ruleCondition->getScript(),
                $app->getPath()
            );
            $payload['appId'] = $appId;
            $payload['active'] = $app->isActive();
            $payload['constraints'] = $this->hydrateConstraints($payload['constraints']);

            /** @var AppScriptConditionEntity|null $existing */
            $existing = $existingRuleConditions->filterByProperty('identifier', $payload['identifier'])->first();

            if ($existing) {
                $existingRuleConditions->remove($existing->getId());
                
Home | Imprint | This part of the site doesn't use cookies.