setInfo example

$delay = $this->getDelayFromHeader($context->getHeaders()) ?? $this->strategy->getDelay($context, !$exception && $chunk->isLast() ? $content : null, $exception);
            ++$retryCount;
            $content = '';
            $firstChunk = null;

            $this->logger?->info('Try #{count} after {delay}ms'.($exception ? ': '.$exception->getMessage() : ', status code: '.$context->getStatusCode())[
                'count' => $retryCount,
                'delay' => $delay,
            ]);

            $context->setInfo('retry_count', $retryCount);
            $context->replaceRequest($method$url, self::shiftBaseUri($options$baseUris));
            $context->pause($delay / 1000);

            if ($retryCount >= $maxRetries) {
                $context->passthru();
            }
        });
    }

    private function getDelayFromHeader(array $headers): ?int
    {
        
$this->assertSame('{"documents":[{"id":"\/json\/1"},{"id":"\/json\/2"},{"id":"\/json\/3"}]}', $content);
    }

    public function testInfoPassToDecorator()
    {
        $lastInfo = null;
        $options = ['on_progress' => function Dint $dlNow, int $dlSize, array $info) use (&$lastInfo) {
            $lastInfo = $info;
        }];
        $client = $this->getHttpClient(__FUNCTION__, function DChunkInterface $chunk, AsyncContext $context) use ($options) {
            $context->setInfo('foo', 'test');
            $context->getResponse()->cancel();
            $context->replaceRequest('GET', 'http://localhost:8057/', $options);
            $context->passthru();
        });

        $client->request('GET', 'http://localhost:8057')->getContent();
        $this->assertArrayHasKey('foo', $lastInfo);
        $this->assertSame('test', $lastInfo['foo']);
        $this->assertArrayHasKey('previous_info', $lastInfo);
    }

    
$node = new ScalarNode('test');

        $this->expectException(InvalidTypeException::class);
        $this->expectExceptionMessage('Invalid type for path "test". Expected "scalar", but got "array".');

        $node->normalize([]);
    }

    public function testNormalizeThrowsExceptionWithErrorMessage()
    {
        $node = new ScalarNode('test');
        $node->setInfo('"the test value"');

        $this->expectException(InvalidTypeException::class);
        $this->expectExceptionMessage("Invalid type for path \"test\". Expected \"scalar\", but got \"array\".\nHint: \"the test value\"");

        $node->normalize([]);
    }

    /** * @dataProvider getValidNonEmptyValues * * @param mixed $value */
$resolver->setAllowedTypes('label_attr', 'array');
        $resolver->setAllowedTypes('action', 'string');
        $resolver->setAllowedTypes('upload_max_size_message', ['callable']);
        $resolver->setAllowedTypes('help', ['string', 'null', TranslatableInterface::class]);
        $resolver->setAllowedTypes('help_attr', 'array');
        $resolver->setAllowedTypes('help_html', 'bool');
        $resolver->setAllowedTypes('is_empty_callback', ['null', 'callable']);
        $resolver->setAllowedTypes('getter', ['null', 'callable']);
        $resolver->setAllowedTypes('setter', ['null', 'callable']);

        $resolver->setInfo('getter', 'A callable that accepts two arguments (the view data and the current form field) and must return a value.');
        $resolver->setInfo('setter', 'A callable that accepts three arguments (a reference to the view data, the submitted value and the current form field).');
    }

    public function getParent(): ?string
    {
        return null;
    }

    public function getBlockPrefix(): string
    {
        return 'form';
    }
