Last active
September 28, 2015 23:08
-
-
Save henriquemoody/1510328 to your computer and use it in GitHub Desktop.
[php-entity-finder] Find PHP classes or interfaces.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Usage: {script} ENTITY | |
# | |
declare ENTITIES=${1} | |
find_entity() | |
{ | |
local entity=${1} | |
local spaces="${2}" | |
while read line; do | |
echo -n "${spaces} ${entity}: " | |
echo "${line}" | egrep --color=auto "\b${entity}\b" | |
pattern=".*(class|interface) +([^ ]+).+(extends|implements) +${entity}.*"; | |
echo "${line}" | egrep -q "${pattern}" | |
if [[ ${?} -eq 0 ]]; then | |
child_entity=$(echo ${line} | cut -d ':' -f 3 | sed -r "s/${pattern}/\2/g"); | |
if ! [[ "${ENTITIES}" =~ "\b${child_entity}\b" ]]; then | |
ENTITIES="${ENTITIES}:${child_entity}" | |
find_entity ${child_entity} "${spaces} " | |
fi | |
fi | |
done < <(egrep -Rn "\b${entity}\b" --include=*.php . | sort) | |
} | |
find_entity ${1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment