diff --git a/src/Task/File/Replace.php b/src/Task/File/Replace.php index 7b4cd49d6..e493f7451 100644 --- a/src/Task/File/Replace.php +++ b/src/Task/File/Replace.php @@ -44,6 +44,11 @@ class Replace extends BaseTask */ protected $from; + /** + * @var integer + */ + protected $limit = -1; + /** * @var string|string[] */ @@ -112,6 +117,19 @@ public function regex($regex) return $this; } + /** + * If used with $this->regexp() how many counts will be replaced + * + * @param int $limit + * + * @return $this + */ + public function limit($limit) + { + $this->limit = $limit; + return $this; + } + /** * {@inheritdoc} */ @@ -124,7 +142,7 @@ public function run() $text = file_get_contents($this->filename); if ($this->regex) { - $text = preg_replace($this->regex, $this->to, $text, -1, $count); + $text = preg_replace($this->regex, $this->to, $text, $this->limit, $count); } else { $text = str_replace($this->from, $this->to, $text, $count); }