Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NamedParameterMap.php

class NamedParameterMap

`NamedParameterMap` represents a mapping of values to a set of named keys that may optionally be typed

@extends AbstractMap<string, mixed>

Hierarchy

  • class \Ramsey\Collection\AbstractArray implements \Ramsey\Collection\ArrayInterface
    • class \Ramsey\Collection\Map\AbstractMap extends \Ramsey\Collection\AbstractArray implements \Ramsey\Collection\Map\MapInterface
      • class \Ramsey\Collection\Map\NamedParameterMap extends \Ramsey\Collection\Map\AbstractMap uses \Ramsey\Collection\Tool\TypeTrait, \Ramsey\Collection\Tool\ValueToStringTrait

Expanded class hierarchy of NamedParameterMap

File

vendor/ramsey/collection/src/Map/NamedParameterMap.php, line 31

Namespace

Ramsey\Collection\Map
View source
class NamedParameterMap extends AbstractMap {
    use TypeTrait;
    use ValueToStringTrait;
    
    /**
     * Named parameters defined for this map.
     *
     * @var array<string, string>
     */
    private readonly array $namedParameters;
    
    /**
     * Constructs a new `NamedParameterMap`.
     *
     * @param array<array-key, string> $namedParameters The named parameters defined for this map.
     * @param array<string, mixed> $data An initial set of data to set on this map.
     */
    public function __construct(array $namedParameters, array $data = []) {
        $this->namedParameters = $this->filterNamedParameters($namedParameters);
        parent::__construct($data);
    }
    
    /**
     * Returns named parameters set for this `NamedParameterMap`.
     *
     * @return array<string, string>
     */
    public function getNamedParameters() : array {
        return $this->namedParameters;
    }
    public function offsetSet(mixed $offset, mixed $value) : void {
        if (!array_key_exists($offset, $this->namedParameters)) {
            throw new InvalidArgumentException('Attempting to set value for unconfigured parameter \'' . $this->toolValueToString($offset) . '\'');
        }
        if ($this->checkType($this->namedParameters[$offset], $value) === false) {
            throw new InvalidArgumentException('Value for \'' . $offset . '\' must be of type ' . $this->namedParameters[$offset] . '; value is ' . $this->toolValueToString($value));
        }
        $this->data[$offset] = $value;
    }
    
    /**
     * Given an array of named parameters, constructs a proper mapping of
     * named parameters to types.
     *
     * @param array<array-key, string> $namedParameters The named parameters to filter.
     *
     * @return array<string, string>
     */
    protected function filterNamedParameters(array $namedParameters) : array {
        $names = [];
        $types = [];
        foreach ($namedParameters as $key => $value) {
            if (is_int($key)) {
                $names[] = $value;
                $types[] = 'mixed';
            }
            else {
                $names[] = $key;
                $types[] = $value;
            }
        }
        return array_combine($names, $types) ?: [];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractArray::$data protected property The items of this array.
AbstractArray::clear public function Removes all items from this array. Overrides ArrayInterface::clear
AbstractArray::count public function Returns the number of items in this array.
AbstractArray::isEmpty public function Returns `true` if this array is empty. Overrides ArrayInterface::isEmpty
AbstractArray::offsetExists public function Returns `true` if the given offset exists in this array.
AbstractArray::offsetGet public function Returns the value at the specified offset.
AbstractArray::offsetUnset public function Removes the given offset and its value from the array.
AbstractArray::__unserialize public function Adds unserialized data to the object.
AbstractMap::containsKey public function Returns `true` if this map contains a mapping for the specified key. Overrides MapInterface::containsKey
AbstractMap::containsValue public function Returns `true` if this map maps one or more keys to the specified value. Overrides MapInterface::containsValue
AbstractMap::get public function Overrides MapInterface::get
AbstractMap::getIterator public function Overrides AbstractArray::getIterator
AbstractMap::keys public function @inheritDoc Overrides MapInterface::keys
AbstractMap::put public function Overrides MapInterface::put
AbstractMap::putIfAbsent public function Overrides MapInterface::putIfAbsent
AbstractMap::remove public function Overrides MapInterface::remove
AbstractMap::removeIf public function Removes the entry for the specified key only if it is currently mapped to
the specified value.
Overrides MapInterface::removeIf
AbstractMap::replace public function Overrides MapInterface::replace
AbstractMap::replaceIf public function Replaces the entry for the specified key only if currently mapped to the
specified value.
Overrides MapInterface::replaceIf
AbstractMap::toArray public function Overrides AbstractArray::toArray
AbstractMap::__serialize public function Overrides AbstractArray::__serialize
NamedParameterMap::$namedParameters private property Named parameters defined for this map.
NamedParameterMap::filterNamedParameters protected function Given an array of named parameters, constructs a proper mapping of
named parameters to types.
NamedParameterMap::getNamedParameters public function Returns named parameters set for this `NamedParameterMap`.
NamedParameterMap::offsetSet public function @inheritDoc
@psalm-suppress MoreSpecificImplementedParamType,DocblockTypeContradiction
Overrides AbstractMap::offsetSet
NamedParameterMap::__construct public function Constructs a new `NamedParameterMap`. Overrides AbstractMap::__construct
TypeTrait::checkType protected function Returns `true` if value is of the specified type.
ValueToStringTrait::toolValueToString protected function Returns a string representation of the value.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal