Created
July 25, 2017 07:22
-
-
Save greymd/cd55f15f2dbe9be84dcee192d441098c to your computer and use it in GitHub Desktop.
Create loading file from multiple php class files under lib directory.
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
#!/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