Ouzo\Utilities\RecursiveStrSubstitutor::replace PHP Метод

replace() публичный Метод

Example: $strSubstitutor = new RecursiveStrSubstitutor(array('HOST' => '{{URL}}', 'URL' => 'website.foo')); $substituted = $strSubstitutor->replace('Connect with {{HOST}}'); Result: Connect with website.foo
public replace ( string $string ) : mixed
$string string
Результат mixed
    public function replace($string)
    {
        $nestLevel = 1;
        do {
            $originalString = $string;
            $nestLevel++;
            $string = $this->_substitutor->replace($string);
        } while ($originalString != $string && $nestLevel <= $this->_maxNestLevel);
        return $string;
    }

Usage Example

 /**
  * @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);
 }
RecursiveStrSubstitutor