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 "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "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" "PO-Revision-Date: \n"
"Last-Translator: Benjamin Renard <brenard@easter-eggs.com>\n" "Last-Translator: Benjamin Renard <brenard@easter-eggs.com>\n"
"Language-Team: \n" "Language-Team: \n"
@ -132,62 +132,71 @@ msgstr "Démarrer le service HTTP intégré à PHP pour servir l'application"
#: Cli.php:58 #: Cli.php:58
msgid "" msgid ""
"This command could be used to start the PHP built-in HTTP server to serve " "This command could be used to start the PHP built-in HTTP server to serve\n"
"the application." "the application.\n"
"\n"
"Additionnal parameters:\n"
" -P/--enable-profiler Enable Xdebug profiler\n"
" -O/--profiler-output [path] Xdebug profiler output directory path"
msgstr "" msgstr ""
"Cette commande peut-être utilisée pour démarrer le service HTTP intégré à " "Cette commande peut-être utilisée pour démarre le serveur HTTP intégré\n"
"PHP pour servir l'application." "à 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 #, php-format
msgid "The CLI command '%s' already exists." msgid "The CLI command '%s' already exists."
msgstr "La commande CLI '%s' n'existe pas." msgstr "La commande CLI '%s' n'existe pas."
#: Cli.php:94 #: Cli.php:99
#, php-format #, php-format
msgid "The CLI command '%s' handler is not callable !" msgid "The CLI command '%s' handler is not callable !"
msgstr "La fonction implémentant la commande CLI '%s' n'est pas exécutable !" msgstr "La fonction implémentant la commande CLI '%s' n'est pas exécutable !"
#: Cli.php:126 #: Cli.php:131
#, php-format #, php-format
msgid "Usage: %s [-h] [-qd] command\n" msgid "Usage: %s [-h] [-qd] command\n"
msgstr "Utilisation: %s [-h] [-qd] commande\n" msgstr "Utilisation: %s [-h] [-qd] commande\n"
#: Cli.php:127 #: Cli.php:132
msgid " -h Show this message\n" msgid " -h Show this message\n"
msgstr " -h Affiche ce message\n" msgstr " -h Affiche ce message\n"
#: Cli.php:128 #: Cli.php:133
msgid " -q / -d Quiet/Debug mode\n" msgid " -q / -d Quiet/Debug mode\n"
msgstr " -q / -d Mode silencieux/debug\n" msgstr " -q / -d Mode silencieux/debug\n"
#: Cli.php:129 #: Cli.php:134
msgid " --trace Trace mode (the most verbose)\n" msgid " --trace Trace mode (the most verbose)\n"
msgstr " --trace Mode trace (le plus verbeux)\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" msgid " -l / --log-file Overwrite log file specified in configuration\n"
msgstr "" msgstr ""
" -l / --log-file Redéfinir le fichier de journalisation à utiliser à la " " -l / --log-file Redéfinir le fichier de journalisation à utiliser à la "
"place de celui défini dans la configuration\n" "place de celui défini dans la configuration\n"
#: Cli.php:131 #: Cli.php:136
msgid " -C / --console Enable log on console\n" msgid " -C / --console Enable log on console\n"
msgstr " -C / --console Activer la journalisation dans la console\n" msgstr " -C / --console Activer la journalisation dans la console\n"
#: Cli.php:132 #: Cli.php:137
msgid " command Command to run\n" msgid " command Command to run\n"
msgstr " command La commande à exécuter\n" msgstr " command La commande à exécuter\n"
#: Cli.php:134 #: Cli.php:139
msgid "Available commands:\n" msgid "Available commands:\n"
msgstr "Commandes disponibles:\n" msgstr "Commandes disponibles:\n"
#: Cli.php:184 #: Cli.php:189
msgid "Only one command could be executed !" msgid "Only one command could be executed !"
msgstr "Une seul commande peut-être exécutée !" msgstr "Une seul commande peut-être exécutée !"
#: Cli.php:221 #: Cli.php:226
#, php-format #, php-format
msgid "" msgid ""
"Invalid parameter \"%s\".\n" "Invalid parameter \"%s\".\n"
@ -197,32 +206,44 @@ msgstr ""
"Note : Les paramètres/arguments de la requête doivent être placés après " "Note : Les paramètres/arguments de la requête doivent être placés après "
"celle-ci." "celle-ci."
#: Cli.php:246 #: Cli.php:251
#, php-format #, php-format
msgid "An exception occured running command %s" msgid "An exception occured running command %s"
msgstr "Une exception est survenue en exécutant la commande %s" msgstr "Une exception est survenue en exécutant la commande %s"
#: Cli.php:309 #: Cli.php:319
msgid "" msgid "The PHP XDEBUG extension is missing."
"This command only accept one argument: the listen address in format \"host:" msgstr "L'extension PHP XDEBUG ne semble pas installée."
"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: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 "" msgid ""
"Invalid listen address specify. Must be in formart host:port (or :port)." "Invalid listen address specify. Must be in formart host:port (or :port)."
msgstr "" msgstr ""
"Adresse d'écoute spécifiée invalide. Elle doit être au format hôte:port (ou :" "Adresse d'écoute spécifiée invalide. Elle doit être au format hôte:port (ou :"
"port)." "port)."
#: Cli.php:330 #: Cli.php:372
msgid "Invalid listen host specified. Must be an IPv4 or IPv6 address." msgid "Invalid listen host specified. Must be an IPv4 or IPv6 address."
msgstr "" msgstr ""
"Hôte d'écoute spécifié invalide. Il doit s'agir d'une adresse IPv4 ou IPv6." "Hôte d'écoute spécifié invalide. Il doit s'agir d'une adresse IPv4 ou IPv6."
#: Cli.php:337 #: Cli.php:379
msgid "" msgid ""
"Invalid listen port specified. Must be a positive integer between 1 and " "Invalid listen port specified. Must be a positive integer between 1 and "
"65535." "65535."
@ -230,13 +251,13 @@ msgstr ""
"Port d'écoute spécifié invalide. Il doit s'agir d'un entier positif entre 1 " "Port d'écoute spécifié invalide. Il doit s'agir d'un entier positif entre 1 "
"et 65535." "et 65535."
#: Cli.php:367 #: Cli.php:423
msgid "Can't invoke bash. Can't ask password prompt." msgid "Can't invoke bash. Can't ask password prompt."
msgstr "" msgstr ""
"Impossible d'utiliser bash. Impossible de demander à l'utilisateur de saisir " "Impossible d'utiliser bash. Impossible de demander à l'utilisateur de saisir "
"un mot de passe." "un mot de passe."
#: Cli.php:370 #: Cli.php:426
msgid "Please enter password:" msgid "Please enter password:"
msgstr "Merci de saisir le mot de passe :" msgstr "Merci de saisir le mot de passe :"
@ -601,23 +622,23 @@ msgstr "Déconnexion"
msgid "Log in" msgid "Log in"
msgstr "Connexion" msgstr "Connexion"
#: templates/empty.tpl:117 #: templates/empty.tpl:119
msgid "Loading time:" msgid "Loading time:"
msgstr "Temps de chargement :" msgstr "Temps de chargement :"
#: templates/empty.tpl:118 #: templates/empty.tpl:120
msgid "Page: %1" msgid "Page: %1"
msgstr "Page : %1" msgstr "Page : %1"
#: templates/empty.tpl:119 #: templates/empty.tpl:121
msgid "Database: %1" msgid "Database: %1"
msgstr "Base de données : %1" msgstr "Base de données : %1"
#: templates/empty.tpl:120 #: templates/empty.tpl:122
msgid "Templating: " msgid "Templating: "
msgstr "Modèle : " msgstr "Modèle : "
#: templates/empty.tpl:121 #: templates/empty.tpl:123
msgid "Total: " msgid "Total: "
msgstr "Total : " msgstr "Total : "
@ -637,6 +658,20 @@ msgstr ""
"fichier <em>homepage.tpl</em> pour l'écraser. Vous pouvez également écraser " "fichier <em>homepage.tpl</em> pour l'écraser. Vous pouvez également écraser "
"le gestionnaire de l'URL racine de l'application web." "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" #~ msgid "Logout"
#~ msgstr "Déconnexion" #~ msgstr "Déconnexion"

