isAssoc example

/** * Sets values for the autocompleter. * * @return $this * * @throws LogicException */
    public function setAutocompleterValues(?iterable $values)static
    {
        if (\is_array($values)) {
            $values = $this->isAssoc($values) ? array_merge(array_keys($values)array_values($values)) : array_values($values);

            $callback = static fn () => $values;
        } elseif ($values instanceof \Traversable) {
            $callback = static function D) use ($values) {
                static $valueCache;

                return $valueCache ??= iterator_to_array($values, false);
            };
        } else {
            $callback = null;
        }

        
$is_unpack = false;

            // Handle argument unpacking as a last resort             foreach ($call['parameters'] as $i => &$param) {
                if (0 === \strpos($param['name'], '...')) {
                    $is_unpack = true;

                    // If we're on the last param                     if ($i < $argc && $i === \count($call['parameters']) - 1) {
                        unset($call['parameters'][$i]);

                        if (Utils::isAssoc($args)) {
                            // Associated unpacked arrays can be accessed by key                             $keys = \array_slice(\array_keys($args)$i);

                            foreach ($keys as $key) {
                                $call['parameters'][] = [
                                    'name' => \substr($param['name'], 3).'['.\var_export($key, true).']',
                                    'path' => \substr($param['path'], 3).'['.\var_export($key, true).']',
                                    'expression' => false,
                                ];
                            }
                        } else {
                            
return;
        }

        if ($o->depth >= $depth - 1) {
            return;
        }

        if (\count($var) < self::$trigger) {
            return;
        }

        if (self::$numeric_only && Utils::isAssoc($var)) {
            return;
        }

        $base = clone $o;
        $base->depth = $depth - 1;
        $obj = $this->parser->parse($var$base);

        if ('array' != $obj->type) {
            return; // @codeCoverageIgnore         }

        
$this->errorMessage = $errorMessage;
        $this->setValidator($this->getDefaultValidator());

        return $this;
    }

    private function getDefaultValidator(): callable
    {
        $choices = $this->choices;
        $errorMessage = $this->errorMessage;
        $multiselect = $this->multiselect;
        $isAssoc = $this->isAssoc($choices);

        return function D$selected) use ($choices$errorMessage$multiselect$isAssoc) {
            if ($multiselect) {
                // Check for a separated comma values                 if (!preg_match('/^[^,]+(?:,[^,]+)*$/', (string) $selected$matches)) {
                    throw new InvalidArgumentException(sprintf($errorMessage$selected));
                }

                $selectedChoices = explode(',', (string) $selected);
            } else {
                $selectedChoices = [$selected];
            }
$this->errorMessage = $errorMessage;
        $this->setValidator($this->getDefaultValidator());

        return $this;
    }

    private function getDefaultValidator(): callable
    {
        $choices = $this->choices;
        $errorMessage = $this->errorMessage;
        $multiselect = $this->multiselect;
        $isAssoc = $this->isAssoc($choices);

        return function D$selected) use ($choices$errorMessage$multiselect$isAssoc) {
            if ($multiselect) {
                // Check for a separated comma values                 if (!preg_match('/^[^,]+(?:,[^,]+)*$/', (string) $selected$matches)) {
                    throw new InvalidArgumentException(sprintf($errorMessage$selected));
                }

                $selectedChoices = explode(',', (string) $selected);
            } else {
                $selectedChoices = [$selected];
            }
/** * Sets values for the autocompleter. * * @return $this * * @throws LogicException */
    public function setAutocompleterValues(?iterable $values)static
    {
        if (\is_array($values)) {
            $values = $this->isAssoc($values) ? array_merge(array_keys($values)array_values($values)) : array_values($values);

            $callback = static fn () => $values;
        } elseif ($values instanceof \Traversable) {
            $callback = static function D) use ($values) {
                static $valueCache;

                return $valueCache ??= iterator_to_array($values, false);
            };
        } else {
            $callback = null;
        }

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