Overview

Packages

  • Reflection

Classes

  • Horde_Reflection
  • Horde_Reflection_CLI
  • Horde_Reflection_Html
  • Horde_Reflection_Wiki
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Reflection_Cli class renders method documention on the command line.
  4:  *
  5:  * Based on the PEAR XML_RPC2_Server_Method class by Sergio Carvalho
  6:  *
  7:  * Copyright 2004-2006 Sergio Gonalves Carvalho
  8:  *                     (<sergio.carvalho@portugalmail.com>)
  9:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
 10:  *
 11:  * See the enclosed file COPYING for license information (LGPL). If you
 12:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 13:  *
 14:  * @author  Sergio Carvalho <sergio.carvalho@portugalmail.com>
 15:  * @author  Duck <duck@obala.net>
 16:  * @package Reflection
 17:  */
 18: class Horde_Reflection_CLI extends Horde_Reflection {
 19: 
 20:     /**
 21:      * Cli inteface
 22:      */
 23:     private $_cli;
 24: 
 25:     /**
 26:      * Constructor.
 27:      *
 28:      * @param ReflectionMethod $method  The PHP method to introspect.
 29:      */
 30:     public function __construct(ReflectionFunction $method)
 31:     {
 32:         $this->_cli = Horde_Cli::init();
 33: 
 34:         parent::__construct($method);
 35:     }
 36: 
 37:     /**
 38:      * Returns a signature of the method.
 39:      *
 40:      * @return string  Method signature.
 41:      */
 42:     private function _getSignature()
 43:     {
 44:         $name = $this->_name;
 45:         $returnType = $this->_returns;
 46: 
 47:         $title = substr($name, strpos($name, '_', 2) + 1);
 48: 
 49:         $result = $this->_cli->yellow($title) . '  ' .  $this->_help . "\n";
 50:         $result .= $this->_cli->blue($returnType) . ' ';
 51:         $result .=  $this->_cli->green($title) . ' ';
 52:         $result .= "(";
 53:         $first = true;
 54:         $nbr = 0;
 55: 
 56:         while (list($name, $parameter) = each($this->_parameters)) {
 57:             $nbr++;
 58:             if ($nbr == $this->_numberOfRequiredParameters + 1) {
 59:                 $result .= " [ ";
 60:             }
 61:             if ($first) {
 62:                 $first = false;
 63:             } else {
 64:                 $result .= ', ';
 65:             }
 66:             $type = $parameter['type'];
 67:             $result .= $this->_cli->red($type) . ' ';
 68:             $result .= $this->_cli->blue($name);
 69:         }
 70:         reset($this->_parameters);
 71:         if ($nbr > $this->_numberOfRequiredParameters) {
 72:             $result .= " ] ";
 73:         }
 74:         $result .= ")";
 75:         return $result;
 76:     }
 77: 
 78:     /**
 79:      * Returns a complete description of the method.
 80:      *
 81:      * @return string  A snippet with the method documentation.
 82:      */
 83:     public function autoDocument()
 84:     {
 85:         $this->_cli->writeln();
 86:         $this->_cli->writeln($this->_getSignature());
 87: 
 88:         if (count($this->_parameters) > 0) {
 89:             $out = $this->_cli->indent("Type\tName\tDocumentation\n");
 90:             while (list($name, $parameter) = each($this->_parameters)) {
 91:                 $type = $parameter['type'];
 92:                 if (is_array($type)) {
 93:                     $type = implode(' | ', $type);
 94:                 }
 95:                 if (isset($parameter['doc'])) {
 96:                     $doc = trim($parameter['doc']);
 97:                 } else {
 98:                     $doc = '';
 99:                 }
100:                 $out .= $this->_cli->indent("$type\t$name\t$doc\n");
101:             }
102:             $this->_cli->writeln($out);
103: 
104:             reset($this->_parameters);
105:         }
106:     }
107: 
108: }
109: 
API documentation generated by ApiGen