cakephp/cakephp — pull request #1665 by rooseveltrp (2013-09-21 06:29:46+00:00)
Title: Added a method File::replace() to the File Utilities

Reopened Against Branch 2.5: https://github.com/cakephp/cakephp/pull/1664

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 :)