setContext example

$request->server->all(),
            ['REQUEST_URI' => $request->attributes->get(RequestTransformer::SALES_CHANNEL_RESOLVED_URI)]
        );

        $localClone = $request->duplicate(null, null, null, null, null, $server);

        return $this->decorated->matchRequest($localClone);
    }

    public function setContext(RequestContext $context): void
    {
        $this->decorated->setContext($context);
    }

    public function getContext(): RequestContext
    {
        return $this->decorated->getContext();
    }

    public function getRouteCollection(): RouteCollection
    {
        return $this->decorated->getRouteCollection();
    }

    

  public function __construct(CurrentPathStack $current_path) {
    $this->currentPath = $current_path;
  }

  public function finalMatch(RouteCollection $collection, Request $request) {
    $this->routes = $collection;
    $context = new RequestContext();
    $context->fromRequest($request);
    $this->setContext($context);

    return $this->match($this->currentPath->getPath($request));
  }

  /** * {@inheritdoc} */
  protected function getAttributes(Route $route$name, array $attributes): array {
    if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) {
      $name = $route->getRouteKey();
    }
    
$routes->setHTTPVerb($method);

        // Make sure any other classes that might call the request         // instance get the right one.         Services::injectMock('request', $request);

        // Make sure filters are reset between tests         Services::injectMock('filters', Services::filters(null, false));

        $response = $this->app
            ->setContext('web')
            ->setRequest($request)
            ->run($routes, true);

        $output = \ob_get_contents();
        if (empty($response->getBody()) && ! empty($output)) {
            $response->setBody($output);
        }

        // Reset directory if it has been set         Services::router()->setDirectory(null);

        
// Make sure any other classes that might call the request         // instance get the right one.         Services::injectMock('request', $request);

        // Make sure filters are reset between tests         Services::injectMock('filters', Services::filters(null, false));

        // Make sure validation is reset between tests         Services::injectMock('validation', Services::validation(null, false));

        $response = $this->app
            ->setContext('web')
            ->setRequest($request)
            ->run($routes, true);

        // Reset directory if it has been set         Services::router()->setDirectory(null);

        return new TestResponse($response);
    }

    /** * Performs a GET request. * * @param string $path URI path relative to baseURL. May include query. * * @return TestResponse * * @throws RedirectException * @throws Exception */
$shop = $modelManager->getRepository(Shop::class)->getActiveById($notify['language']);

            // Continue if shop is inactive or deleted             if ($shop === null) {
                continue;
            }

            $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

            $shopContext = Context::createFromShop($shop$this->get(Shopware_Components_Config::class));
            $this->get(RouterInterface::class)->setContext($shopContext);
            $sContext = $this->get(ContextServiceInterface::class)->createShopContext($notify['language']);

            $productInformation = $this->get(ListProductServiceInterface::class)->get($notify['ordernumber']$sContext);

            if (empty($productInformation)) {
                continue;
            }

            $productInformation = $this->get('legacy_struct_converter')->convertListProductStruct($productInformation);

            $link = Shopware()->Front()->ensureRouter()->assemble([
                

    private function generateAsynchronous(RepositoryIterator $mediaIterator, Context $context): void
    {
        $batchCount = 0;
        $this->io->comment('Generating batch jobs...');
        while (($result = $mediaIterator->fetch()) !== null) {
            $msg = new UpdateThumbnailsMessage();
            $msg->setIsStrict($this->isStrict);
            $msg->setMediaIds($result->getEntities()->getIds());

            if (Feature::isActive('v6.6.0.0')) {
                $msg->setContext($context);
            } else {
                $msg->withContext($context);
            }

            $this->messageBus->dispatch($msg);
            ++$batchCount;
        }
        $this->io->success(sprintf('Generated %d Batch jobs!', $batchCount));
    }
}

  protected function rekey($from_index = 0) {
    // Re-key the list to maintain consecutive indexes.     $this->list = array_values($this->list);
    // Each item holds its own index as a "name", it needs to be updated     // according to the new list indexes.     for ($i = $from_index$i < count($this->list)$i++) {
      $this->list[$i]->setContext($i$this);
    }
  }

  /** * {@inheritdoc} */
  public function first() {
    return $this->get(0);
  }

  /** * {@inheritdoc} */
/** * @covers ::applyContextMapping */
  public function testApplyContextMappingAlreadyApplied() {
    $entity = EntityTest::create([]);
    $context_definition = EntityContextDefinition::fromEntity($entity);
    $context = EntityContext::fromEntity($entity);

    $definition = ['context_definitions' => ['a_context_id' => $context_definition]];
    $plugin = new TestContextAwarePlugin([], 'test_plugin_id', $definition);
    $plugin->setContext('a_context_id', $context);
    (new ContextHandler())->applyContextMapping($plugin[]);

    $result = $plugin->getContext('a_context_id');

    $this->assertInstanceOf(EntityContext::class$result);
    $this->assertSame($context$result);
  }

}

