Skip to content

Instantly share code, notes, and snippets.

@henriquemoody
Created August 23, 2011 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henriquemoody/1165985 to your computer and use it in GitHub Desktop.
Save henriquemoody/1165985 to your computer and use it in GitHub Desktop.
[php-entity-rename] Rename a PHP class or interface.
#!/bin/bash
oldName=$1
newName=$2
pattern="(new|class|extends|interface|implements) +(\b${oldName}\b)";
egrep -i "${pattern}" -Rn --include=*.php --exclude=*.svn* . | cut -d':' -f1 | sort | uniq | xargs sed -ri "s/${pattern}/\1 ${newName}/gi";
pattern="(\b${oldName}\b)::";
egrep -i "${pattern}" -Rn --include=*.php --exclude=*.svn* . | cut -d':' -f1 | sort | uniq | xargs sed -ri "s/${pattern}/${newName}::/gi";
pattern="(\b${oldName}\b)";
egrep -i "${pattern}" -Rn --include=*.php --exclude=*.svn* . | cut -d':' -f1 | sort | uniq | xargs sed -ri "s/${pattern}/${newName}/gi";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment