Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create loading file from multiple php class files under lib directory.
#!/bin/bash
THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%N}}")"; pwd)"
files=("$(find ${THIS_DIR-}/lib -type f)")
class_lines=("$(printf '%s\n' "${files[@]}" \
| xargs -n 1 grep -m 1 -E '^(abstract )?class' \
| sed -r 's/^.*class ([A-Za-z]+)/\1/')")
class_names=("$(printf '%s\n' "${class_lines[@]}" | awk '{print $1}')")
remove_buildin_classes () {
sed \
-e 's/ extends Exception//;' \
-e 's/ implements ArrayAccess//'
}
breath_first_order () {
sed 's/class //;s/ extends/:/;s/$/;@echo $@/' \
| sed '/:/!{s/;/:;/}' \
| make -f- $* \
| grep -v make
}
echo "<?php"
printf '%s\n' "${class_lines[@]}" \
| remove_buildin_classes \
| breath_first_order "${class_names[@]}" \
| \
while read pattern ; do
printf '%s\n' "${files[@]}" \
| grep "/${pattern}.php$" \
| sed "s|${THIS_DIR-}||" \
| sed "s|.*|require(dirname(__FILE__) . '&');|"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.