/** * Provides a test implementation of a context-aware plugin. */
'bundle' => 'entity_test',
      'mode' => 'default',
      'status' => TRUE,
    ]);
    if ($is_enabled) {
      $display->enableLayoutBuilder();
    }
    $display
      ->setThirdPartySetting('layout_builder', 'sections', $section_data)
      ->save();

    $this->plugin->setContext('display', EntityContext::fromEntity($display));
    $result = $this->plugin->access($operation);
    $this->assertSame($expected$result);
  }

  /** * Provides test data for ::testAccess(). */
  public function providerTestAccess() {
    $section_data = [
      new Section(
        'layout_onecol',
        [],
// Ensure to call every other function to the router.     return call_user_func_array([$this->router, $name]$arguments);
  }

  /** * {@inheritdoc} * * phpcs:ignore Drupal.Commenting.FunctionComment.VoidReturn * @return void */
  public function setContext(SymfonyRequestContext $context) {
    $this->router->setContext($context);
  }

  /** * {@inheritdoc} */
  public function getContext(): SymfonyRequestContext {
    return $this->router->getContext();
  }

  /** * {@inheritdoc} * * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * Thrown when access checking failed. */
/** * @after */
    public function resetRequestContext(): void
    {
        $router = $this->getContainer()
            ->get('router');

        $context = $router->getContext();

        $router->setContext($context->fromRequest(Request::create((string) EnvironmentHelper::getVariable('APP_URL'))));
    }

    abstract protected static function getContainer(): ContainerInterface;
}
\Drupal::setContainer($container);

    $this->plugin->getPluginDefinition()
      ->addContextDefinition('display', EntityContextDefinition::fromEntityTypeId('entity_view_display'))
      ->addContextDefinition('view_mode', new ContextDefinition('string'));

    // Set an initial value on the section list.     $section_list = $this->prophesize(LayoutEntityDisplayInterface::class);

    $context = $this->prophesize(ContextInterface::class);
    $context->getContextValue()->willReturn($section_list->reveal());
    $this->plugin->setContext('display', $context->reveal());

    $section_list->getThirdPartySetting('the_module', 'the_key', NULL)->willReturn('value 1');

    // The plugin returns the initial value.     $this->assertSame('value 1', $this->plugin->getThirdPartySetting('the_module', 'the_key'));

    // When the section list is updated, also update the result returned.     $section_list->setThirdPartySetting('the_module', 'the_key', 'value 2')->shouldBeCalled()->will(function Darray $args) use ($section_list) {
      $section_list->getThirdPartySetting('the_module', 'the_key', NULL)->willReturn($args[2]);
    });

    
/** * {@inheritdoc} */
  public function getContextValue($name) {
    return $this->getContext($name)->getContextValue();
  }

  /** * {@inheritdoc} */
  public function setContextValue($name$value) {
    $this->setContext($name, Context::createFromContext($this->getContext($name)$value));
    return $this;
  }

  /** * {@inheritdoc} */
  public function getContextMapping() {
    $configuration = $this instanceof ConfigurableInterface ? $this->getConfiguration() : $this->configuration;
    return $configuration['context_mapping'] ?? [];
  }

  
foreach ($this->fields as $name => $fields_by_langcode) {
      $this->fields[$name] = [];
      // Untranslatable fields may have multiple references for the same field       // object keyed by language. To avoid creating different field objects       // we retain just the original value, as references will be recreated       // later as needed.       if (!$definitions[$name]->isTranslatable() && count($fields_by_langcode) > 1) {
        $fields_by_langcode = array_intersect_key($fields_by_langcode[LanguageInterface::LANGCODE_DEFAULT => TRUE]);
      }
      foreach ($fields_by_langcode as $langcode => $items) {
        $this->fields[$name][$langcode] = clone $items;
        $this->fields[$name][$langcode]->setContext($name$this->getTranslation($langcode)->getTypedData());
      }
    }
  }

  /** * {@inheritdoc} */
  public function label() {
    if ($this->getEntityType()->getKey('label')) {
      return $this->getEntityKey('label');
    }
  }
return $this->isLayoutBuilderEnabled();
  }

  /** * {@inheritdoc} */
  public function setContext($name, ComponentContextInterface $context) {
    // Set the view mode context based on the display context.     if ($name === 'display') {
      $this->setContextValue('view_mode', $context->getContextValue()->getMode());
    }
    parent::setContext($name$context);
  }

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