/** * Returns the value of the binding. If the value is an instance of * \Drupal\drupalmoduleupgrader\Utility\Path\PathComponentInterface, * the binding expects to be physically represented in the path, although * it may not yet be (this can be ascertained by the inPath() method). Any * other value is used verbatim. * * @return mixed */ public function getValue() { if ($this->hasArgument()) { if ($this->isPathPosition()) { $position = $this->getArgument(); return $this->path->containsKey($position) ? $this->path[$position] : new PathComponent('%'); } else { return $this->getArgument(); } } else { $value = $this->getParameter()->getValue(); if ($value instanceof ScalarNode) { return $value->toValue(); } } }
/** * Apply the parameter map to a Drupal 8 route, modifying it as needed. * * @param \Symfony\Component\Routing\Route $route * The route to process. */ public function applyRoute(Drupal8Route $route) { $this->applyPath($this->path); foreach ($this as $key => $binding) { $parameter = $binding->getParameter(); /** @var ParameterBinding $binding */ if (is_integer($key)) { if ($parameter->isOptional()) { // @todo Don't use eval(). $value = eval('return ' . $parameter->getValue() . ';'); $route->setDefault($parameter->getName(), $value); } } elseif ($binding->hasArgument()) { $route->setDefault($parameter->getName(), $binding->getValue()); } } $route->setPath($this->path->__toString()); }