cakephp/cakephp — pull request #1664 by rooseveltrp (2013-09-21 05:19:07+00:00)
Title: Created and Updated an Uility method File::replace()

This method allows you to search the current file for a specific string, and replace it with a given argument. Very useful for custom shell scripts or any general file operation where you need to replace specific contents of a file.

My apologizes to markstory. The original pull request can be found here: https://github.com/cakephp/cakephp/pull/1663. My original cakephp repository was faulty because the branch I was using was custom created and it was not an actual upstream/master branch. Anyways, here are some of the answers from the original pull request.

1) I realized that if the file is too big to process then it makes sense for the developer to use the terminal or increasing the memory limit. Because if we read a file piece by piece and run the replacement against one piece at a time and the string you are searching for gets split between the bytes, it will fail to replace the text. So, I changed the code to use CakePHP's $file->read() method.

Thanks :)