vendor/symfony/config/Definition/ArrayNode.php line 234

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Config\Definition;
  11. use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
  12. use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
  13. use Symfony\Component\Config\Definition\Exception\UnsetKeyException;
  14. /**
  15.  * Represents an Array node in the config tree.
  16.  *
  17.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  18.  */
  19. class ArrayNode extends BaseNode implements PrototypeNodeInterface
  20. {
  21.     protected $xmlRemappings = [];
  22.     protected $children = [];
  23.     protected $allowFalse false;
  24.     protected $allowNewKeys true;
  25.     protected $addIfNotSet false;
  26.     protected $performDeepMerging true;
  27.     protected $ignoreExtraKeys false;
  28.     protected $removeExtraKeys true;
  29.     protected $normalizeKeys true;
  30.     public function setNormalizeKeys($normalizeKeys)
  31.     {
  32.         $this->normalizeKeys = (bool) $normalizeKeys;
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      *
  37.      * Namely, you mostly have foo_bar in YAML while you have foo-bar in XML.
  38.      * After running this method, all keys are normalized to foo_bar.
  39.      *
  40.      * If you have a mixed key like foo-bar_moo, it will not be altered.
  41.      * The key will also not be altered if the target key already exists.
  42.      */
  43.     protected function preNormalize($value)
  44.     {
  45.         if (!$this->normalizeKeys || !\is_array($value)) {
  46.             return $value;
  47.         }
  48.         $normalized = [];
  49.         foreach ($value as $k => $v) {
  50.             if (str_contains($k'-') && !str_contains($k'_') && !\array_key_exists($normalizedKey str_replace('-''_'$k), $value)) {
  51.                 $normalized[$normalizedKey] = $v;
  52.             } else {
  53.                 $normalized[$k] = $v;
  54.             }
  55.         }
  56.         return $normalized;
  57.     }
  58.     /**
  59.      * Retrieves the children of this node.
  60.      *
  61.      * @return array<string, NodeInterface>
  62.      */
  63.     public function getChildren()
  64.     {
  65.         return $this->children;
  66.     }
  67.     /**
  68.      * Sets the xml remappings that should be performed.
  69.      *
  70.      * @param array $remappings An array of the form [[string, string]]
  71.      */
  72.     public function setXmlRemappings(array $remappings)
  73.     {
  74.         $this->xmlRemappings $remappings;
  75.     }
  76.     /**
  77.      * Gets the xml remappings that should be performed.
  78.      *
  79.      * @return array an array of the form [[string, string]]
  80.      */
  81.     public function getXmlRemappings()
  82.     {
  83.         return $this->xmlRemappings;
  84.     }
  85.     /**
  86.      * Sets whether to add default values for this array if it has not been
  87.      * defined in any of the configuration files.
  88.      *
  89.      * @param bool $boolean
  90.      */
  91.     public function setAddIfNotSet($boolean)
  92.     {
  93.         $this->addIfNotSet = (bool) $boolean;
  94.     }
  95.     /**
  96.      * Sets whether false is allowed as value indicating that the array should be unset.
  97.      *
  98.      * @param bool $allow
  99.      */
  100.     public function setAllowFalse($allow)
  101.     {
  102.         $this->allowFalse = (bool) $allow;
  103.     }
  104.     /**
  105.      * Sets whether new keys can be defined in subsequent configurations.
  106.      *
  107.      * @param bool $allow
  108.      */
  109.     public function setAllowNewKeys($allow)
  110.     {
  111.         $this->allowNewKeys = (bool) $allow;
  112.     }
  113.     /**
  114.      * Sets if deep merging should occur.
  115.      *
  116.      * @param bool $boolean
  117.      */
  118.     public function setPerformDeepMerging($boolean)
  119.     {
  120.         $this->performDeepMerging = (bool) $boolean;
  121.     }
  122.     /**
  123.      * Whether extra keys should just be ignored without an exception.
  124.      *
  125.      * @param bool $boolean To allow extra keys
  126.      * @param bool $remove  To remove extra keys
  127.      */
  128.     public function setIgnoreExtraKeys($boolean$remove true)
  129.     {
  130.         $this->ignoreExtraKeys = (bool) $boolean;
  131.         $this->removeExtraKeys $this->ignoreExtraKeys && $remove;
  132.     }
  133.     /**
  134.      * {@inheritdoc}
  135.      */
  136.     public function setName($name)
  137.     {
  138.         $this->name $name;
  139.     }
  140.     /**
  141.      * {@inheritdoc}
  142.      */
  143.     public function hasDefaultValue()
  144.     {
  145.         return $this->addIfNotSet;
  146.     }
  147.     /**
  148.      * {@inheritdoc}
  149.      */
  150.     public function getDefaultValue()
  151.     {
  152.         if (!$this->hasDefaultValue()) {
  153.             throw new \RuntimeException(sprintf('The node at path "%s" has no default value.'$this->getPath()));
  154.         }
  155.         $defaults = [];
  156.         foreach ($this->children as $name => $child) {
  157.             if ($child->hasDefaultValue()) {
  158.                 $defaults[$name] = $child->getDefaultValue();
  159.             }
  160.         }
  161.         return $defaults;
  162.     }
  163.     /**
  164.      * Adds a child node.
  165.      *
  166.      * @throws \InvalidArgumentException when the child node has no name
  167.      * @throws \InvalidArgumentException when the child node's name is not unique
  168.      */
  169.     public function addChild(NodeInterface $node)
  170.     {
  171.         $name $node->getName();
  172.         if ('' === $name) {
  173.             throw new \InvalidArgumentException('Child nodes must be named.');
  174.         }
  175.         if (isset($this->children[$name])) {
  176.             throw new \InvalidArgumentException(sprintf('A child node named "%s" already exists.'$name));
  177.         }
  178.         $this->children[$name] = $node;
  179.     }
  180.     /**
  181.      * {@inheritdoc}
  182.      *
  183.      * @throws UnsetKeyException
  184.      * @throws InvalidConfigurationException if the node doesn't have enough children
  185.      */
  186.     protected function finalizeValue($value)
  187.     {
  188.         if (false === $value) {
  189.             throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: "%s".'$this->getPath(), json_encode($value)));
  190.         }
  191.         foreach ($this->children as $name => $child) {
  192.             if (!\array_key_exists($name$value)) {
  193.                 if ($child->isRequired()) {
  194.                     $ex = new InvalidConfigurationException(sprintf('The child node "%s" at path "%s" must be configured.'$name$this->getPath()));
  195.                     $ex->setPath($this->getPath());
  196.                     throw $ex;
  197.                 }
  198.                 if ($child->hasDefaultValue()) {
  199.                     $value[$name] = $child->getDefaultValue();
  200.                 }
  201.                 continue;
  202.             }
  203.             if ($child->isDeprecated()) {
  204.                 @trigger_error($child->getDeprecationMessage($name$this->getPath()), \E_USER_DEPRECATED);
  205.             }
  206.             try {
  207.                 $value[$name] = $child->finalize($value[$name]);
  208.             } catch (UnsetKeyException $e) {
  209.                 unset($value[$name]);
  210.             }
  211.         }
  212.         return $value;
  213.     }
  214.     /**
  215.      * {@inheritdoc}
  216.      */
  217.     protected function validateType($value)
  218.     {
  219.         if (!\is_array($value) && (!$this->allowFalse || false !== $value)) {
  220.             $ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected array, but got %s'$this->getPath(), \gettype($value)));
  221.             if ($hint $this->getInfo()) {
  222.                 $ex->addHint($hint);
  223.             }
  224.             $ex->setPath($this->getPath());
  225.             throw $ex;
  226.         }
  227.     }
  228.     /**
  229.      * {@inheritdoc}
  230.      *
  231.      * @throws InvalidConfigurationException
  232.      */
  233.     protected function normalizeValue($value)
  234.     {
  235.         if (false === $value) {
  236.             return $value;
  237.         }
  238.         $value $this->remapXml($value);
  239.         $normalized = [];
  240.         foreach ($value as $name => $val) {
  241.             if (isset($this->children[$name])) {
  242.                 try {
  243.                     $normalized[$name] = $this->children[$name]->normalize($val);
  244.                 } catch (UnsetKeyException $e) {
  245.                 }
  246.                 unset($value[$name]);
  247.             } elseif (!$this->removeExtraKeys) {
  248.                 $normalized[$name] = $val;
  249.             }
  250.         }
  251.         // if extra fields are present, throw exception
  252.         if (\count($value) && !$this->ignoreExtraKeys) {
  253.             $proposals array_keys($this->children);
  254.             sort($proposals);
  255.             $guesses = [];
  256.             foreach (array_keys($value) as $subject) {
  257.                 $minScore = \INF;
  258.                 foreach ($proposals as $proposal) {
  259.                     $distance levenshtein($subject$proposal);
  260.                     if ($distance <= $minScore && $distance 3) {
  261.                         $guesses[$proposal] = $distance;
  262.                         $minScore $distance;
  263.                     }
  264.                 }
  265.             }
  266.             $msg sprintf('Unrecognized option%s "%s" under "%s"'=== \count($value) ? '' 's'implode(', 'array_keys($value)), $this->getPath());
  267.             if (\count($guesses)) {
  268.                 asort($guesses);
  269.                 $msg .= sprintf('. Did you mean "%s"?'implode('", "'array_keys($guesses)));
  270.             } else {
  271.                 $msg .= sprintf('. Available option%s %s "%s".'=== \count($proposals) ? '' 's'=== \count($proposals) ? 'is' 'are'implode('", "'$proposals));
  272.             }
  273.             $ex = new InvalidConfigurationException($msg);
  274.             $ex->setPath($this->getPath());
  275.             throw $ex;
  276.         }
  277.         return $normalized;
  278.     }
  279.     /**
  280.      * Remaps multiple singular values to a single plural value.
  281.      *
  282.      * @param array $value The source values
  283.      *
  284.      * @return array The remapped values
  285.      */
  286.     protected function remapXml($value)
  287.     {
  288.         foreach ($this->xmlRemappings as [$singular$plural]) {
  289.             if (!isset($value[$singular])) {
  290.                 continue;
  291.             }
  292.             $value[$plural] = Processor::normalizeConfig($value$singular$plural);
  293.             unset($value[$singular]);
  294.         }
  295.         return $value;
  296.     }
  297.     /**
  298.      * {@inheritdoc}
  299.      *
  300.      * @throws InvalidConfigurationException
  301.      * @throws \RuntimeException
  302.      */
  303.     protected function mergeValues($leftSide$rightSide)
  304.     {
  305.         if (false === $rightSide) {
  306.             // if this is still false after the last config has been merged the
  307.             // finalization pass will take care of removing this key entirely
  308.             return false;
  309.         }
  310.         if (false === $leftSide || !$this->performDeepMerging) {
  311.             return $rightSide;
  312.         }
  313.         foreach ($rightSide as $k => $v) {
  314.             // no conflict
  315.             if (!\array_key_exists($k$leftSide)) {
  316.                 if (!$this->allowNewKeys) {
  317.                     $ex = new InvalidConfigurationException(sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file. If you are trying to overwrite an element, make sure you redefine it with the same name.'$this->getPath()));
  318.                     $ex->setPath($this->getPath());
  319.                     throw $ex;
  320.                 }
  321.                 $leftSide[$k] = $v;
  322.                 continue;
  323.             }
  324.             if (!isset($this->children[$k])) {
  325.                 if (!$this->ignoreExtraKeys || $this->removeExtraKeys) {
  326.                     throw new \RuntimeException('merge() expects a normalized config array.');
  327.                 }
  328.                 $leftSide[$k] = $v;
  329.                 continue;
  330.             }
  331.             $leftSide[$k] = $this->children[$k]->merge($leftSide[$k], $v);
  332.         }
  333.         return $leftSide;
  334.     }
  335.     /**
  336.      * {@inheritdoc}
  337.      */
  338.     protected function allowPlaceholders(): bool
  339.     {
  340.         return false;
  341.     }
  342. }
dobrowin | betleao | moverbet | winzada 777 | supremo | casadeapostas | dobrowin | betleao | moverbet | wazamba | fezbet | betsson | lvbet | dobrowin | betsul | pixbet | bwin | betobet | dobrowin | bet7 | betcris | blaze | 888 | betano | stake | stake | esportesdasorte | betmotion | rivalry | novibet | pinnacle | cbet | dobrowin | betleao | moverbet | gogowin | jogos win | campobet | mesk bet | infinity bet | betfury | doce | bet7k | jogowin | lobo888 | iribet | leao | dobrowin | allwin | aajogo | pgwin | greenbets | brapub | moverbet | onebra | flames | brdice | brwin | poplottery | queens | winbrl | omgbet | winbra | goinbet | codbet | betleao | fuwin | allwin568 | wingdus | juntosbet | today | talon777 | brlwin | fazobetai | pinup bet | bet sport | bet esporte | mrbet | premier bet | apostebet | spicy bet | prosport bet | bet nacional | luck | jogodeouro | heads bet | marjack bet | apostaganha | gbg bet | esoccer bet | esport bet | realbet | aposte e ganhe | aviator aposta | bet vitoria | imperador bet | realsbet | bet favorita | esportenet | flames bet | pague bet | betsury | doce888 | obabet | winzada | globalbet | bet77 | lottoland | 7gamesbet | dicasbet | esportivabet | tvbet | sportbet | misterjackbet | esportebet | nacionalbet | simplesbet | betestrela | batbet | Pk55 | Bet61 | Upsports Bet | roleta online | roleta | poker online | poker | blackjack online | bingo | 12bet | 33win | bet168 | bk8 | bong88 | bong99 | fcb8 | hb88 | hotlive | ibet888 | k8 | kubet77 | kubet | lode88 | mig8 | nbet | onebox63 | oxbet | s666 | sbobet | suncity | vwin | w88 | win2888 | zbet | xoso66 | zowin | sun | top88 | vnloto | 11bet | bet69 | 8xbet | Ceará | Paysandu | Juventude | Bahia | Sport | Cuiabá | Coritiba | Criciúma | Vitória | Fortaleza | Corinthians | São Paulo | Vasco | Grêmio | Fluminense | Cruzeiro | Botafogo | Flamengo | bingo slots | slots slots | hacker do slot | pg slot demo | slot win | pg slot soft | arne slot | riqueza slots | slots 777 | pg slot | 777 slot game | slot pg soft | hacker slot | 777 slots | slot-pg-soft | fortune ox demo grátis | demo fortune ox | fortune mouse demo | fortune ox demo | jogo fortune tiger | fortune tiger grátis | fortune tiger baixar | fortune tiger demo grátis | fortune tiger demo | fortune tiger 777 | 580bet | bet 7k | leao | luck 2 | john bet | 7755 bet | cbet | bet7 | pk55 | 8800 bet | doce | bet 4 | f12bet | bet7 | ggbet | bet77 | mrbet | bet61 | tvbet | pgwin | today | fuwin | brwin | bet7k | tv bet | allwin | stake | bwin 789 | lvbet | blaze | dj bet | umbet | b1bet | 20bet | bk bet | h2bet | 7kbet | fbbet | 9d bet | 9k bet | 73 bet | ktobet | 74 bet | betpix | betvip | batbet | onabet | f12bet | codbet | winbra | b2xbet | obabet | brlwin | onebra | winbrl | omgbet | queens | brdice | brapub | flames | betano | aajogo | iribet | pixbet | betsul | fezbet | curso beta | betway | bkbet | peixe beta | bet365 | pixbet | 4 play bet | 365bet | brxbet | 939 bet | seubet | cnc bet | gbg bet | 522bet | brl bet | pagbet | jonbet | jqk bet | 166bet | abc bet | bggbet | obabet | 136bet | mmabet | win bet | ir6 bet | 667bet | qqq bet | 193 bet | 3ss bet | 317 bet | kkk bet | 585 bet | 569 bet | vai bet | aaa bet | 969 bet | z11 bet | kw bet | 26 bet | mj bet | betio | 01 bet | ut bet | 9y bet | bet70 | f9 bet | hw bet | kg bet | 5e bet | bet br | hr bet | br bet | 75 bet | 03 bet | 6z bet | 6r bet | v6 bet | 78 bet | bt bet | 80 bet | 8g bet | 72 bet | xp bet | f12 bet | p9 bet | 5 bet | 4 bet | bet 4 | r7 bet | um bet | 29 bet | 5s bet | ck bet | pg bet | ea bet | 23 bet | bl bet | 3l bet | 2a bet | p7 bet | 888 bet | 707 bet | 361 bet | bet29 | 700 bet | 161 bet | bet777 | up bet | 58 bet | nn bet | 67 bet | 22 bet | 9g bet | 1x bet | bet10 | 70 bet | 2h bet | 9r bet | 16 bet | 81 bet | 7 bet | 5u bet | 6k bet | mg bet | b1 bet | 5h bet | je- bet | joya | hopa | nomini | ls bet | 1xbit | platin | ice bet | rant | bet us | bet go | 31 bet | slingo | flush | ice36 | weiss | bet9 | rabona | i bet | starda | dreams | bongo | snatch | 10 bet | daddy | metal | zep bet | drip | gama | drake | verde | shazam | wish | thor | exclusive | sol | highway | 500 casino | jazz | howl | supernova | sherbet | fresh | daddy | jet | wish | eclipse | inplay | drip | marvel | stake | scorpion | luxebet | drake | thor | puma | winzir | loki | shazam | rivalry | f1 casino | xgbet | sushi | bk8 | art casino | manga | pgasia | gemini | bingoplus | slot vip | help slot win | 8k8 slot | tadhana slot | jili slot | 55bmw slot | vip slot | nn777 slot | jili slot 777 | tg777 slot | w500 slot | phfun slot | bmw55 slot | sg777 slot | wj slot | slot free 100 | lucky cola slot | cc6 slot | taya777 slot | ph444 slot | slot games | fb777 slot | okebet slot | help slot | tg77 slot | phwin slot | vvjl slot | fc777 slot | slot vin | yy777 slot | define slot | define slot | inplay | 99bet | 60win | melbet | jollibet | jili slot | rich711 | tayabet | phl63 | unobet | 63jili | mwplay888 | gold99 | jolibet | ubet95 | nice88 | jili777 | nn777 | phlove | jiliko | 55bmw | phoenix game | 8k8 | cgebet | 7up gaming | diamond game | hellowin | win88 | big win | kabibe game | sabong bet | phcity | colorplay | tongits go | slotsgo | spinph | go perya | casino frenzy | aurora game | escala gaming | winning plus | bingo plus | ph dream | 747 live | niceph | lucky cola | pera play