getParameter example


    public function generateMainThumbnails(ProductModel $article$force = false)
    {
        $generator = $this->getContainer()->get(Manager::class);

        $mediaService = Shopware()->Container()->get(MediaServiceInterface::class);

        foreach ($article->getImages() as $image) {
            $media = $image->getMedia();

            $projectDir = $this->getContainer()->getParameter('shopware.app.rootDir');

            if (!\is_string($projectDir)) {
                throw new RuntimeException('Parameter shopware.app.rootDir has to be a string');
            }

            if (!$force && $mediaService->has($projectDir . $media->getPath())) {
                continue;
            }

            foreach ($media->getThumbnailFilePaths() as $size => $path) {
                $generator->createMediaThumbnail($media[$size], true);
            }
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) {
    // Filter unselected items so we don't unnecessarily store giant arrays.     $options['vids'] = array_filter($options['vids']);
  }

  /** * {@inheritdoc} */
  public function getArgument() {
    // Load default argument from taxonomy page.     if (!empty($this->options['term_page'])) {
      if (($taxonomy_term = $this->routeMatch->getParameter('taxonomy_term')) && $taxonomy_term instanceof TermInterface) {
        return $taxonomy_term->id();
      }
    }
    // Load default argument from node.     if (!empty($this->options['node'])) {
      // Just check, if a node could be detected.       if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $taxonomy = [];
        foreach ($node->getFieldDefinitions() as $field) {
          if ($field->getType() == 'entity_reference' && $field->getSetting('target_type') == 'taxonomy_term') {
            $taxonomy_terms = $node->{$field->getName()}->referencedEntities();
            
$loaderResolver = new LoaderResolver([
            new XmlFileLoader($container$fileLocator),
            new YamlFileLoader($container$fileLocator),
            new PhpFileLoader($container$fileLocator),
        ]);
        $delegatingLoader = new DelegatingLoader($loaderResolver);

        foreach ($this->getServicesFilePathArray($this->getPath() . '/Resources/config/services.*') as $path) {
            $delegatingLoader->load($path);
        }

        if ($container->getParameter('kernel.environment') === 'test') {
            foreach ($this->getServicesFilePathArray($this->getPath() . '/Resources/config/services_test.*') as $testPath) {
                $delegatingLoader->load($testPath);
            }
        }
    }

    /** * @return list<string> */
    private function getServicesFilePathArray(string $path): array
    {
        
public function __construct(array $compiledRoutes, RequestContext $context, LoggerInterface $logger = null, string $defaultLocale = null)
    {
        $this->compiledRoutes = $compiledRoutes;
        $this->context = $context;
        $this->logger = $logger;
        $this->defaultLocale = $defaultLocale;
    }

    public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
    {
        $locale = $parameters['_locale']
            ?? $this->context->getParameter('_locale')
            ?: $this->defaultLocale;

        if (null !== $locale) {
            do {
                if (($this->compiledRoutes[$name.'.'.$locale][1]['_canonical_route'] ?? null) === $name) {
                    $name .= '.'.$locale;
                    break;
                }
            } while (false !== $locale = strstr($locale, '_', true));
        }

        
/** * @internal */
class ThemeFileImporterTest extends TestCase
{
    use KernelTestBehaviour;

    public function testFileExists(): void
    {
        $existingFile = realpath(__DIR__ . '/fixtures/SimpleTheme/Resources/theme.json');

        $projectDir = $this->getContainer()->getParameter('kernel.project_dir');

        $importer = new ThemeFileImporter($projectDir);
        static::assertFalse($importer->fileExists('random-file.twig'));
        static::assertTrue($importer->fileExists($existingFile));
    }

    public function testFileRealPath(): void
    {
        $existingFile = realpath(__DIR__ . '/fixtures/SimpleTheme/Resources/theme.json');

        $projectDir = $this->getContainer()->getParameter('kernel.project_dir');

        
use Shopware\Core\Framework\Log\Package;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

#[Package('core')] class AssetBundleRegistrationCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        /** @var array<class-string<Bundle>> $bundles */
        $bundles = $container->getParameter('kernel.bundles');

        $assetService = $container->getDefinition('assets.packages');
        $assetService->setFactory([AssetPackageService::class, 'create']);

        $bundleMap = [];

        foreach ($bundles as $bundleClass) {
            $reflection = new \ReflectionClass($bundleClass);
            $bundle = $reflection->newInstanceWithoutConstructor();

            if ($bundle instanceof Bundle) {
                
/** * @return void */
    public function process(ContainerBuilder $container)
    {
        $container->setAlias(LoggerInterface::class, 'logger');

        if ($container->has('logger')) {
            return;
        }

        if ($debug = $container->getParameter('kernel.debug')) {
            // Build an expression that will be equivalent to `!in_array(PHP_SAPI, ['cli', 'phpdbg'])`             $debug = (new Definition('bool'))
                ->setFactory('in_array')
                ->setArguments([
                    (new Definition('string'))->setFactory('constant')->setArguments(['PHP_SAPI']),
                    ['cli', 'phpdbg'],
                ]);
            $debug = (new Definition('bool'))
                ->setFactory('in_array')
                ->setArguments([$debug[false]]);
        }

        
$attemptedLanguage = substr($identity->locale->getLocale(), 0, 2);

        if (file_exists(Shopware()->DocPath() . 'engine/Library/TinyMce/langs/' . $attemptedLanguage . '.js')) {
            return $attemptedLanguage;
        }

        return 'en';
    }

    private function enableBrowserCache(): void
    {
        if ($this->container->getParameter('shopware.template.forceCompile')) {
            return;
        }

        $this->Response()->headers->set('cache-control', 'max-age=2592000, public', true);
    }
}

    }

    /** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var string $version */
        $version = $input->getOption('shopware-version');
        if (empty($version)) {
            $version = $this->container->getParameter('shopware.release.version');

            if (!\is_string($version)) {
                throw new RuntimeException('Parameter shopware.release.version has to be an string');
            }
        }

        $plugins = $this->container->get(\Shopware\Bundle\PluginInstallerBundle\Service\PluginLocalService::class)->getPluginsForUpdateCheck();
        $domain = $this->container->get('shopware_plugininstaller.account_manager_service')->getDomain();
        $service = $this->container->get('shopware_plugininstaller.plugin_service_view');
        $request = new UpdateListingRequest('', $version$domain$plugins);
        /** @var UpdateResultStruct $updates */
        
$refs = $types = [];
            foreach ($value->getValues() as $k => $v) {
                $refs[$k] = [$v, null];
                $types[$k] = $v instanceof TypedReference ? $v->getType() : '?';
            }
            $value = new ServiceLocator($this->resolveServices(...)$refs$types);
        } elseif ($value instanceof Reference) {
            $value = $this->doGet((string) $value$value->getInvalidBehavior()$inlineServices$isConstructorArgument);
        } elseif ($value instanceof Definition) {
            $value = $this->createService($value$inlineServices$isConstructorArgument);
        } elseif ($value instanceof Parameter) {
            $value = $this->getParameter((string) $value);
        } elseif ($value instanceof Expression) {
            $value = $this->getExpressionLanguage()->evaluate($value['container' => $this]);
        } elseif ($value instanceof AbstractArgument) {
            throw new RuntimeException($value->getTextWithContext());
        }

        return $value;
    }

    /** * Returns service ids for a given tag. * * Example: * * $container->register('foo')->addTag('my.tag', ['hello' => 'world']); * * $serviceIds = $container->findTaggedServiceIds('my.tag'); * foreach ($serviceIds as $serviceId => $tags) { * foreach ($tags as $tag) { * echo $tag['hello']; * } * } * * @return array<string, array> An array of tags with the tagged service as key, holding a list of attribute arrays */
$this->assertNotEmpty($results_cache_item, 'Results cache item found.');
        if ($results_cache_item) {
          $this->assertEqualsCanonicalizing($expected_results_cache$results_cache_item->tags);
        }
      }
      else {
        $this->assertNull($results_cache_item, 'Results cache item not found.');
      }

      // Check Views render cache item cache tags.       $original['#cache'] += ['contexts' => []];
      $original['#cache']['contexts'] = Cache::mergeContexts($original['#cache']['contexts']$this->container->getParameter('renderer.config')['required_cache_contexts']);

      $render_cache_item = $render_cache->get($original);
      if ($views_caching_is_enabled === TRUE) {
        $this->assertNotEmpty($render_cache_item, 'Render cache item found.');
        if ($render_cache_item) {
          $this->assertEqualsCanonicalizing($expected_render_array_cache_tags$render_cache_item['#cache']['tags']);
        }
      }
      else {
        $this->assertNull($render_cache_item, 'Render cache item not found.');
      }
    }
'cache.adapter.redis' => ShopwareRedisAdapter::class,
            'cache.adapter.redis_tag_aware' => ShopwareRedisTagAwareAdapter::class,
        ];

        foreach ($ids as $id => $class) {
            if (!$container->hasDefinition($id)) {
                continue;
            }

            $definition = $container->getDefinition($id);
            $definition->setClass($class);
            $definition->addArgument($container->getParameter('shopware.cache.redis_prefix'));
        }
    }
}

        $flatFiles = [];
        foreach ($files as $file) {
            $flatFiles[$file->getFilepath()] = $file->getResolveMapping();
        }

        static::assertEquals($expected$flatFiles);
    }

    private function stripProjectDir(string $path): string
    {
        $projectDir = $this->getContainer()->getParameter('kernel.project_dir');

        if (str_starts_with($path$projectDir)) {
            return substr($path, \strlen($projectDir) + 1);
        }

        return $path;
    }
}
public function process(ContainerBuilder $container)
    {
        foreach ($container->getAutoconfiguredInstanceof() as $interface => $definition) {
            if ($definition->getArguments()) {
                throw new InvalidArgumentException(sprintf('Autoconfigured instanceof for type "%s" defines arguments but these are not supported and should be removed.', $interface));
            }
        }

        $tagsToKeep = [];

        if ($container->hasParameter('container.behavior_describing_tags')) {
            $tagsToKeep = $container->getParameter('container.behavior_describing_tags');
        }

        foreach ($container->getDefinitions() as $id => $definition) {
            $container->setDefinition($id$this->processDefinition($container$id$definition$tagsToKeep));
        }

        if ($container->hasParameter('container.behavior_describing_tags')) {
            $container->getParameterBag()->remove('container.behavior_describing_tags');
        }
    }

    

    public function process(ContainerBuilder $container): void
    {
        if (!class_exists(AbstractUid::class)) {
            return;
        }

        if (!$container->hasParameter('doctrine.dbal.connection_factory.types')) {
            return;
        }

        $typeDefinition = $container->getParameter('doctrine.dbal.connection_factory.types');

        if (!isset($typeDefinition['uuid'])) {
            $typeDefinition['uuid'] = ['class' => UuidType::class];
        }

        if (!isset($typeDefinition['ulid'])) {
            $typeDefinition['ulid'] = ['class' => UlidType::class];
        }

        $container->setParameter('doctrine.dbal.connection_factory.types', $typeDefinition);
    }
}
Home | Imprint | This part of the site doesn't use cookies.