Skip to content

Instantly share code, notes, and snippets.

@henriquemoody
Last active September 28, 2015 23:08
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/1510328 to your computer and use it in GitHub Desktop.
Save henriquemoody/1510328 to your computer and use it in GitHub Desktop.
[php-entity-finder] Find PHP classes or interfaces.
#!/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