CLI serve command: add parameters to start Xdebug profiler

This commit is contained in:
Benjamin Renard 2023-03-22 19:18:23 +01:00
parent a274f04a1a
commit 8d0907b1ba
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
4 changed files with 189 additions and 81 deletions

View file

@ -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 <brenard@easter-eggs.com>\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 <em>homepage.tpl</em> 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"

View file

@ -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 ""

View file

@ -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);