View file

@ -1,7 +1,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"POT-Creation-Date: 2023-03-22 18:21+0100\n" "POT-Creation-Date: 2023-03-22 19:13+0100\n"
"PO-Revision-Date: 2023-03-22 18:21+0100\n" "PO-Revision-Date: 2023-03-22 19:13+0100\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
@ -116,95 +116,112 @@ msgstr ""
#: Cli.php:58 #: Cli.php:58
msgid "" msgid ""
"This command could be used to start the PHP built-in HTTP server to serve " "This command could be used to start the PHP built-in HTTP server to serve\n"
"the application." "the application.\n"
msgstr "" "\n"
"Additionnal parameters:\n"
#: Cli.php:89 " -P/--enable-profiler Enable Xdebug profiler\n"
#, php-format " -O/--profiler-output [path] Xdebug profiler output directory path"
msgid "The CLI command '%s' already exists."
msgstr "" msgstr ""
#: Cli.php:94 #: Cli.php:94
#, php-format #, php-format
msgid "The CLI command '%s' already exists."
msgstr ""
#: Cli.php:99
#, php-format
msgid "The CLI command '%s' handler is not callable !" msgid "The CLI command '%s' handler is not callable !"
msgstr "" msgstr ""
#: Cli.php:126 #: Cli.php:131
#, php-format #, php-format
msgid "Usage: %s [-h] [-qd] command\n" msgid "Usage: %s [-h] [-qd] command\n"
msgstr "" msgstr ""
#: Cli.php:127 #: Cli.php:132
msgid " -h Show this message\n" msgid " -h Show this message\n"
msgstr "" msgstr ""
#: Cli.php:128 #: Cli.php:133
msgid " -q / -d Quiet/Debug mode\n" msgid " -q / -d Quiet/Debug mode\n"
msgstr "" msgstr ""
#: Cli.php:129 #: Cli.php:134
msgid " --trace Trace mode (the most verbose)\n" msgid " --trace Trace mode (the most verbose)\n"
msgstr "" msgstr ""
#: Cli.php:130 #: Cli.php:135
msgid " -l / --log-file Overwrite log file specified in configuration\n" msgid " -l / --log-file Overwrite log file specified in configuration\n"
msgstr "" msgstr ""
#: Cli.php:131 #: Cli.php:136
msgid " -C / --console Enable log on console\n" msgid " -C / --console Enable log on console\n"
msgstr "" msgstr ""
#: Cli.php:132 #: Cli.php:137
msgid " command Command to run\n" msgid " command Command to run\n"
msgstr "" msgstr ""
#: Cli.php:134 #: Cli.php:139
msgid "Available commands:\n" msgid "Available commands:\n"
msgstr "" msgstr ""
#: Cli.php:184 #: Cli.php:189
msgid "Only one command could be executed !" msgid "Only one command could be executed !"
msgstr "" msgstr ""
#: Cli.php:221 #: Cli.php:226
#, php-format #, php-format
msgid "" msgid ""
"Invalid parameter \"%s\".\n" "Invalid parameter \"%s\".\n"
"Note: Command's parameter/argument must be place after the command." "Note: Command's parameter/argument must be place after the command."
msgstr "" msgstr ""
#: Cli.php:246 #: Cli.php:251
#, php-format #, php-format
msgid "An exception occured running command %s" msgid "An exception occured running command %s"
msgstr "" msgstr ""
#: Cli.php:309 #: Cli.php:319
msgid "" msgid "The PHP XDEBUG extension is missing."
"This command only accept one argument: the listen address in format \"host:"
"port\" or \":port\" (= 0.0.0.0:port)."
msgstr "" 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 "" msgid ""
"Invalid listen address specify. Must be in formart host:port (or :port)." "Invalid listen address specify. Must be in formart host:port (or :port)."
msgstr "" msgstr ""
#: Cli.php:330 #: Cli.php:372
msgid "Invalid listen host specified. Must be an IPv4 or IPv6 address." msgid "Invalid listen host specified. Must be an IPv4 or IPv6 address."
msgstr "" msgstr ""
#: Cli.php:337 #: Cli.php:379
msgid "" msgid ""
"Invalid listen port specified. Must be a positive integer between 1 and " "Invalid listen port specified. Must be a positive integer between 1 and "
"65535." "65535."
msgstr "" msgstr ""
#: Cli.php:367 #: Cli.php:423
msgid "Can't invoke bash. Can't ask password prompt." msgid "Can't invoke bash. Can't ask password prompt."
msgstr "" msgstr ""
#: Cli.php:370 #: Cli.php:426
msgid "Please enter password:" msgid "Please enter password:"
msgstr "" msgstr ""
@ -525,23 +542,23 @@ msgstr ""
msgid "Log in" msgid "Log in"
msgstr "" msgstr ""
#: templates/empty.tpl:117 #: templates/empty.tpl:119
msgid "Loading time:" msgid "Loading time:"
msgstr "" msgstr ""
#: templates/empty.tpl:118 #: templates/empty.tpl:120
msgid "Page: %1" msgid "Page: %1"
msgstr "" msgstr ""
#: templates/empty.tpl:119 #: templates/empty.tpl:121
msgid "Database: %1" msgid "Database: %1"
msgstr "" msgstr ""
#: templates/empty.tpl:120 #: templates/empty.tpl:122
msgid "Templating: " msgid "Templating: "
msgstr "" msgstr ""
#: templates/empty.tpl:121 #: templates/empty.tpl:123
msgid "Total: " msgid "Total: "
msgstr "" msgstr ""

View file

@ -53,10 +53,15 @@ class Cli {
'serve', 'serve',
array('\\EesyPHP\\Cli', 'cli_serve'), array('\\EesyPHP\\Cli', 'cli_serve'),
___("Start the PHP built-in HTTP server to serve the application"), ___("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 ". "This command could be used to start the PHP built-in HTTP server to serve
"application.") 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 * @return void
*/ */
public static function cli_serve($command_args) { public static function cli_serve($command_args) {
if (count($command_args) > 1) { $listen_address = null;
self :: usage( $enable_profiler = false;
I18n::_( $profiler_output_dir = realpath(getcwd());
'This command only accept one argument: the listen address in format "host:port" or '. for($i=0; $i < count($command_args); $i++) {
'":port" (= 0.0.0.0:port).') switch($command_args[$i]) {
); case '-P':
return; 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 // 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); $parts = explode(':', $listen_address);
if (count($parts) != 2) { if (count($parts) != 2) {
self :: usage( self :: usage(
@ -347,8 +389,22 @@ class Cli {
$public_html $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( 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_code
); );
exit($exit_code); exit($exit_code);