From 918c96ea3f9f159979095ac70641818beac4574a Mon Sep 17 00:00:00 2001 From: Ludwik Date: Mon, 20 Jul 2015 16:17:17 +0200 Subject: [PATCH] add ability to re-run replace --- src/Selector/NamedSelector.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Selector/NamedSelector.php b/src/Selector/NamedSelector.php index c8a37bef8..94ce213f1 100644 --- a/src/Selector/NamedSelector.php +++ b/src/Selector/NamedSelector.php @@ -168,15 +168,28 @@ public function __construct() { $this->xpathEscaper = new Escaper(); - foreach ($this->replacements as $from => $to) { - $this->replacements[$from] = strtr($to, $this->replacements); - } + $this->replace(); + } - foreach ($this->selectors as $alias => $selector) { - $this->selectors[$alias] = strtr($selector, $this->replacements); - } + /** + * Replace placeholders with replacements + * + * @return NamedSelector + */ + public function replace() + { + foreach ($this->replacements as $from => $to) { + $this->replacements[$from] = strtr($to, $this->replacements); + } + + foreach ($this->selectors as $alias => $selector) { + $this->selectors[$alias] = strtr($selector, $this->replacements); + } + + return $this; } + /** * Registers new XPath selector with specified name. *