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