Add error management in CLI (display the trigger_errors in stderr)

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1732 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-08-19 09:05:55 +00:00
parent 9eb50a537e
commit 8056491a1a

77
cli.php
View File

@@ -13,36 +13,55 @@ class cli
require ("domframework/cli.php");
$cli = new cli;
$cli->run(); */
public function run ()
{
global $argv;
$launcher = $argv[0];
chdir (dirname ($argv[0])."/..");
array_shift ($argv);
if (isset ($argv[0]) && $argv[0] === "-h")
{
echo "Execute in CLI a controller or a model (in expert mode)\n";
echo " $launcher -h : display this help\n";
echo " $launcher -list : display controllers\n";
echo " $launcher -expert -list : display controllers and models\n";
echo " $launcher -listmethods <class> : \n";
echo " display the methods available the controller class\n";
echo " $launcher -expert -listmethods <class> :\n";
echo " display the methods available the model or controller class".
"\n";
echo " $launcher -listmethodsdetails <class> : \n";
echo " display the methods available the controller class\n";
echo " $launcher -expert -listmethodsdetails <class> :\n";
echo " display the methods available the model or controller class".
"\n";
echo " $launcher <class> <method> [args]\n";
echo " execute the method with the provided args\n";
echo " $launcher -expert <class> <method> [args]\n";
echo " execute the method with the provided args\n";
echo "You can replace ONE arg by a dash (-) to read from stdin\n";
echo "Arrays must be coded like key1=val1&key2=val2&key3=val3...\n";
exit;
public function __construct ()
{
// Catch the trigger_errors and display them politely
set_error_handler(array(&$this, "cliErrorHandler"));
}
/** The error handler for CLI : display error in STDERR */
public function cliErrorHandler ($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno))
{
// This error code is not included in error_reporting
return;
}
file_put_contents ("php://stderr", "$errstr [".basename ($errfile) .
":$errline]\n");
}
public function run ()
{
global $argv;
$launcher = $argv[0];
chdir (dirname ($argv[0])."/..");
array_shift ($argv);
if (isset ($argv[0]) && $argv[0] === "-h")
{
echo "Execute in CLI a controller or a model (in expert mode)\n";
echo " $launcher -h : display this help\n";
echo " $launcher -list : display controllers\n";
echo " $launcher -expert -list : display controllers and models\n";
echo " $launcher -listmethods <class> : \n";
echo " display the methods available the controller class\n";
echo " $launcher -expert -listmethods <class> :\n";
echo " display the methods available the model or controller class".
"\n";
echo " $launcher -listmethodsdetails <class> : \n";
echo " display the methods available the controller class\n";
echo " $launcher -expert -listmethodsdetails <class> :\n";
echo " display the methods available the model or controller class".
"\n";
echo " $launcher <class> <method> [args]\n";
echo " execute the method with the provided args\n";
echo " $launcher -expert <class> <method> [args]\n";
echo " execute the method with the provided args\n";
echo "You can replace ONE arg by a dash (-) to read from stdin\n";
echo "Arrays must be coded like key1=val1&key2=val2&key3=val3...\n";
exit;
}
$EXPERT = FALSE;