Console_CommandLine
[ class tree: Console_CommandLine ] [ index: Console_CommandLine ] [ all elements ]

Source for file Default.php

Documentation is available at Default.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * This file is part of the PEAR Console_CommandLine package.
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This source file is subject to the MIT license that is available
  11.  * through the world-wide-web at the following URI:
  12.  * http://opensource.org/licenses/mit-license.php
  13.  *
  14.  * @category  Console
  15.  * @package   Console_CommandLine
  16.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  17.  * @copyright 2007 David JEAN LOUIS
  18.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  19.  * @version   CVS: $Id: Default.php,v 1.5 2008/10/09 10:44:54 izi Exp $
  20.  * @link      http://pear.php.net/package/Console_CommandLine
  21.  * @since     File available since release 0.1.0
  22.  * @filesource
  23.  */
  24.  
  25. /**
  26.  * The message provider interface.
  27.  */
  28. require_once 'Console/CommandLine/MessageProvider.php';
  29.  
  30. /**
  31.  * Lightweight class that manages messages used by Console_CommandLine package,
  32.  * allowing the developper to customize these messages, for example to
  33.  * internationalize a command line frontend.
  34.  *
  35.  * @category  Console
  36.  * @package   Console_CommandLine
  37.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  38.  * @copyright 2007 David JEAN LOUIS
  39.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  40.  * @version   Release: 1.0.6
  41.  * @link      http://pear.php.net/package/Console_CommandLine
  42.  * @since     Class available since release 0.1.0
  43.  */
  44. class Console_CommandLine_MessageProvider_Default implements Console_CommandLine_MessageProvider
  45. {
  46.     // Properties {{{
  47.  
  48.     /**
  49.      * Associative array of messages
  50.      *
  51.      * @var array $messages 
  52.      */
  53.     protected $messages = array(
  54.         'OPTION_VALUE_REQUIRED'   => 'Option "{$name}" requires a value.',
  55.         'OPTION_VALUE_UNEXPECTED' => 'Option "{$name}" does not expect a value (got "{$value}").',
  56.         'OPTION_VALUE_NOT_VALID'  => 'Option "{$name}" must be one of the following: "{$choices}" (got "{$value}").',
  57.         'OPTION_VALUE_TYPE_ERROR' => 'Option "{$name}" requires a value of type {$type} (got "{$value}").',
  58.         'OPTION_AMBIGUOUS'        => 'Ambiguous option "{$name}", can be one of the following: {$matches}.',
  59.         'OPTION_UNKNOWN'          => 'Unknown option "{$name}".',
  60.         'ARGUMENT_REQUIRED'       => 'You must provide at least {$argnum} argument{$plural}.',
  61.         'PROG_HELP_LINE'          => 'Type "{$progname} --help" to get help.',
  62.         'PROG_VERSION_LINE'       => '{$progname} version {$version}.',
  63.         'COMMAND_HELP_LINE'       => 'Type "{$progname} <command> --help" to get help on specific command.',
  64.         'USAGE_WORD'              => 'Usage',
  65.         'OPTION_WORD'             => 'Options',
  66.         'ARGUMENT_WORD'           => 'Arguments',
  67.         'COMMAND_WORD'            => 'Commands',
  68.         'PASSWORD_PROMPT'         => 'Password: ',
  69.         'PASSWORD_PROMPT_ECHO'    => 'Password (warning: will echo): ',
  70.         'INVALID_CUSTOM_INSTANCE' => 'Instance does not implement the required interface',
  71.         'LIST_OPTION_MESSAGE'     => 'lists valid choices for option {$name}',
  72.         'LIST_DISPLAYED_MESSAGE'  => 'Valid choices are: ',
  73.     );
  74.  
  75.     // }}}
  76.     // get() {{{
  77.  
  78.     /**
  79.      * Retrieve the given string identifier corresponding message.
  80.      *
  81.      * @param string $code The string identifier of the message
  82.      * @param array  $vars An array of template variables
  83.      *
  84.      * @return string 
  85.      */
  86.     public function get($code$vars = array())
  87.     {
  88.         if (!isset($this->messages[$code])) {
  89.             return 'UNKNOWN';
  90.         }
  91.         $tmpkeys array_keys($vars);
  92.         $keys    = array();
  93.         foreach ($tmpkeys as $key{
  94.             $keys['{$' $key '}';
  95.         }
  96.         return str_replace($keysarray_values($vars)$this->messages[$code]);
  97.     }
  98.  
  99.     // }}}
  100. }

Documentation generated on Mon, 11 Mar 2019 15:28:01 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.