array_walk example


  protected function getKeys(Config $config$key$get_method, ConfigEntityTypeInterface $entity_type) {
    if (substr($key, -1) == '*') {
      throw new InvalidLookupKeyException(strtr('%entity_type lookup key %key ends with a wildcard this can not be used as a lookup', ['%entity_type' => $entity_type->id(), '%key' => $key]));
    }
    $parts = explode('.*', $key);
    // Remove leading dots.     array_walk($partsfunction D&$value) {
      $value = trim($value, '.');
    });

    $values = (array) $this->getValues($config$parts[0]$get_method$parts);

    $output = [];
    // Flatten the array to a single dimension and add the key to all the     // values.     array_walk_recursive($valuesfunction D$current) use (&$output$key) {
      if (is_scalar($current)) {
        $current = $key . ':' . $current;
      }

  public function setData(array $data) {
    array_walk($datafunction D&$config$name) {
      $config = new ConfigEntityDependency($name$config);
    });
    $this->data = $data;
    $this->graph = NULL;
    return $this;
  }

  /** * Updates one of the lightweight ConfigEntityDependency objects. * * @param $name * The configuration dependency name. * @param array $dependencies * The configuration dependencies. The array is structured like this: * @code * array( * 'config' => array( * // An array of configuration entity object names. * ), * 'content' => array( * // An array of content entity configuration dependency names. The default * // format is "ENTITY_TYPE_ID:BUNDLE:UUID". * ), * 'module' => array( * // An array of module names. * ), * 'theme' => array( * // An array of theme names. * ), * ); * @endcode * * @return $this */
$temporaryPath = $fileSystem->tempnam(sys_get_temp_dir(), 'symfonyManagerRegistryTest');
        $fileSystem->remove($temporaryPath);
        $fileSystem->mkdir($temporaryPath);

        $dumper = new PhpDumper($container);

        $containerFiles = $dumper->dump([
            'class' => 'LazyServiceDoctrineBridgeContainerAsFiles',
            'as_files' => true,
        ]);

        array_walk(
            $containerFiles,
            static function Dstring $containerSources, string $fileName) use ($temporaryPath): void {
                (new Filesystem())->dumpFile($temporaryPath.'/'.$fileName$containerSources);
            }
        );

        require $temporaryPath.'/LazyServiceDoctrineBridgeContainerAsFiles.php';
    }
}
        // For reference: It is NOT possible to return names indexed by         // numeric code here, because some numeric codes map to multiple         // 3-letter codes (e.g. 32 => "ARA", "ARP", "ARS")         // ====================================================================
        $names = self::readEntry(['Names']$displayLocale);

        if ($names instanceof \Traversable) {
            $names = iterator_to_array($names);
        }

        array_walk($namesfunction D&$value) {
            $value = $value[self::INDEX_NAME];
        });

        return self::asort($names$displayLocale);
    }

    /** * @throws MissingResourceException if the currency code does not exist */
    public static function getSymbol(string $currency, string $displayLocale = null): string
    {
        
if ($key->type === 'UNIQUE') {
                $keyFields = array_merge($keyFields$key->fields);
            }
        }

        // Get the unique field names         $escKeyFields = array_map(fn (string $field): string => $this->db->protectIdentifiers($field)array_values(array_unique($keyFields)));

        // Get the binds         $binds = $this->binds;
        array_walk($bindsstatic function D&$item) {
            $item = $item[0];
        });

        // Get the common field and values from the keys data and index fields         $common = array_intersect($keys$escKeyFields);
        $bingo  = [];

        foreach ($common as $v) {
            $k = array_search($v$keys, true);

            $bingo[$keys[$k]] = $binds[trim($values[$k], ':')];
        }
    $text = str_replace("\r", '', $text);
    // See if soft-wrapping is allowed.     $clean_indent = static::htmlToTextClean($indent);
    $soft = !str_contains($clean_indent, ' ');
    // Check if the string has line breaks.     if (str_contains($text, "\n")) {
      // Remove trailing spaces to make existing breaks hard, but leave       // signature marker untouched (RFC 3676, Section 4.3).       $text = preg_replace('/(?(?<!^--) +\n| +\n)/m', "\n", $text);
      // Wrap each line at the needed width.       $lines = explode("\n", $text);
      array_walk($lines, '\Drupal\Core\Mail\MailFormatHelper::wrapMailLine', ['soft' => $soft, 'length' => strlen($indent)]);
      $text = implode("\n", $lines);
    }
    else {
      // Wrap this line.       static::wrapMailLine($text, 0, ['soft' => $soft, 'length' => strlen($indent)]);
    }
    // Empty lines with nothing but spaces.     $text = preg_replace('/^ +\n/m', "\n", $text);
    // Space-stuff special lines.     $text = preg_replace('/^(>| |From)/m', ' $1', $text);
    // Apply indentation. We only include non-'>' indentation on the first line.
if (1 !== \count($item)) {
                    throw new InvalidArgumentException(sprintf('Form field values with integer keys can only have one array element, the key being the field name and the value being the field value, %d provided.', \count($item)));
                }

                $key = key($item);
                $item = $item[$key];
            }

            $fieldName = null !== $root ? sprintf('%s[%s]', $root$key) : $key;

            if (\is_array($item)) {
                array_walk($item$prepare$fieldName);

                return;
            }

            $values[] = $this->preparePart($fieldName$item);
        };

        array_walk($fields$prepare);

        return $values;
    }

    
