1: <?php
2: /**
3: * The command line handling for the Kolab_Filter package.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Filter
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Filter
12: */
13:
14: /**
15: * The command line handling for the Kolab_Filter package.
16: *
17: * Copyright 2008 Klarälvdalens Datakonsult AB
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you did not
20: * receive this file, see
21: * http://www.horde.org/licenses/lgpl21.
22: *
23: * @category Kolab
24: * @package Kolab_Filter
25: * @author Gunnar Wrobel <wrobel@pardus.de>
26: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
27: * @link http://pear.horde.org/index.php?package=Kolab_Filter
28: */
29: class Horde_Kolab_Filter_Cli
30: {
31: /**
32: * The CLI argument parser.
33: *
34: * @var Horde_Argv_Parser
35: */
36: private $_parser;
37:
38: /**
39: * The CLI options.
40: *
41: * @var Horde_Argv_Values
42: */
43: private $_options;
44:
45: /**
46: * The CLI arguments.
47: *
48: * @var array
49: */
50: private $_arguments;
51:
52: /**
53: * Constructor.
54: */
55: public function __construct()
56: {
57: $this->_parser = new Horde_Kolab_Filter_Cli_Parser(
58: array('optionList' =>
59: array(
60: new Horde_Argv_Option(
61: '-s',
62: '--sender',
63: array(
64: 'help' => 'The message sender.',
65: 'type' => 'string',
66: 'nargs' => 1
67: )
68: ),
69: new Horde_Argv_Option(
70: '-r',
71: '--recipient',
72: array(
73: 'help' => 'A message recipient.',
74: 'action' => 'append',
75: 'type' => 'string'
76: )
77: ),
78: new Horde_Argv_Option(
79: '-H',
80: '--host',
81: array(
82: 'help' => 'The host running this script.'
83: )
84: ),
85: new Horde_Argv_Option(
86: '-c',
87: '--client',
88: array(
89: 'help' => 'The client sending the message.'
90: )
91: ),
92: new Horde_Argv_Option(
93: '-u',
94: '--user',
95: array(
96: 'help' => 'ID of the currently authenticated user.',
97: 'default' => ''
98: )
99: ),
100: new Horde_Argv_Option(
101: '-C',
102: '--config',
103: array(
104: 'help' => 'Path to the configuration file for this filter.'
105: )
106: )
107: )
108: )
109: );
110: }
111:
112: /**
113: * Parse the command line arguments.
114: *
115: * @return NULL
116: */
117: public function parse()
118: {
119: try {
120: list($this->_options, $this->_arguments) = $this->_parser->parseArgs();
121: } catch (InvalidArgumentException $e) {
122: throw new Horde_Kolab_Filter_Exception_Usage(
123: $e->getMessage() . "\n\n" . $this->_parser->getUsage()
124: );
125: }
126:
127: if (empty($this->_options['recipient'])) {
128: throw new Horde_Kolab_Filter_Exception_Usage(
129: sprintf(
130: "Please provide one or more recipients.\n\n%s",
131: $this->_parser->getUsage()
132: )
133: );
134: }
135: }
136:
137: /**
138: * Return the command line options.
139: *
140: * @return Horde_Argv_Values The command line values.
141: */
142: public function getOptions()
143: {
144: if ($this->_options === null) {
145: $this->parse();
146: }
147: return $this->_options;
148: }
149: }