This commit is contained in:
Juan Ferrer Toribio 2016-08-26 14:44:08 +02:00
parent 83977af8a3
commit 87ab2e249c
2 changed files with 8 additions and 4 deletions

View File

@ -6,6 +6,7 @@ require_once (__DIR__.'/method.php');
require_once (__DIR__.'/exception.php');
require_once (__DIR__.'/user-exception.php');
require_once (__DIR__.'/locale.php');
require_once (__DIR__.'/util.php');
require_once ('vn/db/conn.php');
use Vn\Db\Conn;
@ -142,13 +143,15 @@ class App
/**
* Runs a method.
**/
function loadMethod ($methodUri = NULL, $baseDir = NULL)
function loadMethod ($methodUri = NULL, $checkClass = NULL, $baseDir = NULL)
{
// XXX: Partially implemented
if (!$methodUri)
$methodUri = basename ($_SERVER['SCRIPT_FILENAME'], '.php');
if (!$baseDir)
$baseDir = $this->methodDir;
if (!$checkClass)
$checkClass = __NAMESPACE__ .'\Method';
if (!preg_match ('/^[\/\w\-]+$/', $methodUri))
throw new \Exception ('Method contains invalid characters');
@ -173,8 +176,8 @@ class App
if (!class_exists ($className))
throw new \Exception ("Class '$className' not exists");
if (!is_subclass_of ($className, __NAMESPACE__ .'\Method'))
throw new \Exception ("Class '$className' is not a 'Method' child");
if (!is_subclass_of ($className, $checkClass))
throw new \Exception ("Class '$className' is not a '$checkClass' child");
Locale::addPath ("$baseDir/$methodName");
return new $className ($this);

View File

@ -22,6 +22,7 @@ class CliApp extends App
if (empty ($options['m']))
$this->usage ();
echo "Executing method '{$options['m']}'\n";
$method = $this->loadMethod ($options['m']);
$method->run ();
}
@ -35,7 +36,7 @@ class CliApp extends App
function usage ()
{
global $argv;
echo "{$argv[0]} -m method\n";
echo "Usage: {$argv[0]} -m method_path\n";
exit (1);
}
}