assertAllStrings example

if (!$allow_invalid && !$cache->valid) {
      return FALSE;
    }

    return $cache;
  }

  /** * {@inheritdoc} */
  public function set($cid$data$expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = []) {
    assert(Inspector::assertAllStrings($tags), 'Cache tags must be strings.');
    $tags = array_unique($tags);
    $cache = new \stdClass();
    $cache->cid = $cid;
    $cache->created = round(microtime(TRUE), 3);
    $cache->expire = $expire;
    $cache->tags = implode(' ', $tags);
    $cache->checksum = $this->checksumProvider->getCurrentChecksum($tags);
    // APCu serializes/unserializes any structure itself.     $cache->serialized = 0;
    $cache->data = $data;

    

  private static function selectCandidate(array $candidates, HTMLRestrictions $still_needed, array $already_supported_tags): array {
    assert(Inspector::assertAllStrings($already_supported_tags));

    // Make a selection in the candidates: minimize the surplus count, to     // avoid generating surplus additions whenever possible.     $selected_plugins = [];
    foreach ($still_needed->getAllowedElements() as $tag_name => $attributes_config) {
      if (!isset($candidates[$tag_name])) {
        // Sadly no plugin found for this tag.         continue;
      }

      // Non-specific attribute restrictions for tag.

  public static function mergeTags(array ...$cache_tags) {
    $cache_tags = array_unique(array_merge(...$cache_tags));
    assert(Inspector::assertAllStrings($cache_tags), 'Cache tags must be valid strings');
    return $cache_tags;
  }

  /** * Merges max-age values (expressed in seconds), finds the lowest max-age. * * Ensures infinite max-age (Cache::PERMANENT) is taken into account. * * @param int ... * Max age values to merge. * * @return int * The minimum max-age value. */

  protected function getFields(array $field_names, EntityTypeInterface $entity_type$bundle) {
    assert(Inspector::assertAllStrings($field_names));
    assert($entity_type instanceof ContentEntityTypeInterface || $entity_type instanceof ConfigEntityTypeInterface);
    assert(is_string($bundle) && !empty($bundle), 'A bundle ID is required. Bundleless entity types should pass the entity type ID again.');

    // JSON:API resource identifier objects are sufficient to identify     // entities. By exposing all fields as attributes, we expose unwanted,     // confusing or duplicate information:     // - exposing an entity's ID (which is not a UUID) is bad, but it's     // necessary for certain Drupal-coupled clients, so we alias it by     // prefixing it with `drupal_internal__`.     // - exposing an entity's UUID as an attribute is useless (it's already part     // of the mandatory "id" attribute in JSON:API), so we disable it in most

  public function __construct(object $connection, array $connection_options) {
    assert(count($this->identifierQuotes) === 2 && Inspector::assertAllStrings($this->identifierQuotes), '\Drupal\Core\Database\Connection::$identifierQuotes must contain 2 string values');

    // Manage the table prefix.     $connection_options['prefix'] = $connection_options['prefix'] ?? '';
    $this->setPrefix($connection_options['prefix']);

    // Work out the database driver namespace if none is provided. This normally     // written to setting.php by installer or set by     // \Drupal\Core\Database\Database::parseConnectionInfo().     if (empty($connection_options['namespace'])) {
      $connection_options['namespace'] = (new \ReflectionObject($this))->getNamespaceName();
    }

    

  protected function doSetMultiple(array $items) {
    $values = [];

    foreach ($items as $cid => $item) {
      $item += [
        'expire' => CacheBackendInterface::CACHE_PERMANENT,
        'tags' => [],
      ];

      assert(Inspector::assertAllStrings($item['tags']), 'Cache Tags must be strings.');
      $item['tags'] = array_unique($item['tags']);
      // Sort the cache tags so that they are stored consistently in the DB.       sort($item['tags']);

      $fields = [
        'cid' => $this->normalizeCid($cid),
        'expire' => $item['expire'],
        'created' => round(microtime(TRUE), 3),
        'tags' => implode(' ', $item['tags']),
        'checksum' => $this->checksumProvider->getCurrentChecksum($item['tags']),
      ];

      
if (!$allow_invalid && !$cache->valid) {
      return FALSE;
    }

    return $cache;
  }

  /** * {@inheritdoc} */
  public function set($cid$data$expire = MemoryCacheInterface::CACHE_PERMANENT, array $tags = []) {
    assert(Inspector::assertAllStrings($tags), 'Cache tags must be strings.');
    $tags = array_unique($tags);

    $this->cache[$cid] = (object) [
      'cid' => $cid,
      'data' => $data,
      'created' => $this->getRequestTime(),
      'expire' => $expire,
      'tags' => $tags,
    ];
  }

}
if (!$allow_invalid && !$prepared->valid) {
      return FALSE;
    }

    return $prepared;
  }

  /** * {@inheritdoc} */
  public function set($cid$data$expire = Cache::PERMANENT, array $tags = []) {
    assert(Inspector::assertAllStrings($tags), 'Cache Tags must be strings.');
    $tags = array_unique($tags);
    // Sort the cache tags so that they are stored consistently in the database.     sort($tags);
    $this->cache[$cid] = (object) [
      'cid' => $cid,
      'data' => serialize($data),
      'created' => $this->getRequestTime(),
      'expire' => $expire,
      'tags' => $tags,
    ];
  }

  
/** * Holds an array of cache tags invalidators. * * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface[] */
  protected $invalidators = [];

  /** * {@inheritdoc} */
  public function invalidateTags(array $tags) {
    assert(Inspector::assertAllStrings($tags), 'Cache tags must be strings.');

    // Notify all added cache tags invalidators.     foreach ($this->invalidators as $invalidator) {
      $invalidator->invalidateTags($tags);
    }

    // Additionally, notify each cache bin if it implements the service.     foreach ($this->getInvalidatorCacheBins() as $bin) {
      $bin->invalidateTags($tags);
    }
  }

  
if (!$allow_invalid && !$cache->valid) {
      return FALSE;
    }

    return $cache;
  }

  /** * {@inheritdoc} */
  public function set($cid$data$expire = Cache::PERMANENT, array $tags = []) {
    assert(Inspector::assertAllStrings($tags), 'Cache Tags must be strings.');

    $item = (object) [
      'cid' => $cid,
      'data' => $data,
      'created' => round(microtime(TRUE), 3),
      'expire' => $expire,
      'tags' => array_unique($tags),
      'checksum' => $this->checksumProvider->getCurrentChecksum($tags),
    ];
    $this->writeItem($this->normalizeCid($cid)$item);
  }

  

  private static function validateAllowedRestrictionsPhase1(array $elements): void {
    if (!is_array($elements) || !Inspector::assertAllStrings(array_keys($elements))) {
      throw new \InvalidArgumentException('An array of key-value pairs must be provided, with HTML tag names as keys.');
    }
    foreach (array_keys($elements) as $html_tag_name) {
      if (trim($html_tag_name) !== $html_tag_name) {
        throw new \InvalidArgumentException(sprintf('The "%s" HTML tag contains trailing or leading whitespace.', $html_tag_name));
      }
      if ($html_tag_name[0] === '<' || $html_tag_name[-1] === '>') {
        throw new \InvalidArgumentException(sprintf('"%s" is not a HTML tag name, it is an actual HTML tag. Omit the angular brackets.', $html_tag_name));
      }
      if (self::isWildcardTag($html_tag_name)) {
        continue;
      }

  protected function validateAndBuildMaps(): void {
    if ($this->cke4ButtonsMap !== NULL) {
      return;
    }

    foreach ($this->getDefinitions() as $upgrade_plugin_id => $definition) {
      // Only one CKEditor4To5Upgrade plugin can define the upgrade path for a       // CKEditor 4 button.       if (isset($definition['cke4_buttons'])) {
        assert(Inspector::assertAllStrings($definition['cke4_buttons']));
        foreach ($definition['cke4_buttons'] as $cke4_button_id) {
          if (isset($this->cke4ButtonsMap[$cke4_button_id])) {
            throw new \OutOfBoundsException(sprintf('The "%s" CKEditor 4 button is already being upgraded by the "%s" CKEditor4To5Upgrade plugin, the "%s" plugin is as well. This conflict needs to be resolved.', $cke4_button_id$this->cke4ButtonsMap[$cke4_button_id]$upgrade_plugin_id));
          }
          $this->cke4ButtonsMap[$cke4_button_id] = $upgrade_plugin_id;
        }
      }

      // Only one CKEditor4To5Upgrade plugin can define the upgrade path for a       // CKEditor 4 plugin's settings.       if (isset($definition['cke4_plugin_settings'])) {
        

  }

  /** * Asserts structure of $patchProtectedFieldNames. */
  protected function assertPatchProtectedFieldNamesStructure() {
    $is_null_or_string = function D$value) {
      return is_null($value) || is_string($value);
    };
    $this->assertTrue(
      Inspector::assertAllStrings(array_keys(static::$patchProtectedFieldNames)),
      'In Drupal 8.6, the structure of $patchProtectedFieldNames changed. It used to be an array with field names as values. Now those values are the keys, and their values should be either NULL or a string: a string containing the reason for why the field cannot be PATCHed, or NULL otherwise.'
    );
    $this->assertTrue(
      Inspector::assertAll($is_null_or_stringstatic::$patchProtectedFieldNames),
      'In Drupal 8.6, the structure of $patchProtectedFieldNames changed. It used to be an array with field names as values. Now those values are the keys, and their values should be either NULL or a string: a string containing the reason for why the field cannot be PATCHed, or NULL otherwise.'
    );
  }

  /** * Gets an entity resource's GET/PATCH/DELETE URL. * * @return \Drupal\Core\Url * The URL to GET/PATCH/DELETE. */

  public function setCacheBackend(CacheBackendInterface $cache_backend$cache_key, array $cache_tags = []) {
    assert(Inspector::assertAllStrings($cache_tags), 'Cache Tags must be strings.');
    $this->cacheBackend = $cache_backend;
    $this->cacheKey = $cache_key;
    $this->cacheTags = $cache_tags;
  }

  /** * Sets the alter hook name. * * @param string $alter_hook * Name of the alter hook; for example, to invoke * hook_mymodule_data_alter() pass in "mymodule_data". */
$this->assertFalse(Inspector::assertTraversable(new \stdClass()));
    $this->assertFalse(Inspector::assertTraversable('foo'));
  }

  /** * Tests asserting all members are strings. * * @covers ::assertAllStrings * @dataProvider providerTestAssertAllStrings */
  public function testAssertAllStrings($input$expected) {
    $this->assertSame($expected, Inspector::assertAllStrings($input));
  }

  public function providerTestAssertAllStrings() {
    $data = [
      'empty-array' => [[], TRUE],
      'array-with-strings' => [['foo', 'bar'], TRUE],
      'string' => ['foo', FALSE],
      'array-with-strings-with-colon' => [['foo', 'bar', 'llama:2001988', 'baz', 'llama:14031991'], TRUE],

      'with-FALSE' => [[FALSE], FALSE],
      'with-TRUE' => [[TRUE], FALSE],
      
Home | Imprint | This part of the site doesn't use cookies.