Files
structure/dockerfiles/workspace/xdebug.sh

74 lines
1.7 KiB
Bash
Raw Normal View History

2020-10-02 22:30:46 +03:00
#! /bin/bash
# NOTE: At the moment, this has only been confirmed to work with PHP 7
PHP_VERSION=$2 # Without dot
WITH_PROFILER=$3
2020-10-02 22:30:46 +03:00
# Grab full name of workspace container
WORKSPACE_CONTAINER=$(docker ps | grep workspace${PHP_VERSION} | awk '{print $1}')
2020-10-02 22:30:46 +03:00
if [[ -z "${WORKSPACE_CONTAINER}" ]]; then
echo "Unable to find workspace container: workspace${PHP_VERSION}"
exit 1
fi
2020-10-02 22:30:46 +03:00
if [[ ! -z "${WITH_PROFILER}" ]]; then
echo "With profiler option".
fi
2020-10-02 22:30:46 +03:00
xdebug_status ()
{
echo 'xDebug status'
docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
2020-10-02 22:30:46 +03:00
}
xdebug_start ()
{
echo 'Start xDebug'
# And uncomment line with xdebug extension, thus enabling it
ON_CMD='sed -i "s/^;zend_extension=/zend_extension=/g" /etc/php/$PHP_VERSION/cli/conf.d/20-xdebug.ini'
2020-10-02 22:30:46 +03:00
docker exec -it $WORKSPACE_CONTAINER bash -c "${ON_CMD}"
docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
2020-10-02 22:30:46 +03:00
echo 'In cli use this for resolve hostname for debugger in your IDE:'
echo 'export PHP_IDE_CONFIG="serverName=loc.mydomain.ru"'
2020-10-02 22:30:46 +03:00
}
xdebug_stop ()
{
echo 'Stop xDebug'
# Comment out xdebug extension line
OFF_CMD='sed -i "s/^zend_extension=/;zend_extension=/g" /etc/php/$PHP_VERSION/cli/conf.d/20-xdebug.ini'
2020-10-02 22:30:46 +03:00
docker exec -it $WORKSPACE_CONTAINER bash -c "${OFF_CMD}"
docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
2020-10-02 22:30:46 +03:00
}
case $1 in
2020-10-02 22:30:46 +03:00
stop|STOP)
xdebug_stop
;;
start|START)
xdebug_start
;;
status|STATUS)
xdebug_status
;;
*)
echo "xDebug [Stop | Start | Status] in the ${WORKSPACE_CONTAINER} container."
echo "xDebug must have already been installed."
echo "Usage:"
echo " .php-fpm/xdebug stop|start|status"
esac
exit 1