Ouzo\Tools\Model\Template\ClassStub::replacePlaceholders PHP Метод

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

public replacePlaceholders ( $replacement )
    public function replacePlaceholders($replacement)
    {
        foreach ($replacement as $key => $value) {
            $searchRegExp = $value ? "/{({$key})}/" : "/\\s*{({$key})}*/";
            $this->_stubContent = preg_replace($searchRegExp, $value, $this->_stubContent);
        }
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * @test
  */
 public function shouldReplacePlaceholderInStubFile()
 {
     //given
     $classStub = new ClassStub();
     //when
     $classStub->replacePlaceholders(array('class' => 'TestClassName', 'fields' => 'fieldA, fieldB'));
     //then
     $this->assertContains('TestClassName', $classStub->contents());
     $this->assertContains('fieldA, fieldB', $classStub->contents());
 }