-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_method.php
More file actions
75 lines (62 loc) · 1.62 KB
/
run_method.php
File metadata and controls
75 lines (62 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/php -f
<?php
require_once 'abstract.php';
class Herve_Run_Method extends Mage_Shell_Abstract
{
protected function _parseArgs()
{
$this->_args = array_slice(
array_filter($_SERVER['argv'],
create_function('$e',
'return $e != \'--\';')),
1);
return $this;
}
/**
* Run script
*
* @return null
*/
public function run()
{
if (empty($this->_args)) {
echo $this->usageHelp();
return;
}
$uri = array_shift($this->_args);
$method = array_shift($this->_args);
$model = Mage::getModel($uri);
echo "\n\r";
try {
$result = call_user_func_array(array($model, $method), $this->_args);
echo 'Processed "' . get_class($model) . '::' . $method . '()" and returned ';
if (is_object($result)) {
echo 'an instance of "' . get_class($result) . '"';
}
else {
var_dump($result);
}
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\n\r\n\r";
}
/**
* Get the usage string
*
* @return string
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f run_method.php -- <class URi> <method> [args]
Example:
php -f run_method.php -- module/class method arg1 arg2
will do:
Mage::getModel('module/class')->method(arg1, arg2);
Do the 'help' command to see the list of available commands
USAGE;
}
}
$shell = new Herve_Run_Method();
$shell->run();