Mark Shust 4 meses atrás
pai
commit
6a4fbd29f1
3 arquivos alterados com 48 adições e 43 exclusões
  1. 5 0
      CHANGELOG.md
  2. 42 42
      compose/bin/xdebug
  3. 1 1
      compose/compose.yaml

+ 5 - 0
CHANGELOG.md

@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
+## [49.0.0] - 2024-01-15
+
+### Updated
+- Enhanced `bin/xdebug` script with more comprehensive mode management and validation, supporting all Xdebug modes (off, develop, coverage, debug, gcstats, profile, trace) and combinations [PR #1276](https://github.com/markshust/docker-magento/pull/1276)
+
 ## [48.0.1] - 2024-12-07
 
 ### Fixed

+ 42 - 42
compose/bin/xdebug

@@ -1,53 +1,53 @@
 #!/usr/bin/env bash
 
-S=$(bin/clinotty cat /usr/local/etc/php/php.ini | grep -iGc 'xdebug.mode = off');
+current_mode=$(bin/clinotty cat /usr/local/etc/php/php.ini | grep '^xdebug.mode' | cut -d'=' -f2 | tr -d ' ')
 
-xdebug_status() {
-    if [[ $S == 1 ]]; then
-        echo "Xdebug debug mode is disabled."
-    else
-        echo "Xdebug debug mode is enabled."
-    fi
+display_modes() {
+    echo "- off"
+    echo "- develop"
+    echo "- coverage"
+    echo "- debug"
+    echo "- gcstats"
+    echo "- profile"
+    echo "- trace"
+    echo ""
+    printf "You can also combine multiple modes with commas (e.g., develop,trace)\n"
 }
 
-xdebug_toggle() {
-    if [[ $S == 1 ]]; then
-        xdebug_enable
-    else
-        xdebug_disable
-    fi
-}
+xdebug_set_mode() {
+    local new_mode=$1
 
-xdebug_enable() {
-    if [[ $S == 1 ]]; then
-        bin/root sed -i -e 's/^xdebug.mode = off/xdebug.mode = debug/g' /usr/local/etc/php/php.ini
-        bin/cli kill -USR2 1
-        echo "Xdebug debug mode has been enabled."
-    else
-        echo "Xdebug debug mode is already enabled."
-    fi
-}
+    # Validate the mode(s)
+    IFS=',' read -ra MODES <<< "$new_mode"
+    for mode in "${MODES[@]}"; do
+        case $mode in
+            off|develop|coverage|debug|gcstats|profile|trace)
+                continue
+                ;;
+            *)
+                printf "Invalid mode: %s\n\n" "$mode"
+                echo "Valid modes are:"
+                display_modes
+                return 1
+                ;;
+        esac
+    done
 
-xdebug_disable() {
-    if [[ $S == 0 ]]; then
-        bin/root sed -i -e 's/^xdebug.mode = debug/xdebug.mode = off/g' /usr/local/etc/php/php.ini
-        bin/cli kill -USR2 1
-        echo "Xdebug debug mode has been disabled."
-    else
-        echo "Xdebug debug mode is already disabled."
+    if [ "$current_mode" = "$new_mode" ]; then
+        echo "Current setting is already: xdebug.mode = $new_mode"
+        return 0
     fi
+
+    bin/root sed -i -e "s/^xdebug\.mode.*$/xdebug.mode = $new_mode/g" /usr/local/etc/php/php.ini
+    bin/cli kill -USR2 1
+    echo "New setting: xdebug.mode = $new_mode"
 }
 
-firstArgLetter="$(echo "$1" | head -c 1)"
-
-if [[ $firstArgLetter == "d" ]]; then
-    xdebug_disable
-elif [[ $firstArgLetter == "e" ]]; then
-    xdebug_enable
-elif [[ $firstArgLetter == "t" ]]; then
-    xdebug_toggle
-elif [[ $firstArgLetter == "s" ]]; then
-    xdebug_status
-else
-    printf "Please specify either 'disable', 'enable', 'status' or 'toggle' as an argument.\nEx: bin/xdebug status\n"
+if [ -z "$1" ]; then
+    printf "Current setting: xdebug.mode = %s\n\n" "$current_mode"
+    printf "Update it by passing in a valid mode as an argument:\n"
+    display_modes
+    exit 1
 fi
+
+xdebug_set_mode "$1"

+ 1 - 1
compose/compose.yaml

@@ -1,7 +1,7 @@
 ## Mark Shust's Docker Configuration for Magento
 ## (https://github.com/markshust/docker-magento)
 ##
-## Version 48.0.1
+## Version 49.0.0
 
 ## To use SSH, see https://github.com/markshust/docker-magento#ssh
 ## Linux users, see https://github.com/markshust/docker-magento#linux