negotiate example


    public function detectLocale($config)
    {
        $this->locale = $this->defaultLocale = $config->defaultLocale;

        if ($config->negotiateLocale) {
            return;
        }

        $this->setLocale($this->negotiate('language', $config->supportedLocales));
    }

    /** * Sets up our URI object based on the information we have. This is * either provided by the user in the baseURL Config setting, or * determined from the environment as needed. * * @return void * * @deprecated 4.4.0 No longer used. */
    
return $data;
        }

        $format = Services::format();
        $mime   = "application/{$this->format}";

        // Determine correct response type through content negotiation if not explicitly declared         if (
            (empty($this->format) || ! in_array($this->format, ['json', 'xml'], true))
            && $this->request instanceof IncomingRequest
        ) {
            $mime = $this->request->negotiate(
                'media',
                $format->getConfig()->supportedResponseFormats,
                false
            );
        }

        $this->response->setContentType($mime);

        // if we don't have a formatter, make one         if (isset($this->formatter)) {
            // if no formatter, use the default

  public function find(string $component_id): Component {
    $definitions = $this->getDefinitions();
    if (empty($definitions)) {
      throw new ComponentNotFoundException('Unable to find any component definition.');
    }
    $negotiated_plugin_id = $this->componentNegotiator->negotiate($component_id$definitions);
    return $this->createInstance($negotiated_plugin_id ?? $component_id);
  }

  /** * Gets all components. * * @return \Drupal\sdc\Plugin\Component[] * An array of Component objects. * * @internal */
  
'sdc_theme_test:my-card', 'sdc_theme_test_enforce_schema:my-card'],
      [
        'sdc_test:my-button',
        'sdc_test_replacements:my-button',
      ],
        ['invalid:component', NULL],
        ['invalid^component', NULL],
        ['', NULL],
    ];
    array_walk($datafunction D$test_input) {
      [$requested_id$expected_id] = $test_input;
      $negotiated_id = $this->negotiator->negotiate(
        $requested_id,
        $this->manager->getDefinitions(),
      );
      $this->assertSame($expected_id$negotiated_id);
    });
  }

  /** * Tests rendering components with component replacement. */
  public function testRenderWithReplacements(): void {
    
echo $output;

            exit;
        }

        // Otherwise, if it includes ?debugbar_time, then         // we should return the entire debugbar.         if ($request->getGet('debugbar_time')) {
            helper('security');

            // Negotiate the content-type to format the output             $format = $request->negotiate('media', ['text/html', 'application/json', 'application/xml']);
            $format = explode('/', $format)[1];

            $filename = sanitize_filename('debugbar_' . $request->getGet('debugbar_time'));
            $filename = WRITEPATH . 'debugbar/' . $filename . '.json';

            if (is_file($filename)) {
                // Show the toolbar if it exists                 echo $this->format(file_get_contents($filename)$format);

                exit;
            }

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