From 8d0907b1ba46f0afc50d939bef0720977b64d3bc Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 22 Mar 2023 19:18:23 +0100 Subject: [PATCH] CLI serve command: add parameters to start Xdebug profiler --- locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.mo | Bin 14331 -> 14878 bytes locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po | 105 ++++++++++++++-------- locales/messages.pot | 85 +++++++++++------- src/Cli.php | 80 ++++++++++++++--- 4 files changed, 189 insertions(+), 81 deletions(-) diff --git a/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.mo b/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.mo index 2929023cdc6b6ce9325d0d1f7fac994d54b9255c..ff101fe92f9f0ca44b56efadc0bdf82b5529bd8a 100644 GIT binary patch delta 3447 zcmb8wd2AGA7{~D!C@4!2D7BR;@KS*yva}Qht*9KW6x7mkOGVsvr*veyyUxxQ6?FyF zSkY*xMB{~;7;U17v0~yC(GqX{Q^dq89+(g{#v`bW`u*)ptI@>cO`rX|@9fUZJJ0*P z(_d2e`?(K`3icSNZ1*hY;xEN0uWy~~e z#*=Y7mf^#AChkYw=V#nuOwN=R8Z(*$cViSE#R_~E&%F8@a!^na(T@d>MXm{FvYe<;b6@%x%u^U(7o8frUIAbO=UW*I3zv-l-RQ2LiJcznrKPt6V zMaITbE zc^#Fq_i-s6#cEu5e2}ROYONo@a{Lr0;0Ug+iP_NEs3ll{{Fxz@pGLyouwxunmiOJf(CSuEzuTHBO|ok6_`6!7e$9x?UM2u8Ax|WvB_; z(MO&CLHPZ=9C=ppor6mG7C!VOU7@>?$(nmmDelDfUqs!2iZI5>oHSLm+LTTv;$ zEp&Hyd=F0HgxsBUv|pbgubS~ksG2y8=imezY{&Jujq!D;ecz8!tl;Iq!iZ&YGN1dKCOR9j3(vsAs3*6) zWi;b6P~!&FiEXGNdKg#Wui?01R*=C*FwOD(s2k2k|iR7v0}EJP1Au^f)XJ*ap5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*&hgHTmFER?RInKS_S#epL1ZMdo%8* ztJT_d-ss586N5W$PF^29pVyKQ-85}^d`I)t5~fvZheCGGyll(oiOtHkc7{D+pB1#j zjaIWa;BD$U9SYc1k=5w&I@999o~|=B{xGL|!~f2(>s-k0nPT{Vrnt1x3PwMkxijG( De0*Cr diff --git a/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po b/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po index 93736ea..ce07897 100644 --- a/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po +++ b/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2023-03-22 18:21+0100\n" +"POT-Creation-Date: 2023-03-22 19:13+0100\n" "PO-Revision-Date: \n" "Last-Translator: Benjamin Renard \n" "Language-Team: \n" @@ -132,62 +132,71 @@ msgstr "Démarrer le service HTTP intégré à PHP pour servir l'application" #: Cli.php:58 msgid "" -"This command could be used to start the PHP built-in HTTP server to serve " -"the application." +"This command could be used to start the PHP built-in HTTP server to serve\n" +"the application.\n" +"\n" +"Additionnal parameters:\n" +" -P/--enable-profiler Enable Xdebug profiler\n" +" -O/--profiler-output [path] Xdebug profiler output directory path" msgstr "" -"Cette commande peut-être utilisée pour démarrer le service HTTP intégré à " -"PHP pour servir l'application." +"Cette commande peut-être utilisée pour démarre le serveur HTTP intégré\n" +"à PHP pour servir l'application.\n" +"\n" +"Paramètres additionnels :\n" +" -P/--enable-profiler Activer le profilter Xdebug\n" +" -O/--profiler-output [path] Chemin du dossier de sortie du profiler\n" +" Xdebug" -#: Cli.php:89 +#: Cli.php:94 #, php-format msgid "The CLI command '%s' already exists." msgstr "La commande CLI '%s' n'existe pas." -#: Cli.php:94 +#: Cli.php:99 #, php-format msgid "The CLI command '%s' handler is not callable !" msgstr "La fonction implémentant la commande CLI '%s' n'est pas exécutable !" -#: Cli.php:126 +#: Cli.php:131 #, php-format msgid "Usage: %s [-h] [-qd] command\n" msgstr "Utilisation: %s [-h] [-qd] commande\n" -#: Cli.php:127 +#: Cli.php:132 msgid " -h Show this message\n" msgstr " -h Affiche ce message\n" -#: Cli.php:128 +#: Cli.php:133 msgid " -q / -d Quiet/Debug mode\n" msgstr " -q / -d Mode silencieux/debug\n" -#: Cli.php:129 +#: Cli.php:134 msgid " --trace Trace mode (the most verbose)\n" msgstr " --trace Mode trace (le plus verbeux)\n" -#: Cli.php:130 +#: Cli.php:135 msgid " -l / --log-file Overwrite log file specified in configuration\n" msgstr "" " -l / --log-file Redéfinir le fichier de journalisation à utiliser à la " "place de celui défini dans la configuration\n" -#: Cli.php:131 +#: Cli.php:136 msgid " -C / --console Enable log on console\n" msgstr " -C / --console Activer la journalisation dans la console\n" -#: Cli.php:132 +#: Cli.php:137 msgid " command Command to run\n" msgstr " command La commande à exécuter\n" -#: Cli.php:134 +#: Cli.php:139 msgid "Available commands:\n" msgstr "Commandes disponibles:\n" -#: Cli.php:184 +#: Cli.php:189 msgid "Only one command could be executed !" msgstr "Une seul commande peut-être exécutée !" -#: Cli.php:221 +#: Cli.php:226 #, php-format msgid "" "Invalid parameter \"%s\".\n" @@ -197,32 +206,44 @@ msgstr "" "Note : Les paramètres/arguments de la requête doivent être placés après " "celle-ci." -#: Cli.php:246 +#: Cli.php:251 #, php-format msgid "An exception occured running command %s" msgstr "Une exception est survenue en exécutant la commande %s" -#: Cli.php:309 -msgid "" -"This command only accept one argument: the listen address in format \"host:" -"port\" or \":port\" (= 0.0.0.0:port)." -msgstr "" -"Cette commande n'accepte qu'un seul paramètre : l'adresse d'écoute au format " -"\"hôte:port\" ou \":port\" (= 0.0.0.0:port)." +#: Cli.php:319 +msgid "The PHP XDEBUG extension is missing." +msgstr "L'extension PHP XDEBUG ne semble pas installée." -#: Cli.php:320 +#: Cli.php:330 +#, php-format +msgid "Invalid profiler output directory \"%s\": not found" +msgstr "Dossier de sortie du profiler invalide \"%s\" : introuvable" + +#: Cli.php:337 +#, php-format +msgid "Invalid profiler output directory \"%s\": not writeable" +msgstr "" +"Dossier de sortie du profiler invalide \"%s\" : non-accessible en écriture" + +#: Cli.php:349 +#, php-format +msgid "Invalid parameter \"%s\"" +msgstr "Paramètre \"%s\" invalide" + +#: Cli.php:362 msgid "" "Invalid listen address specify. Must be in formart host:port (or :port)." msgstr "" "Adresse d'écoute spécifiée invalide. Elle doit être au format hôte:port (ou :" "port)." -#: Cli.php:330 +#: Cli.php:372 msgid "Invalid listen host specified. Must be an IPv4 or IPv6 address." msgstr "" "Hôte d'écoute spécifié invalide. Il doit s'agir d'une adresse IPv4 ou IPv6." -#: Cli.php:337 +#: Cli.php:379 msgid "" "Invalid listen port specified. Must be a positive integer between 1 and " "65535." @@ -230,13 +251,13 @@ msgstr "" "Port d'écoute spécifié invalide. Il doit s'agir d'un entier positif entre 1 " "et 65535." -#: Cli.php:367 +#: Cli.php:423 msgid "Can't invoke bash. Can't ask password prompt." msgstr "" "Impossible d'utiliser bash. Impossible de demander à l'utilisateur de saisir " "un mot de passe." -#: Cli.php:370 +#: Cli.php:426 msgid "Please enter password:" msgstr "Merci de saisir le mot de passe :" @@ -601,23 +622,23 @@ msgstr "Déconnexion" msgid "Log in" msgstr "Connexion" -#: templates/empty.tpl:117 +#: templates/empty.tpl:119 msgid "Loading time:" msgstr "Temps de chargement :" -#: templates/empty.tpl:118 +#: templates/empty.tpl:120 msgid "Page: %1" msgstr "Page : %1" -#: templates/empty.tpl:119 +#: templates/empty.tpl:121 msgid "Database: %1" msgstr "Base de données : %1" -#: templates/empty.tpl:120 +#: templates/empty.tpl:122 msgid "Templating: " msgstr "Modèle : " -#: templates/empty.tpl:121 +#: templates/empty.tpl:123 msgid "Total: " msgstr "Total : " @@ -637,6 +658,20 @@ msgstr "" "fichier homepage.tpl pour l'écraser. Vous pouvez également écraser " "le gestionnaire de l'URL racine de l'application web." +#~ msgid "" +#~ "This command could be used to start the PHP built-in HTTP server to serve " +#~ "the application." +#~ msgstr "" +#~ "Cette commande peut-être utilisée pour démarrer le service HTTP intégré à " +#~ "PHP pour servir l'application." + +#~ msgid "" +#~ "This command only accept one argument: the listen address in format " +#~ "\"host:port\" or \":port\" (= 0.0.0.0:port)." +#~ msgstr "" +#~ "Cette commande n'accepte qu'un seul paramètre : l'adresse d'écoute au " +#~ "format \"hôte:port\" ou \":port\" (= 0.0.0.0:port)." + #~ msgid "Logout" #~ msgstr "Déconnexion" diff --git a/locales/messages.pot b/locales/messages.pot index 2b00dca..2608939 100644 --- a/locales/messages.pot +++ b/locales/messages.pot @@ -1,7 +1,7 @@ msgid "" msgstr "" -"POT-Creation-Date: 2023-03-22 18:21+0100\n" -"PO-Revision-Date: 2023-03-22 18:21+0100\n" +"POT-Creation-Date: 2023-03-22 19:13+0100\n" +"PO-Revision-Date: 2023-03-22 19:13+0100\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -116,95 +116,112 @@ msgstr "" #: Cli.php:58 msgid "" -"This command could be used to start the PHP built-in HTTP server to serve " -"the application." -msgstr "" - -#: Cli.php:89 -#, php-format -msgid "The CLI command '%s' already exists." +"This command could be used to start the PHP built-in HTTP server to serve\n" +"the application.\n" +"\n" +"Additionnal parameters:\n" +" -P/--enable-profiler Enable Xdebug profiler\n" +" -O/--profiler-output [path] Xdebug profiler output directory path" msgstr "" #: Cli.php:94 #, php-format +msgid "The CLI command '%s' already exists." +msgstr "" + +#: Cli.php:99 +#, php-format msgid "The CLI command '%s' handler is not callable !" msgstr "" -#: Cli.php:126 +#: Cli.php:131 #, php-format msgid "Usage: %s [-h] [-qd] command\n" msgstr "" -#: Cli.php:127 +#: Cli.php:132 msgid " -h Show this message\n" msgstr "" -#: Cli.php:128 +#: Cli.php:133 msgid " -q / -d Quiet/Debug mode\n" msgstr "" -#: Cli.php:129 +#: Cli.php:134 msgid " --trace Trace mode (the most verbose)\n" msgstr "" -#: Cli.php:130 +#: Cli.php:135 msgid " -l / --log-file Overwrite log file specified in configuration\n" msgstr "" -#: Cli.php:131 +#: Cli.php:136 msgid " -C / --console Enable log on console\n" msgstr "" -#: Cli.php:132 +#: Cli.php:137 msgid " command Command to run\n" msgstr "" -#: Cli.php:134 +#: Cli.php:139 msgid "Available commands:\n" msgstr "" -#: Cli.php:184 +#: Cli.php:189 msgid "Only one command could be executed !" msgstr "" -#: Cli.php:221 +#: Cli.php:226 #, php-format msgid "" "Invalid parameter \"%s\".\n" "Note: Command's parameter/argument must be place after the command." msgstr "" -#: Cli.php:246 +#: Cli.php:251 #, php-format msgid "An exception occured running command %s" msgstr "" -#: Cli.php:309 -msgid "" -"This command only accept one argument: the listen address in format \"host:" -"port\" or \":port\" (= 0.0.0.0:port)." +#: Cli.php:319 +msgid "The PHP XDEBUG extension is missing." msgstr "" -#: Cli.php:320 +#: Cli.php:330 +#, php-format +msgid "Invalid profiler output directory \"%s\": not found" +msgstr "" + +#: Cli.php:337 +#, php-format +msgid "Invalid profiler output directory \"%s\": not writeable" +msgstr "" + +#: Cli.php:349 +#, php-format +msgid "Invalid parameter \"%s\"" +msgstr "" + +#: Cli.php:362 msgid "" "Invalid listen address specify. Must be in formart host:port (or :port)." msgstr "" -#: Cli.php:330 +#: Cli.php:372 msgid "Invalid listen host specified. Must be an IPv4 or IPv6 address." msgstr "" -#: Cli.php:337 +#: Cli.php:379 msgid "" "Invalid listen port specified. Must be a positive integer between 1 and " "65535." msgstr "" -#: Cli.php:367 +#: Cli.php:423 msgid "Can't invoke bash. Can't ask password prompt." msgstr "" -#: Cli.php:370 +#: Cli.php:426 msgid "Please enter password:" msgstr "" @@ -525,23 +542,23 @@ msgstr "" msgid "Log in" msgstr "" -#: templates/empty.tpl:117 +#: templates/empty.tpl:119 msgid "Loading time:" msgstr "" -#: templates/empty.tpl:118 +#: templates/empty.tpl:120 msgid "Page: %1" msgstr "" -#: templates/empty.tpl:119 +#: templates/empty.tpl:121 msgid "Database: %1" msgstr "" -#: templates/empty.tpl:120 +#: templates/empty.tpl:122 msgid "Templating: " msgstr "" -#: templates/empty.tpl:121 +#: templates/empty.tpl:123 msgid "Total: " msgstr "" diff --git a/src/Cli.php b/src/Cli.php index 92c57a3..6b6ff36 100644 --- a/src/Cli.php +++ b/src/Cli.php @@ -53,10 +53,15 @@ class Cli { 'serve', array('\\EesyPHP\\Cli', 'cli_serve'), ___("Start the PHP built-in HTTP server to serve the application"), - null, + '[-h] [-P -O path]', ___( - "This command could be used to start the PHP built-in HTTP server to serve the ". - "application.") +"This command could be used to start the PHP built-in HTTP server to serve +the application. + +Additionnal parameters: + -P/--enable-profiler Enable Xdebug profiler + -O/--profiler-output [path] Xdebug profiler output directory path" + ) ); } } @@ -303,17 +308,54 @@ class Cli { * @return void */ public static function cli_serve($command_args) { - if (count($command_args) > 1) { - self :: usage( - I18n::_( - 'This command only accept one argument: the listen address in format "host:port" or '. - '":port" (= 0.0.0.0:port).') - ); - return; + $listen_address = null; + $enable_profiler = false; + $profiler_output_dir = realpath(getcwd()); + for($i=0; $i < count($command_args); $i++) { + switch($command_args[$i]) { + case '-P': + case '--enable-profiler': + if (phpversion('xdebug') === false) { + self :: usage(I18n::_("The PHP XDEBUG extension is missing.")); + return; + } + $enable_profiler = true; + break; + case '-O': + case '--profiler-output': + $i++; + $profiler_output_dir = $command_args[$i]; + if (!is_dir($profiler_output_dir)) { + self :: usage( + I18n::_('Invalid profiler output directory "%s": not found'), + $profiler_output_dir + ); + return; + } + if (!is_writable($profiler_output_dir)) { + self :: usage( + I18n::_('Invalid profiler output directory "%s": not writeable'), + $profiler_output_dir + ); + return; + } + break; + default: + if (is_null($listen_address)) { + $i++; + $listen_address = $command_args[$i]; + } + else { + self :: usage(I18n::_('Invalid parameter "%s"', $command_args[$i])); + return; + } + break; + } } // Check listen address - $listen_address = ($command_args?$command_args[0]:'127.0.0.1:8000'); + if (is_null($listen_address)) + $listen_address = '127.0.0.1:8000'; $parts = explode(':', $listen_address); if (count($parts) != 2) { self :: usage( @@ -347,8 +389,22 @@ class Cli { $public_html ) ); + $args = array( + "-S", $listen_address, + ); + if ($enable_profiler) { + $args = array_merge( + $args, + array( + "-d", "xdebug.mode=profile", + "-d", "xdebug.profiler_enable=On", + "-d", "xdebug.profiler_output_dir=$profiler_output_dir", + ) + ); + } passthru( - "EESYPHP_SERVE_URL=http://$listen_address ".PHP_BINARY." -S $listen_address index.php", + "EESYPHP_SERVE_URL=http://$listen_address ".PHP_BINARY." ". + implode(' ', array_map('escapeshellarg', $args))." index.php", $exit_code ); exit($exit_code);