-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxdebug
62 lines (47 loc) · 1.29 KB
/
xdebug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
if [ $# -eq 0 ] || [ "--help" == "$1" ] || [ "-h" == "$1" ]
then
default=$(echo -e "\\033[0m")
title=$(echo -e "\\033[33m")
info=$(echo -e "\\033[32m")
cat <<USAGE
${title}Usage:${default}
xdebug [-h|--help] [<command>]
${title}Help:${default}
The ${info}xdebug${default} command allows to run a PHP command with Xdebug remote debug enabled.
Run a local executable PHP script:
${info}xdebug bin/console symfony:command${default}
Run the PHP command:
${info}xdebug php script.php${default}
USAGE
if [ $# -eq 0 ]
then
exit 3
fi
exit 0
fi
run_with_xdebug() {
DEVICE=`ip addr | grep "^3:" | awk '{ print $2 }' | sed -r 's/://g'`
IP=`ip addr | grep "global $DEVICE" | awk '{ print $2 }' | sed -r 's/\/24//g'`
XDEBUG_CONFIG="idekey=PHPSTORM" \
PHP_IDE_CONFIG="serverName=$IP" \
php \
-d zend_extension=xdebug.so \
-d xdebug.remote_enable=on \
-d xdebug.remote_host=`ip route | grep default | awk '{ print $3 }'` \
"$@"
}
if [ -f "$1" ]
then
run_with_xdebug "$@"
elif [ "php" != "$1" ]
then
if ! which "$1" > /dev/null 2>&1
then
echo "Not a PHP file or a command: $1"
exit 4
fi
run_with_xdebug "$(which "$1")" "${@:2}"
else
run_with_xdebug "${@:2}"
fi