Overview

Packages

  • Kolab
    • Cli

Classes

  • Horde_Kolab_Cli
  • Horde_Kolab_Cli_Data_Ledger
  • Horde_Kolab_Cli_Exception
  • Horde_Kolab_Cli_Module_Account
  • Horde_Kolab_Cli_Module_Base
  • Horde_Kolab_Cli_Module_Data
  • Horde_Kolab_Cli_Module_Folder
  • Horde_Kolab_Cli_Module_Format
  • Horde_Kolab_Cli_Module_Ledger
  • Horde_Kolab_Cli_Module_List
  • Horde_Kolab_Cli_Translation

Interfaces

  • Horde_Kolab_Cli_Module
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Kolab_Cli_Module_Base:: module provides the base options of the
  4:  * Kolab CLI.
  5:  *
  6:  * PHP version 5
  7:  *
  8:  * @category Horde
  9:  * @package  Kolab_Cli
 10:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 11:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 12:  * @link     http://pear.horde.org/index.php?package=Kolab_Cli
 13:  */
 14: 
 15: /**
 16:  * The Horde_Kolab_Cli_Module_Base:: module provides the base options of the
 17:  * Kolab CLI.
 18:  *
 19:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
 20:  *
 21:  * See the enclosed file COPYING for license information (LGPL). If you
 22:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 23:  *
 24:  * @category Horde
 25:  * @package  Kolab_Cli
 26:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 27:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 28:  * @link     http://pear.horde.org/index.php?package=Kolab_Cli
 29:  */
 30: class Horde_Kolab_Cli_Module_Base
 31: implements Horde_Kolab_Cli_Module
 32: {
 33:     /**
 34:      * Get the usage description for this module.
 35:      *
 36:      * @return string The description.
 37:      */
 38:     public function getUsage()
 39:     {
 40:         return '';
 41:     }
 42: 
 43:     /**
 44:      * Get a set of base options that this module adds to the CLI argument
 45:      * parser.
 46:      *
 47:      * @return array The options.
 48:      */
 49:     public function getBaseOptions()
 50:     {
 51:         return array(
 52:             new Horde_Argv_Option(
 53:                 '-d',
 54:                 '--driver',
 55:                 array(
 56:                     'action' => 'store',
 57:                     'choices' => array('horde', 'horde-php', 'php', 'pear', 'roundcube', 'mock'),
 58:                     'help'   => Horde_Kolab_Cli_Translation::t("The Kolab backend driver that should be used.
 59: Choices are:
 60: 
 61:  - horde     [IMAP]: The Horde_Imap_Client driver as pure PHP implementation.
 62:  - horde-php [IMAP]: The Horde_Imap_Client driver based on c-client in PHP
 63:  - php       [IMAP]: The PHP imap_* functions which are based on c-client
 64:  - pear      [IMAP]: The PEAR-Net_IMAP driver
 65:  - roundcube [IMAP]: The roundcube IMAP driver
 66:  - mock      [Mem.]: A dummy driver that uses memory."
 67:                     ),
 68:                 )
 69:             ),
 70:             new Horde_Argv_Option(
 71:                 '-u',
 72:                 '--username',
 73:                 array(
 74:                     'action' => 'store',
 75:                     'help'   => Horde_Kolab_Cli_Translation::t('The user accessing the backend.')
 76:                 )
 77:             ),
 78:             new Horde_Argv_Option(
 79:                 '-p',
 80:                 '--password',
 81:                 array(
 82:                     'action' => 'store',
 83:                     'help'   => Horde_Kolab_Cli_Translation::t('The password of the user accessing the backend.')
 84:                 )
 85:             ),
 86:             new Horde_Argv_Option(
 87:                 '-H',
 88:                 '--host',
 89:                 array(
 90:                     'action' => 'store',
 91:                     'help'   => Horde_Kolab_Cli_Translation::t('The host that holds the data.'),
 92:                 )
 93:             ),
 94:             new Horde_Argv_Option(
 95:                 '-P',
 96:                 '--port',
 97:                 array(
 98:                     'action' => 'store',
 99:                     'help'   => Horde_Kolab_Cli_Translation::t('The port that should be used to connect to the host.')
100:                 )
101:             ),
102:             new Horde_Argv_Option(
103:                 '-S',
104:                 '--secure',
105:                 array(
106:                     'action' => 'store',
107:                     'help'   => Horde_Kolab_Cli_Translation::t('Sets the connection type. Use either "tls" or "ssl" here.')
108:                 )
109:             ),
110:             new Horde_Argv_Option(
111:                 '-t',
112:                 '--timed',
113:                 array(
114:                     'action' => 'store_true',
115:                     'help'   => Horde_Kolab_Cli_Translation::t('Produce time measurements to indicate how long the processing takes. You *must* activate logging for this as well.')
116:                 )
117:             ),
118:             new Horde_Argv_Option(
119:                 '-m',
120:                 '--memory',
121:                 array(
122:                     'action' => 'store_true',
123:                     'help'   => Horde_Kolab_Cli_Translation::t('Report memory consumption statistics. You *must* activate logging for this as well.')
124:                 )
125:             ),
126:             new Horde_Argv_Option(
127:                 '-n',
128:                 '--nocache',
129:                 array(
130:                     'action' => 'store_true',
131:                     'help'   => Horde_Kolab_Cli_Translation::t('Deactivate caching of the IMAP data.')
132:                 )
133:             ),
134:             new Horde_Argv_Option(
135:                 '-l',
136:                 '--log',
137:                 array(
138:                     'action' => 'store',
139:                     'help'   => Horde_Kolab_Cli_Translation::t('Write a log file in the provided LOG location. Use "STDOUT" here to direct the log output to the screen.')
140:                 )
141:             ),
142:             new Horde_Argv_Option(
143:                 '-D',
144:                 '--debug',
145:                 array(
146:                     'action' => 'store',
147:                     'help'   => Horde_Kolab_Cli_Translation::t('Activates the IMAP debug log. This will log the full IMAP communication - CAUTION: the "php" driver is the only driver variant that does not support this feature. For most drivers you should use "STDOUT" which will direct the debug log to your screen. For the horde, the horde-php, and the roundcube drivers you may also set this to a filename and the output will be directed there.'),
148:                 )
149:             ),
150:             new Horde_Argv_Option(
151:                 '-c',
152:                 '--config',
153:                 array(
154:                     'action' => 'store',
155:                     'help'   => Horde_Kolab_Cli_Translation::t('Path to the configuration file. Comman line parameters overwrite values from the configuration file.')
156:                 )
157:             ),
158:         );
159:     }
160: 
161:     /**
162:      * Indicate if the module provides an option group.
163:      *
164:      * @return boolean True if an option group should be added.
165:      */
166:     public function hasOptionGroup()
167:     {
168:         return false;
169:     }
170: 
171:     /**
172:      * Return the title for the option group representing this module.
173:      *
174:      * @return string The group title.
175:      */
176:     public function getOptionGroupTitle()
177:     {
178:         return '';
179:     }
180: 
181:     /**
182:      * Return the description for the option group representing this module.
183:      *
184:      * @return string The group description.
185:      */
186:     public function getOptionGroupDescription()
187:     {
188:         return '';
189:     }
190: 
191:     /**
192:      * Return the options for this module.
193:      *
194:      * @return array The group options.
195:      */
196:     public function getOptionGroupOptions()
197:     {
198:         return array();
199:     }
200: 
201:     /**
202:      * Handle the options and arguments.
203:      *
204:      * @param mixed &$options   An array of options.
205:      * @param mixed &$arguments An array of arguments.
206:      * @param array &$world     A list of initialized dependencies.
207:      *
208:      * @return NULL
209:      */
210:     public function handleArguments(&$options, &$arguments, &$world)
211:     {
212:         if (isset($options['driver'])
213:             && in_array($options['driver'], array('roundcube', 'php', 'pear'))) {
214:             if (defined('E_DEPRECATED')) {
215:                 error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE);
216:             } else {
217:                 error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
218:             }
219:         }
220:         if (isset($options['log'])) {
221:             if (class_exists('Horde_Log_Logger')) {
222:                 $options['log'] = new Horde_Log_Logger(
223:                     new Horde_Log_Handler_Stream(
224:                         ($options['log'] == 'STDOUT') ? STDOUT : $options['log']
225:                     )
226:                 );
227:             } else {
228:                 file_put_contents($options['log'], 'The Horde_Log_Logger class is not available!');
229:                 unset($options['log']);
230:             }
231:         }
232:         $world['storage'] = $this->_getStorage($options);
233:         $world['format'] = $this->_getFormat($options);
234:     }
235: 
236: 
237:     /**
238:      * Return the driver for the Kolab storage backend.
239:      *
240:      * @param mixed     $options   An array of options.
241:      *
242:      * @return Horde_Kolab_Storage The storage handler.
243:      */
244:     private function _getStorage($options)
245:     {
246:         if (empty($options['driver'])) {
247:             return;
248:         }
249:         if ($options['driver'] == 'mock') {
250:             $options['data'] = array(
251:                 'format' => 'brief',
252:                 'user/test' => null
253:             );
254:         }
255:         $params = array(
256:             'driver' => $options['driver'],
257:             'params' => $options,
258:             'logger' => isset($options['log']) ? $options['log'] : null,
259:             'timelog' => isset($options['log']) && isset($options['timed']) ? $options['log'] : null,
260:         );
261:         if (empty($options['nocache'])) {
262:             $params['cache'] = array('prefix' => 'kolab_cache_', 'dir' => '/tmp/kolab', 'lifetime' => 0);
263:         }
264:         $factory = new Horde_Kolab_Storage_Factory($params);
265:         return $factory->create();
266:     }
267: 
268:     /**
269:      * Return the factory for the Kolab format parsers.
270:      *
271:      * @param mixed     $options   An array of options.
272:      *
273:      * @return Horde_Kolab_Format_Factory The format parser factory.
274:      */
275:     private function _getFormat($options)
276:     {
277:         return new Horde_Kolab_Format_Factory(
278:             array(
279:                 'timelog' => isset($options['log']) && isset($options['timed']) ? $options['log'] : null,
280:                 'memlog' => isset($options['log']) && isset($options['memory']) ? $options['log'] : null,
281:             )
282:         );
283:     }
284: }
API documentation generated by ApiGen