// Get all possible status codes defined by symfony.     $options = Response::$statusTexts;

    // Move 403/404/500 to the top.     $options = [
      '404' => $options['404'],
      '403' => $options['403'],
      '500' => $options['500'],
    ] + $options;

    // Add the HTTP status code, so it's easier for people to find it.     array_walk($optionsfunction D$title$code) use (&$options) {
      $options[$code] = $this->t('@code (@title)', ['@code' => $code, '@title' => $title]);
    });

    $form['status_code'] = [
      '#title' => $this->t('HTTP status code'),
      '#type' => 'select',
      '#default_value' => $this->options['status_code'],
      '#options' => $options,
    ];
  }

  
$previousCount = isset($this->matrix[$points]) ? $this->matrix[$points]->getCount() : 0;
                    $this->matrix[$points] = new MatrixElement($points$rating->getCount() + $previousCount);
                }
            }

            if (!\array_key_exists($points$this->matrix)) {
                $this->matrix[$points] = new MatrixElement($points, 0);
            }
        }

        array_walk($this->matrix, function DMatrixElement &$rating): void {
            if ($this->totalReviewCount > 0) {
                $rating->setPercent($rating->getCount() / $this->totalReviewCount * 100);
            } else {
                $rating->setPercent(0);
            }
        });
    }

    /** * @return MatrixElement[] */
    
if ($this->QBSet) {
            if ($this->db->DBDebug) {
                throw new DatabaseException('You must use the "set" method to update an entry.');
            }

            return false; // @codeCoverageIgnore         }

        $table = $this->QBFrom[0];
        $set   = $this->binds;

        array_walk($setstatic function Darray &$item) {
            $item = $item[0];
        });

        $key   = array_key_first($set);
        $value = $set[$key];

        $builder = $this->db->table($table);
        $exists  = $builder->where($key$value, true)->get()->getFirstRow();

        if (empty($exists) && $this->testMode) {
            $result = $this->getCompiledInsert();
        }

class Text_Diff_Engine_xdiff {

    /** */
    function diff($from_lines$to_lines)
    {
        array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
        array_walk($to_lines, array('Text_Diff', 'trimNewlines'));

        /* Convert the two input arrays into strings for xdiff processing. */
        $from_string = implode("\n", $from_lines);
        $to_string = implode("\n", $to_lines);

        /* Diff the two strings and convert the result to an array. */
        $diff = xdiff_string_diff($from_string$to_stringcount($to_lines));
        $diff = explode("\n", $diff);

        /* Walk through the diff one line at a time. We build the $edits * array of diff operations by reading the first character of the * xdiff output (which is in the "unified diff" format). * * Note that we don't have enough information to detect "changed" * lines using this approach, so we can't add Text_Diff_Op_changed * instances to the $edits array. The result is still perfectly * valid, albeit a little less descriptive and efficient. */
return $this->_block_header;
    }

    function _startBlock($header)
    {
        return $header;
    }

    function _lines($lines$prefix = ' ', $encode = true)
    {
        if ($encode) {
            array_walk($lines, array(&$this, '_encode'));
        }

        if ($this->_split_level == 'lines') {
            return implode("\n", $lines) . "\n";
        } else {
            return implode('', $lines);
        }
    }

    function _added($lines)
    {
        

    public function scanLocales(string $sourceDir): array
    {
        $locales = glob($sourceDir.'/*.txt', \GLOB_NOSORT);

        // Remove file extension and sort         array_walk($localesfunction D&$locale) { $locale = basename($locale, '.txt')});

        // Remove non-locales         $locales = array_filter($localesfn ($locale) => preg_match('/^[a-z]{2}(_.+)?$/', $locale));

        sort($locales);

        return $locales;
    }

    /** * Returns all locale aliases found in the given directory. * * @return array An array with the locale aliases as keys and the aliased * locales as values */

  protected function assertFieldSelectOptions(string $name, array $expected_options): void {
    $field = $this->assertSession()->selectExists($name);
    $options = $field->findAll('xpath', 'option');
    $optgroups = $field->findAll('xpath', 'optgroup');
    $nested_options = [];
    foreach ($optgroups as $optgroup) {
      $nested_options[] = $optgroup->findAll('xpath', 'option');
    }
    $options = array_merge($options, ...$nested_options);
    array_walk($optionsfunction DNodeElement &$option) {
      $option = $option->getAttribute('value');
    });
    $this->assertEqualsCanonicalizing($expected_options$options);
  }

}
$fileSystem->remove($temporaryPath);
        $fileSystem->mkdir($temporaryPath);

        $dumper = new PhpDumper($container);

        $dumper->setProxyDumper(new ProxyDumper());
        $containerFiles = $dumper->dump([
            'class' => 'LazyServiceProjectAsFilesServiceContainer',
            'as_files' => true,
        ]);

        array_walk(
            $containerFiles,
            static function Dstring $containerSources, string $fileName) use ($temporaryPath): void {
                (new Filesystem())->dumpFile($temporaryPath.'/'.$fileName$containerSources);
            }
        );

        require $temporaryPath.'/LazyServiceProjectAsFilesServiceContainer.php';
    }
}
Home | Imprint | This part of the site doesn't use cookies.