$strSubstitutor = new RecursiveStrSubstitutor(array('HOST' => '{{URL}}', 'URL' => 'website.foo')); $substituted = $strSubstitutor->replace('Connect with {{HOST}}');
Connect with website.foo
public function replace($string) { $nestLevel = 1; do { $originalString = $string; $nestLevel++; $string = $this->_substitutor->replace($string); } while ($originalString != $string && $nestLevel <= $this->_maxNestLevel); return $string; }
/** * @test */ public function shouldReturnValueWhenInfinityLoopOccurs() { //given $strSubstitutor = new RecursiveStrSubstitutor(array('URL' => '{{HOST}}', 'HOST' => '{{URL}}'), null, 10); //when $substituted = $strSubstitutor->replace('Best website: {{URL}}'); //then $this->assertEquals('Best website: {{URL}}', $substituted); }