Forráskód Böngészése

Merge pull request #846 from massalinux/master

Mark Shust 2 éve
szülő
commit
d7489c80f8
2 módosított fájl, 63 hozzáadás és 0 törlés
  1. 1 0
      README.md
  2. 62 0
      compose/bin/debug-cli

+ 1 - 0
README.md

@@ -253,6 +253,7 @@ It is recommended to keep your root docker config files in one repository, and y
 - `bin/devconsole`: Alias for `bin/n98-magerun2 dev:console`
 - `bin/docker-compose`: Support V1 (`docker-compose`) and V2 (`docker compose`) docker compose command, and use custom configuration files, such as `compose.yml` and `compose.dev.yml`
 - `bin/download`: Download specific Magento version from Composer to the container, with optional arguments of the version (2.4.5-p1 [default]) and type ("community" [default], "enterprise", or "mageos"). Ex. `bin/download 2.4.5-p1 enterprise`
+- `bin/debug-cli`: Enable Xdebug for bin/magento, with an optional argument of the IDE key. Defaults to PHPSTORM Ex. `bin/debug-cli enable PHPSTORM`
 - `bin/fixowns`: This will fix filesystem ownerships within the container.
 - `bin/fixperms`: This will fix filesystem permissions within the container.
 - `bin/grunt`: Run the grunt binary. Ex. `bin/grunt exec`

+ 62 - 0
compose/bin/debug-cli

@@ -0,0 +1,62 @@
+#!/bin/bash
+S=$(bin/clinotty cat /usr/local/etc/php/php.ini | grep -iGc 'xdebug.mode = off');
+R=$(grep -c 'XDEBUG_CONFIG=idekey' ./env/phpfpm.env)
+
+if [[ -z "$2" ]]
+  then
+    platform="PHPSTORM"
+  else
+    platform=$2
+fi
+
+local_debug_status(){
+  if [[ $R != 0 ]]; then
+    echo "Cli debug enabled"
+  else
+    echo "Cli debug disabled"
+  fi
+}
+
+local_debug_toggle() {
+    if [[ $R != 0 ]]; then
+      local_debug_disable
+    else
+      local_debug_enable
+    fi
+}
+
+local_debug_enable() {
+  if [[ $S == 1 ]]; then
+    bin/xdebug enable
+  fi
+
+  if [[ $R != 0 ]]; then
+    echo "Already enabled"
+    exit 0
+  fi
+
+  echo "XDEBUG_CONFIG=idekey=$platform" >> ./env/phpfpm.env
+  sleep 1
+  bin/restart phpfpm
+  echo "Cli debug enabled"
+}
+
+local_debug_disable() {
+  sed -i '' '/XDEBUG_CONFIG=idekey/d' ./env/phpfpm.env
+  sleep 1
+  bin/restart phpfpm
+  echo "Cli debug disabled"
+}
+
+firstArgLetter="$(echo "$1" | head -c 1)"
+if [[ $firstArgLetter == "d" ]]; then
+  local_debug_disable
+elif [[ $firstArgLetter == "e" ]]; then
+  local_debug_enable
+elif [[ $firstArgLetter == "t" ]]; then
+  local_debug_toggle
+elif [[ $firstArgLetter == "s" ]]; then
+  local_debug_status
+else
+    printf "Please specify either 'disable', 'enable', 'status' or 'toggle' as mandatory argument.\nSpecify as an optional second argument the platform. Default is PHPSTORM\nEx: bin/debug-cli enable [PHPSTORM]\n"
+fi