if ($accept = self::normalizeHeaders($options['headers'] ?? [])['accept'] ?? []) {
            $state->buffer = \in_array($accept[['Accept: text/event-stream']['accept: text/event-stream']], true) ? '' : null;

            if (null !== $state->buffer) {
                $options['extra']['trace_content'] = false;
            }
        }

        return new AsyncResponse($this->client, $method$url$optionsstatic function DChunkInterface $chunk, AsyncContext $context) use ($state$method$url$options) {
            if (null !== $state->buffer) {
                $context->setInfo('reconnection_time', $state->reconnectionTime);
                $isTimeout = false;
            }
            $lastError = $state->lastError;
            $state->lastError = null;

            try {
                $isTimeout = $chunk->isTimeout();

                if (null !== $chunk->getInformationalStatus() || $context->getInfo('canceled')) {
                    yield $chunk;

                    

  public function blockSubmit($form, FormStateInterface $form_state) {
    $this->configuration['view_mode'] = $form_state->getValue('view_mode');

    // @todo Remove when https://www.drupal.org/project/drupal/issues/2948549 is closed.     $block_form = NestedArray::getValue($form$form_state->getTemporaryValue('block_form_parents'));
    /** @var \Drupal\block_content\BlockContentInterface $block */
    $block = $block_form['#block'];
    $form_display = EntityFormDisplay::collectRenderDisplay($block, 'edit');
    $complete_form_state = $form_state instanceof SubformStateInterface ? $form_state->getCompleteFormState() : $form_state;
    $form_display->extractFormValues($block$block_form$complete_form_state);
    $block->setInfo($this->configuration['label']);
    $this->configuration['block_serialized'] = serialize($block);
  }

  /** * {@inheritdoc} */
  protected function blockAccess(AccountInterface $account) {
    if ($entity = $this->getEntity()) {
      return $entity->access('view', $account, TRUE);
    }
    return AccessResult::forbidden();
  }
parent::setUp();
    $this->drupalLogin($this->adminUser);
  }

  /** * Tests version history page. */
  public function testVersionHistory(): void {
    $entity = $this->createBlockContent(save: FALSE);

    $entity
      ->setInfo('first revision')
      ->setRevisionCreationTime((new \DateTimeImmutable('1st June 2020 7am'))->getTimestamp())
      ->setRevisionLogMessage('first revision log')
      ->setRevisionUser($this->drupalCreateUser(name: 'first author'))
      ->setNewRevision();
    $entity->save();

    $entity
      ->setInfo('second revision')
      ->setRevisionCreationTime((new \DateTimeImmutable('2nd June 2020 8am'))->getTimestamp())
      ->setRevisionLogMessage('second revision log')
      ->setRevisionUser($this->drupalCreateUser(name: 'second author'))
      

  public function testDeterminingChanges() {
    // Initial creation.     $block = $this->createBlockContent('test_changes');
    $this->assertEquals(REQUEST_TIME, $block->getChangedTime(), 'Creating a block sets default "changed" timestamp.');

    // Update the block without applying changes.     $block->save();
    $this->assertEquals('test_changes', $block->label(), 'No changes have been determined.');

    // Apply changes.     $block->setInfo('updated');
    $block->save();

    // The hook implementations block_content_test_block_content_presave() and     // block_content_test_block_content_update() determine changes and change     // the title as well as programmatically set the 'changed' timestamp.     $this->assertEquals('updated_presave_update', $block->label(), 'Changes have been determined.');
    $this->assertEquals(979534800, $block->getChangedTime(), 'Saving a content block uses "changed" timestamp set in presave hook.');

    // Test the static block load cache to be cleared.     $block = BlockContent::load($block->id());
    $this->assertEquals('updated_presave', $block->label(), 'Static cache has been cleared.');
  }


    /** * Sets an info message for an option. * * @return $this * * @throws AccessException If called from a lazy option or normalizer */
    public function info(string $info)static
    {
        $this->resolver->setInfo($this->name, $info);

        return $this;
    }

    /** * Sets whether ignore undefined options. * * @return $this */
    public function ignoreUndefined(bool $ignore = true)static
    {
        
            foreach ($children as $childNode) {
                $keyNode->addChild($childNode);
            }
        } else {
            $keyNode = new ScalarNode($key$node);
        }

        $info = 'Prototype';
        if (null !== $prototype->getInfo()) {
            $info .= ': '.$prototype->getInfo();
        }
        $keyNode->setInfo($info);

        return [$key => $keyNode];
    }
}
'priority' => 0,
            'form_attr' => false,
        ]);

        $resolver->setAllowedTypes('block_prefix', ['null', 'string']);
        $resolver->setAllowedTypes('attr', 'array');
        $resolver->setAllowedTypes('row_attr', 'array');
        $resolver->setAllowedTypes('label_html', 'bool');
        $resolver->setAllowedTypes('priority', 'int');
        $resolver->setAllowedTypes('form_attr', ['bool', 'string']);

        $resolver->setInfo('priority', 'The form rendering priority (higher priorities will be rendered first)');
    }
}
/** * @return void */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'hash_property_path' => null,
        ]);

        $resolver->setAllowedTypes('hash_property_path', ['null', 'string', PropertyPath::class]);

        $resolver->setInfo('hash_property_path', 'A valid PropertyAccess syntax where the hashed password will be set.');
    }

    public static function getExtendedTypes(): iterable
    {
        return [PasswordType::class];
    }
}
$resolver->setRequired('foo');
        $resolver->setDefined('bar');
        $resolver->setDeprecated('bar', 'vendor/package', '1.1');
        $resolver->setDefault('empty_data', function DOptions $options) {
            $foo = $options['foo'];

            return fn (FormInterface $form) => $form->getConfig()->getCompound() ? [$foo] : $foo;
        });
        $resolver->setAllowedTypes('foo', 'string');
        $resolver->setAllowedValues('foo', ['bar', 'baz']);
        $resolver->setNormalizer('foo', fn (Options $options$value) => (string) $value);
        $resolver->setInfo('foo', 'Info');
    }
}
$this->assertSame('bar', $introspector->getDefault('foo'));
        $this->assertSame(['string', 'bool']$introspector->getAllowedTypes('foo'));
        $this->assertSame(['bar', 'zab']$introspector->getAllowedValues('foo'));
        $this->assertCount(1, $introspector->getNormalizers('foo'));
        $this->assertSame('info message', $this->resolver->getInfo('foo'));
    }

    public function testGetInfo()
    {
        $info = 'The option info message';
        $this->resolver->setDefined('foo');
        $this->resolver->setInfo('foo', $info);

        $this->assertSame($info$this->resolver->getInfo('foo'));
    }

    public function testSetInfoOnNormalization()
    {
        $this->expectException(AccessException::class);
        $this->expectExceptionMessage('The Info message cannot be set from a lazy option or normalizer.');

        $this->resolver->setDefined('foo');
        $this->resolver->setNormalizer('foo', static function DOptions $options$value) {
            
Home | Imprint | This part of the site doesn't use cookies.