getDefinition example


#[Package('buyers-experience')] class ProductPageSeoUrlRouteTest extends TestCase
{
    public function testGetConfig(): void
    {
        $productDefinition = $this->createMock(ProductDefinition::class);
        $route = new ProductPageSeoUrlRoute($productDefinition);

        $config = $route->getConfig();
        static::assertSame($productDefinition$config->getDefinition());
        static::assertSame(ProductPageSeoUrlRoute::ROUTE_NAME, $config->getRouteName());
        static::assertSame(ProductPageSeoUrlRoute::DEFAULT_TEMPLATE, $config->getTemplate());
        static::assertTrue($config->getSkipInvalid());
    }

    public function testCriteria(): void
    {
        $route = new ProductPageSeoUrlRoute($this->createMock(ProductDefinition::class));

        $criteria = new Criteria();
        $salesChannel = new SalesChannelEntity();
        
/** * Updates configuration entity in the key store. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */
  public function onConfigSave(ConfigCrudEvent $event) {
    $saved_config = $event->getConfig();
    $entity_type_id = $this->configManager->getEntityTypeIdByName($saved_config->getName());
    if ($entity_type_id) {
      $entity_type = $this->configManager->getEntityTypeManager()->getDefinition($entity_type_id);
      $this->updateConfigKeyStore($entity_type$saved_config);
    }
  }

  /** * Removes configuration entity from key store. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */
  public function onConfigDelete(ConfigCrudEvent $event) {
    
$resolver = $container->register('argument_resolver.service')->addArgument([]);

        $container->register('stdClass', 'stdClass');
        $container->register(TestCase::class, 'stdClass');
        $container->register('c1', RemoveTestController1::class)->addTag('controller.service_arguments');
        $container->register('c2', RemoveTestController2::class)->addTag('controller.service_arguments')
            ->addMethodCall('setTestCase', [new Reference('c1')]);

        $pass = new RegisterControllerArgumentLocatorsPass();
        $pass->process($container);

        $controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);

        $this->assertCount(2, $container->getDefinition((string) $controllers['c1::fooAction']->getValues()[0])->getArgument(0));
        $this->assertCount(1, $container->getDefinition((string) $controllers['c2::setTestCase']->getValues()[0])->getArgument(0));
        $this->assertCount(1, $container->getDefinition((string) $controllers['c2::fooAction']->getValues()[0])->getArgument(0));

        (new ResolveInvalidReferencesPass())->process($container);

        $this->assertCount(1, $container->getDefinition((string) $controllers['c2::setTestCase']->getValues()[0])->getArgument(0));
        $this->assertSame([]$container->getDefinition((string) $controllers['c2::fooAction']->getValues()[0])->getArgument(0));

        (new RemoveEmptyControllerArgumentLocatorsPass())->process($container);

        
public function normalize(Field $field, array $data, WriteParameterBag $parameters): array
    {
        if (!$field instanceof ReferenceVersionField) {
            throw DataAbstractionLayerException::invalidSerializerField(ReferenceVersionField::class$field);
        }

        $value = $data[$field->getPropertyName()] ?? null;
        if ($value === null && !$field->is(Required::class)) {
            return $data;
        }

        $definition = $parameters->getDefinition();

        $reference = $field->getVersionReferenceDefinition();

        $context = $parameters->getContext();

        if ($value !== null || $definition === $reference) {
            // parent inheritance with versioning             $value ??= Defaults::LIVE_VERSION;
        } elseif ($context->has($reference->getEntityName(), 'versionId')) {
            // if the reference is already written, use the version id of the written entity             $value = $context->get($reference->getEntityName(), 'versionId');
        }
try {
            foreach ($container->getDefinitions() as $id => $definition) {
                if ($definition->isPublic() && !$definition->isPrivate() && !isset($this->resolvedIds[$id])) {
                    $this->resolvedIds[$id] = true;
                    $this->processValue($definition, true);
                }
            }

            foreach ($container->getAliases() as $alias) {
                if ($alias->isPublic() && !$alias->isPrivate() && !isset($this->resolvedIds[$id = (string) $alias]) && $container->hasDefinition($id)) {
                    $this->resolvedIds[$id] = true;
                    $this->processValue($container->getDefinition($id), true);
                }
            }
        } finally {
            $this->resolvedIds = [];
            $this->container = null;
        }

        foreach ($container->getDefinitions() as $definition) {
            if ($definition->hasTag(self::DO_PRELOAD_TAG)) {
                $definition->clearTag(self::DO_PRELOAD_TAG);
            } elseif (!$definition->isDeprecated() && !$definition->hasErrors()) {
                
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/** * @deprecated since shopware 5.7.3 and will be removed with 5.8 */
class SitemapCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        foreach (array_keys($container->findTaggedServiceIds('sitemap_url_provider')) as $id) {
            $def = $container->getDefinition($id);
            $def->setPublic(true);
        }
    }
}

    return $config;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();

    // Create dependency on the bundle.     $entity_type = \Drupal::entityTypeManager()->getDefinition($this->target_entity_type_id);
    $bundle_config_dependency = $entity_type->getBundleConfigDependency($this->target_bundle);
    $this->addDependency($bundle_config_dependency['type']$bundle_config_dependency['name']);

    return $this;
  }

}
protected function processValue(mixed $value, bool $isRoot = false): mixed
    {
        if (\is_string($value)) {
            try {
                $v = $this->bag->resolveValue($value);
            } catch (ParameterNotFoundException $e) {
                if ($this->throwOnResolveException) {
                    throw $e;
                }

                $v = null;
                $this->container->getDefinition($this->currentId)->addError($e->getMessage());
            }

            return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
        }
        if ($value instanceof Definition) {
            $value->setBindings($this->processValue($value->getBindings()));
            $changes = $value->getChanges();
            if (isset($changes['class'])) {
                $value->setClass($this->bag->resolveValue($value->getClass()));
            }
            if (isset($changes['file'])) {
                
public function testProcess()
    {
        $container = new ContainerBuilder();
        $container->register('routing.resolver', LoaderResolver::class);
        $container->register('loader1')->addTag('routing.loader');
        $container->register('loader2')->addTag('routing.loader');

        (new RoutingResolverPass())->process($container);

        $this->assertEquals(
            [['addLoader', [new Reference('loader1')]]['addLoader', [new Reference('loader2')]]],
            $container->getDefinition('routing.resolver')->getMethodCalls()
        );
    }
}

class JsonapiServiceProvider implements ServiceModifierInterface, ServiceProviderInterface {

  /** * {@inheritdoc} */
  public function alter(ContainerBuilder $container) {
    if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), NegotiationMiddleware::class, TRUE)) {
      // @see http://www.iana.org/assignments/media-types/application/vnd.api+json       $container->getDefinition('http_middleware.negotiation')
        ->addMethodCall('registerFormat', [
          'api_json',
          ['application/vnd.api+json'],
        ]);
    }
  }

  /** * {@inheritdoc} */

  protected function calculateRelatableResourceTypes(ResourceType $resource_type, array $resource_types) {
    // For now, only fieldable entity types may contain relationships.     $entity_type = $this->entityTypeManager->getDefinition($resource_type->getEntityTypeId());
    if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      $field_definitions = $this->entityFieldManager->getFieldDefinitions(
        $resource_type->getEntityTypeId(),
        $resource_type->getBundle()
      );

      $relatable_internal = array_map(function D$field_definition) use ($resource_types) {
        return $this->getRelatableResourceTypesFromFieldDefinition($field_definition$resource_types);
      }array_filter($field_definitionsfunction D$field_definition) {
        return $this->isReferenceFieldDefinition($field_definition);
      }));

      
