Core_Controller_Shell::action_default
null Core_Controller_Shell::action_default( )
File: ./core/controllers-shell/shell.controller.php
public function action_default()
{
$examples = array_diff( get_class_methods( $this ), get_class_methods( __CLASS__ ) );
# 获取方法的字符串最大长度
$methods = array();
$name_max_len = 0;
foreach ( $examples as $method )
{
if ( $method == __FUNCTION__ ) continue;
if ( strtolower( substr( $method, 0, 7 ) ) == 'action_' )
{
$m = substr( $method, 7 );
$methods[$m] = $m;
$name_max_len = max( strlen( $m ), $name_max_len );
}
}
$str = '';
$str_usage = 'Usage: ';
foreach ( $methods as $method )
{
$ref_method = new ReflectionMethod( $this, 'action_' . $method );
$parameters = $ref_method->getParameters();
$str_usage .= str_pad( $method, $name_max_len, ' ', STR_PAD_RIGHT );
$comment = self::_parse_doc_comment( $ref_method->getDocComment() );
$str .= CRLF . CRLF . ' ' . $method . CRLF . ' comment : ' . $comment['title'][0] . CRLF . ' parameters: ';
if ( $parameters )
{
$tmpstr = array();
$tmpparameter = array();
$i = 0;
$hava_l = 0;
foreach ( $parameters as $k => $parameter )
{
$tmpstr[] = ' $' . $parameter->name . ' ' . $comment['param'][$i];
$tmpparameter[$k] = '$' . $parameter->getName();
if ( $parameter->isDefaultValueAvailable() )
{
$hava_l ++;
$tmpparameter[$k] = '[' . $tmpparameter[$k] . ' = ' . $parameter->getDefaultValue();
}
$i ++;
}
$str .= trim( implode( CRLF, $tmpstr ) );
$str_usage .= ' [options] ' . '[' . implode( ', ', $tmpparameter ) . ']';
if ( $hava_l )
{
for( $i = 0; $i < $hava_l; $i ++ )
{
$str_usage .= ' ]';
}
}
}
else
{
$str .= '[no parameter]' . CRLF;
}
$str_usage .= CRLF . ' ';
}
$str_usage = trim( $str_usage ) . CRLF;
echo $str_usage, $str;
}