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:  * Command line tools for Kolab storage.
  4:  *
  5:  * PHP version 5
  6:  *
  7:  * @category Kolab
  8:  * @package  Kolab_Cli
  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_Cli
 12:  */
 13: 
 14: /**
 15:  * Command line tools for Kolab storage.
 16:  *
 17:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
 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_Cli
 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_Cli
 28:  */
 29: class Horde_Kolab_Cli
 30: {
 31:     /**
 32:      * The main entry point for the application.
 33:      *
 34:      * @param array $parameters A list of named configuration parameters.
 35:      * <pre>
 36:      * 'parser'   - (array)     Parser configuration parameters.
 37:      *   'class'  - (string)    The class name of the parser to use.
 38:      * 'output'   - (Horde_Cli) The output handler.
 39:      * </pre>
 40:      */
 41:     static public function main(array $parameters = array())
 42:     {
 43:         $modular = self::_prepareModular($parameters);
 44:         if (empty($parameters['output'])) {
 45:             if (!class_exists('Horde_Cli')) {
 46:                 throw new Horde_Kolab_Cli_Exception('The Horde_Cli package seems to be missing (Class Horde_Cli is missing)!');
 47:             }
 48:             $cli = Horde_Cli::init();
 49:         } else {
 50:             $cli = $parameters['output'];
 51:         }
 52:         $parser = $modular->createParser();
 53:         list($options, $arguments) = $parser->parseArgs();
 54:         if (count($arguments) == 0) {
 55:             $parser->printHelp();
 56:         } else {
 57:             try {
 58:                 if (!empty($options['config'])) {
 59:                     if (!file_exists($options['config'])) {
 60:                         throw new Horde_Kolab_Cli_Exception(
 61:                             sprintf(
 62:                                 'The specified config file %s does not exist!',
 63:                                 $options['config']
 64:                             )
 65:                         );
 66:                     }
 67:                     global $conf;
 68:                     include $options['config'];
 69:                     foreach ($conf as $key => $value) {
 70:                         $options->ensureValue($key, $value);
 71:                     }
 72:                 }
 73:                 if (empty($options['host'])) {
 74:                     $options['host'] = 'localhost';
 75:                 }
 76:                 if (empty($options['driver'])) {
 77:                     $options['driver'] = 'horde';
 78:                 }
 79:                 $world = array();
 80:                 foreach ($modular->getModules() as $module) {
 81:                     $modular->getProvider()
 82:                         ->getModule($module)
 83:                         ->handleArguments($options, $arguments, $world);
 84:                 }
 85:                 if (!empty($options['timed'])
 86:                     && class_exists('Horde_Support_Timer')) {
 87:                     $timer = new Horde_Support_Timer();
 88:                     $timer->push();
 89:                 } else {
 90:                     $timer = false;
 91:                 }
 92:                 $modular->getProvider()
 93:                     ->getModule(ucfirst($arguments[0]))
 94:                     ->run($cli, $options, $arguments, $world);
 95:                 if (!empty($options['timed'])) {
 96:                     if ($timer) {
 97:                         $cli->message(floor($timer->pop() * 1000) . ' ms');
 98:                     } else {
 99:                         $cli->message('The class Horde_Support_Timer seems to be missing!');
100:                     }
101:                 }
102:             } catch (Horde_Cli_Modular_Exception $e) {
103:                 $parser->printHelp();
104:             }
105:         }
106:     }
107: 
108:     static private function _prepareModular(array $parameters = array())
109:     {
110:         return new Horde_Cli_Modular(
111:             array(
112:                 'parser' => array(
113:                     'class' => empty($parameters['parser']['class']) ? 'Horde_Argv_Parser' : $parameters['parser']['class'],
114:                     'usage' => Horde_Kolab_Cli_Translation::t(
115:                         "[options] MODULE ACTION\n\nPossible MODULEs and ACTIONs:\n\n"
116:                     )
117:                 ),
118:                 'modules' => array(
119:                     'directory' => dirname(__FILE__) . '/Cli/Module',
120:                 ),
121:                 'provider' => array(
122:                     'prefix' => 'Horde_Kolab_Cli_Module_'
123:                 )
124:             )
125:         );
126:     }
127: }
API documentation generated by ApiGen