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

Source for file Password.php

Documentation is available at Password.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$
  20.  * @link      http://pear.php.net/package/Console_CommandLine
  21.  * @since     File available since release 0.1.0
  22.  * @filesource
  23.  */
  24.  
  25. /**
  26.  * Required by this class.
  27.  */
  28. require_once 'Console/CommandLine/Action.php';
  29.  
  30. /**
  31.  * Class that represent the Password action, a special action that allow the
  32.  * user to specify the password on the commandline or to be prompted for
  33.  * entering it.
  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.2.0
  41.  * @link      http://pear.php.net/package/Console_CommandLine
  42.  * @since     Class available since release 0.1.0
  43.  */
  44. {
  45.     // execute() {{{
  46.  
  47.     /**
  48.      * Executes the action with the value entered by the user.
  49.      *
  50.      * @param mixed $value  The option value
  51.      * @param array $params An array of optional parameters
  52.      *
  53.      * @return string 
  54.      */
  55.     public function execute($value = false$params = array())
  56.     {
  57.         $this->setResult(empty($value$this->_promptPassword($value);
  58.     }
  59.     // }}}
  60.     // _promptPassword() {{{
  61.  
  62.     /**
  63.      * Prompts the password to the user without echoing it.
  64.      *
  65.      * @return string 
  66.      * @todo not echo-ing the password does not work on windows is there a way
  67.      *        to make this work ?
  68.      */
  69.     private function _promptPassword()
  70.     {
  71.         if (strtoupper(substr(PHP_OS03)) === 'WIN'{
  72.             fwrite(STDOUT,
  73.                 $this->parser->message_provider->get('PASSWORD_PROMPT_ECHO'));
  74.             @flock(STDINLOCK_EX);
  75.             $passwd fgets(STDIN);
  76.             @flock(STDINLOCK_UN);
  77.         else {
  78.             fwrite(STDOUT$this->parser->message_provider->get('PASSWORD_PROMPT'));
  79.             // disable echoing
  80.             system('stty -echo');
  81.             @flock(STDINLOCK_EX);
  82.             $passwd fgets(STDIN);
  83.             @flock(STDINLOCK_UN);
  84.             system('stty echo');
  85.         }
  86.         return trim($passwd);
  87.     }
  88.     // }}}
  89. }

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