1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18: class Horde_Reflection_CLI extends Horde_Reflection {
19:
20: 21: 22:
23: private $_cli;
24:
25: 26: 27: 28: 29:
30: public function __construct(ReflectionFunction $method)
31: {
32: $this->_cli = Horde_Cli::init();
33:
34: parent::__construct($method);
35: }
36:
37: 38: 39: 40: 41:
42: private function _getSignature()
43: {
44: $name = $this->_name;
45: $returnType = $this->_returns;
46:
47: $title = substr($name, strpos($name, '_', 2) + 1);
48:
49: $result = $this->_cli->yellow($title) . ' ' . $this->_help . "\n";
50: $result .= $this->_cli->blue($returnType) . ' ';
51: $result .= $this->_cli->green($title) . ' ';
52: $result .= "(";
53: $first = true;
54: $nbr = 0;
55:
56: while (list($name, $parameter) = each($this->_parameters)) {
57: $nbr++;
58: if ($nbr == $this->_numberOfRequiredParameters + 1) {
59: $result .= " [ ";
60: }
61: if ($first) {
62: $first = false;
63: } else {
64: $result .= ', ';
65: }
66: $type = $parameter['type'];
67: $result .= $this->_cli->red($type) . ' ';
68: $result .= $this->_cli->blue($name);
69: }
70: reset($this->_parameters);
71: if ($nbr > $this->_numberOfRequiredParameters) {
72: $result .= " ] ";
73: }
74: $result .= ")";
75: return $result;
76: }
77:
78: 79: 80: 81: 82:
83: public function autoDocument()
84: {
85: $this->_cli->writeln();
86: $this->_cli->writeln($this->_getSignature());
87:
88: if (count($this->_parameters) > 0) {
89: $out = $this->_cli->indent("Type\tName\tDocumentation\n");
90: while (list($name, $parameter) = each($this->_parameters)) {
91: $type = $parameter['type'];
92: if (is_array($type)) {
93: $type = implode(' | ', $type);
94: }
95: if (isset($parameter['doc'])) {
96: $doc = trim($parameter['doc']);
97: } else {
98: $doc = '';
99: }
100: $out .= $this->_cli->indent("$type\t$name\t$doc\n");
101: }
102: $this->_cli->writeln($out);
103:
104: reset($this->_parameters);
105: }
106: }
107:
108: }
109: