Exemplo n.º 1
0
 /**
  * @api
  *
  * @param string $name
  *
  * @return $this
  */
 public function newBuilder($name = null)
 {
     if ($name === null) {
         throw RuntimeException::create()->setMessage('Builder name must be provided when creating tree builders.');
     }
     $this->setTreeBuilder(new TreeBuilder());
     $this->setNodeDefinition($this->treeBuilder->root($name));
     return $this;
 }
Exemplo n.º 2
0
 /**
  * @api
  *
  * @param string $name
  * @param string $type
  *
  * @return $this
  */
 public function newBuilder($name, $type)
 {
     $this->setNodeBuilder(new NodeBuilder());
     $method = $type . 'Node';
     if (!method_exists($this->nodeBuilder, $method)) {
         throw RuntimeException::create()->setMessage('Invalid node type "%s" provided when asking for new builder.', $method);
     }
     $this->setNodeDefinition(call_user_func([$this->nodeBuilder, $method], $name));
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Normalize config index string by allowing only alphanumeric strings with periods, dashes, and underscores. Remove
  * any consecutive periods which may have been introduced while building the index. Final index MUST begin with an
  * alpha character: an exception is thrown if this is not the case.
  *
  * @param string $resolvedIndexValue
  *
  * @return string
  *
  * @throws RuntimeException
  */
 private function normalizeConfigParameterIndex($resolvedIndexValue)
 {
     $validFirstChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $regexDeliminator = preg_quote($this->indexSeparator, '#');
     $normalizationRegexSet = ['#' . $regexDeliminator . '+#' => $this->indexSeparator, '#[^a-z0-9' . $regexDeliminator . '_-]#i' => ''];
     foreach ($normalizationRegexSet as $regex => $replace) {
         $resolvedIndexValue = (string) preg_replace($regex, $replace, $resolvedIndexValue);
     }
     if (false === stripos($validFirstChar, $resolvedIndexValue[0])) {
         throw RuntimeException::create()->setMessage('DI-auto config->parameter ids must begin with a letter: the index "%s" is invalid.', $resolvedIndexValue);
     }
     return (string) $resolvedIndexValue;
 }