'options' => ['key' => 'value'],
    ];

    $this->pluginDiscovery->expects($this->once())
      ->method('getDefinitions')
      ->willReturn($definitions);

    $this->moduleHandler->expects($this->once())
      ->method('alter')
      ->with('contextual_links_plugins', $definitions);

    $this->contextualLinkManager->getDefinition('test_plugin');
  }

}
/** * Replaces oEmbed-related media services with testing versions. */
class MediaTestOembedServiceProvider extends ServiceProviderBase {

  /** * {@inheritdoc} */
  public function alter(ContainerBuilder $container) {
    parent::alter($container);

    $container->getDefinition('media.oembed.provider_repository')
      ->setClass(ProviderRepository::class);

    $container->getDefinition('media.oembed.url_resolver')
      ->setClass(UrlResolver::class);
  }

}
// If additional plugins need to be enabled to support attribute config,       // loop through the list to enable the plugins and build a UI message that       // will convey this plugin-enabling to the user.       if (!empty($selected_plugins)) {
        $enabled_for_tags_message_content = '';
        $enabled_for_attributes_message_content = '';
        $editor_settings_to_update = $editor->getSettings();
        // Create new group for all the added toolbar items.         $editor_settings_to_update['toolbar']['items'][] = '|';
        foreach ($selected_plugins as $plugin_id => $reason_why_enabled) {
          $plugin_definition = $this->pluginManager->getDefinition($plugin_id);
          $label = $plugin_definition->label();
          $plugins_enabled[] = $label;
          if ($plugin_definition->hasToolbarItems()) {
            [$net_new] = self::computeNetNewElementsForPlugin($provided$still_needed$plugin_definition);
            $editor_settings_to_update['toolbar']['items'] = array_merge($editor_settings_to_update['toolbar']['items']array_keys($plugin_definition->getToolbarItems()));
            foreach ($reason_why_enabled as $attribute_name => $attribute_config) {
              // Plugin was selected for tag.               if (in_array($attribute_name['-attributes-none-', '-attributes-any-'], TRUE)) {
                $tags = array_reduce(array_keys($net_new->getAllowedElements())function D$carry$item) {
                  return $carry . "<$item>";
                });
                

    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = $this->getConfiguration($configs$container);
        $config = $this->processConfiguration($configuration$configs);

        $loader = new PhpFileLoader($containernew FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('profiler.php');

        if ($config['toolbar'] || $config['intercept_redirects']) {
            $loader->load('toolbar.php');
            $container->getDefinition('web_profiler.debug_toolbar')->replaceArgument(4, $config['excluded_ajax_paths']);
            $container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
            $container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
        }

        $container->getDefinition('debug.file_link_formatter')
            ->replaceArgument(3, new ServiceClosureArgument(new Reference('debug.file_link_formatter.url_format')));
    }

    public function getXsdValidationBasePath(): string|false
    {
        return __DIR__.'/../Resources/config/schema';
    }
Home | Imprint | This part of the site doesn't use cookies.